From d379c20f44440f72fa0395a0df4421671f4a7f13 Mon Sep 17 00:00:00 2001 From: Carolyn Van Slyck Date: Fri, 1 Mar 2019 17:08:30 -0600 Subject: [PATCH] Publish charts to azure storage (#1097) * Add chart-push target and script * Rename chart dir to match helm standards --- .travis.yml | 4 +- Makefile | 16 +++++- charts/{proxy => athens-proxy}/Chart.yaml | 0 .../templates/NOTES.txt | 0 .../templates/_helpers.tpl | 0 .../templates/deployment.yaml | 0 .../templates/ingress.yaml | 0 .../templates/jaeger-deploy.yaml | 0 .../templates/jaeger-svc.yaml | 0 .../templates/service.yaml | 0 .../templates/storage-pvc.yaml | 0 charts/{proxy => athens-proxy}/values.yaml | 0 scripts/build-image/Dockerfile | 16 ++++++ scripts/push-helm-charts.sh | 50 +++++++++++++++++++ 14 files changed, 83 insertions(+), 3 deletions(-) rename charts/{proxy => athens-proxy}/Chart.yaml (100%) rename charts/{proxy => athens-proxy}/templates/NOTES.txt (100%) rename charts/{proxy => athens-proxy}/templates/_helpers.tpl (100%) rename charts/{proxy => athens-proxy}/templates/deployment.yaml (100%) rename charts/{proxy => athens-proxy}/templates/ingress.yaml (100%) rename charts/{proxy => athens-proxy}/templates/jaeger-deploy.yaml (100%) rename charts/{proxy => athens-proxy}/templates/jaeger-svc.yaml (100%) rename charts/{proxy => athens-proxy}/templates/service.yaml (100%) rename charts/{proxy => athens-proxy}/templates/storage-pvc.yaml (100%) rename charts/{proxy => athens-proxy}/values.yaml (100%) create mode 100644 scripts/build-image/Dockerfile create mode 100755 scripts/push-helm-charts.sh diff --git a/.travis.yml b/.travis.yml index 13051b0c..3c0166a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ env: - CODE_COV=1 - ATHENS_DIR=${GOPATH}/src/github.com/gomods/athens - REGISTRY=gomods/ + - CHARTS_REPO=https://athens.blob.core.windows.net - GORELEASER_ON=1 - GO111MODULE=on @@ -37,8 +38,7 @@ before_deploy: deploy: - provider: script - script: make docker-push + script: make docker-push charts-push on: repo: gomods/athens all_branches: true - diff --git a/Makefile b/Makefile index 95cfd61f..1bb0e08e 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,14 @@ build: build-ver: GO111MODULE=on CGO_ENABLED=0 go build -mod=vendor -ldflags "-X github.com/gomods/athens/pkg/build.version=$(VERSION) -X github.com/gomods/athens/pkg/build.buildDate=$(DATE)" -o athens ./cmd/proxy +# The build-image step creates a docker image that has all the tools required +# to perform some CI build steps, instead of relying on them being installed locally +.PHONY: build-image +build-image: + docker build -t athens-build ./scripts/build-image + .PHONY: run -run: +run: cd ./cmd/proxy && go run . -config_file ../../config.dev.toml .PHONY: docs @@ -60,6 +66,14 @@ proxy-docker: docker-push: ./scripts/push-docker-images.sh +.PHONY: charts-push +charts-push: build-image + docker run --rm -it \ + -v `pwd`:/go/src/github.com/gomods/athens \ + -e AZURE_STORAGE_CONNECTION_STRING \ + -e CHARTS_REPO \ + athens-build ./scripts/push-helm-charts.sh + bench: ./scripts/benchmark.sh diff --git a/charts/proxy/Chart.yaml b/charts/athens-proxy/Chart.yaml similarity index 100% rename from charts/proxy/Chart.yaml rename to charts/athens-proxy/Chart.yaml diff --git a/charts/proxy/templates/NOTES.txt b/charts/athens-proxy/templates/NOTES.txt similarity index 100% rename from charts/proxy/templates/NOTES.txt rename to charts/athens-proxy/templates/NOTES.txt diff --git a/charts/proxy/templates/_helpers.tpl b/charts/athens-proxy/templates/_helpers.tpl similarity index 100% rename from charts/proxy/templates/_helpers.tpl rename to charts/athens-proxy/templates/_helpers.tpl diff --git a/charts/proxy/templates/deployment.yaml b/charts/athens-proxy/templates/deployment.yaml similarity index 100% rename from charts/proxy/templates/deployment.yaml rename to charts/athens-proxy/templates/deployment.yaml diff --git a/charts/proxy/templates/ingress.yaml b/charts/athens-proxy/templates/ingress.yaml similarity index 100% rename from charts/proxy/templates/ingress.yaml rename to charts/athens-proxy/templates/ingress.yaml diff --git a/charts/proxy/templates/jaeger-deploy.yaml b/charts/athens-proxy/templates/jaeger-deploy.yaml similarity index 100% rename from charts/proxy/templates/jaeger-deploy.yaml rename to charts/athens-proxy/templates/jaeger-deploy.yaml diff --git a/charts/proxy/templates/jaeger-svc.yaml b/charts/athens-proxy/templates/jaeger-svc.yaml similarity index 100% rename from charts/proxy/templates/jaeger-svc.yaml rename to charts/athens-proxy/templates/jaeger-svc.yaml diff --git a/charts/proxy/templates/service.yaml b/charts/athens-proxy/templates/service.yaml similarity index 100% rename from charts/proxy/templates/service.yaml rename to charts/athens-proxy/templates/service.yaml diff --git a/charts/proxy/templates/storage-pvc.yaml b/charts/athens-proxy/templates/storage-pvc.yaml similarity index 100% rename from charts/proxy/templates/storage-pvc.yaml rename to charts/athens-proxy/templates/storage-pvc.yaml diff --git a/charts/proxy/values.yaml b/charts/athens-proxy/values.yaml similarity index 100% rename from charts/proxy/values.yaml rename to charts/athens-proxy/values.yaml diff --git a/scripts/build-image/Dockerfile b/scripts/build-image/Dockerfile new file mode 100644 index 00000000..a32cf423 --- /dev/null +++ b/scripts/build-image/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.12-stretch + +WORKDIR /tmp + +# Install Helm +ENV HELM_VERSION=2.13.0 +RUN curl -sLO https://kubernetes-helm.storage.googleapis.com/helm-v${HELM_VERSION}-linux-amd64.tar.gz && \ + tar -zxvf helm-v${HELM_VERSION}-linux-amd64.tar.gz && \ + mv linux-amd64/helm /usr/local/bin/ + +# Install a tiny azure client +ENV AZCLI_VERSION=v0.3.1 +RUN curl -sLo /usr/local/bin/az https://github.com/carolynvs/az-cli/releases/download/$AZCLI_VERSION/az-linux-amd64 && \ +chmod +x /usr/local/bin/az + +WORKDIR /go/src/github.com/gomods/athens diff --git a/scripts/push-helm-charts.sh b/scripts/push-helm-charts.sh new file mode 100755 index 00000000..66856875 --- /dev/null +++ b/scripts/push-helm-charts.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +set -xeuo pipefail + +helm init --client-only + +##### +# set up the repo dir, and package up all charts +##### +CHARTS_REPO=${CHARTS_REPO:-"https://athens.blob.core.windows.net"} +CHARTS_BUCKET=charts +REPO_DIR=bin/charts # This is where we do the charge merge and dirty things up, not the source chart directory +mkdir -p $REPO_DIR +echo "entering $REPO_DIR" +cd $REPO_DIR +if curl --output /dev/null --silent --head --fail ${CHARTS_REPO}/${CHARTS_BUCKET}/index.yaml; then + echo "downloading existing index.yaml" + curl -sLO ${CHARTS_REPO}/${CHARTS_BUCKET}/index.yaml +fi + +##### +# package the charts +##### +for dir in `ls ../../charts`;do + if [ ! -f ../../charts/$dir/Chart.yaml ];then + echo "skipping $dir because it lacks a Chart.yaml file" + else + echo "packaging $dir" + helm dep build ../../charts/$dir + helm package ../../charts/$dir + fi +done + +if [ -f $REPO_DIR/index.yaml ]; then + echo "merging with existing index.yaml" + helm repo index --url "$CHARTS_REPO/$CHARTS_BUCKET" --merge index.yaml . +else + echo "generating new index.yaml" + helm repo index . +fi + +##### +# upload to Azure blob storage +##### +if [ ! -v AZURE_STORAGE_CONNECTION_STRING ]; then + echo "AZURE_STORAGE_CONNECTION_STRING env var required to publish" + exit 1 +fi +echo "uploading from $PWD" +az storage blob upload-batch --destination $CHARTS_BUCKET --source .