Skip to content

Instantly share code, notes, and snippets.

@miraculixx
Last active August 12, 2020 17:57
Show Gist options
  • Save miraculixx/de62909719c26adf1391f262a725e022 to your computer and use it in GitHub Desktop.
Save miraculixx/de62909719c26adf1391f262a725e022 to your computer and use it in GitHub Desktop.
create a locally hosted helm repository to use in dependencies, serve using python http.server
def helmserver(dirname, hostname='localhost', port=8000):
# runs a helmserver (http server serving index.yaml and helm packages)
# returns a multiprocessing.Process, call .terminate() to stop it
# Usage:
# helmserver('/path/to/dependencies', hostname, port)
def httpdrunner(dirname, bind, port):
# this adopted from http.server module
import os
server_address = (bind, port)
os.chdir(dirname)
httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
httpd.serve_forever()
p = Process(target=httpdrunner, args=(dirname, hostname, port))
p.start()
sleep(1) # give it some time to start
return p
# put this in ./dependencies
# add external dependencies that cannot be added as a repository
# then add this directory as a file
# for every external chart, script the download as shown in localpath example, add to build target dependencies
# use $ make build to download all dependencies, build packages and local repo index
localpath:
mkdir -p staging
curl https://codeload.github.com/rancher/local-path-provisioner/tar.gz/v0.0.15 -o staging/localpath.tgz
cd staging && tar -xzf localpath.tgz
cd staging/local-path-provisioner*/deploy/chart && helm package .
mv staging/local-path-provisioner*/deploy/chart/*.tgz .
rm -rf staging
build: localpath
helm repo index .
@miraculixx
Copy link
Author

miraculixx commented Aug 12, 2020

Why?

  • sometimes your helm chart depends on another helm chart hosted in some github repo, but not served in a proper helm repo
  • you don't really want to clone the repo and keep the full chart, you really just want to keep the charts tgz
  • you want everything automated

Create a local helm repository of your externally hosted packages, e.g.

$ mkdir dependencies
$ cp Makefile dependencies
$ cd dependencies && make build
$ cd dependencies && helm repo index .

Specify in your chart dependencies:

# Chart.yaml
dependencies:
    - name: chart-name
      repository: http://localhost:8000/

Then serve your packages using before calling helm dependency update

$ cd dependencies && python -m http.server &
$ helm dependency update

If you have some python program that does all the helm'ing for you, use the above to run the http.server in a process instead of separately

# myprogram.py, e.g. invoke tasks
from helmserver import helmserver
@task
def update(c):
     p = helmserver('../dependencies')   
     c.run('helm dependency update .')
     p.terminate()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment