Loading .gitlab/ci/shellcheck.gitlab-ci.yml +2 −2 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ test-shellcheck: image: koalaman/shellcheck-alpine:stable needs: [] script: - shellcheck src/bin/auto-deploy test/* - shellcheck src/bin/auto-deploy test/verify-application-secret test/verify-deployment-database test-shfmt: stage: test Loading @@ -12,4 +12,4 @@ test-shfmt: entrypoint: ["/bin/sh", "-c"] needs: [] script: - shfmt -i 2 -ci -l -d src/bin/auto-deploy test/* - shfmt -i 2 -ci -l -d src/bin/auto-deploy test/verify-application-secret test/verify-deployment-database .gitlab/ci/test.gitlab-ci.yml +35 −1 Original line number Diff line number Diff line Loading @@ -57,11 +57,18 @@ test-kube-domain_error: - auto-deploy check_kube_domain && expected_error || failed_as_expected test-download-chart: <<: *test-job script: - auto-deploy download_chart - ./test/verify-chart-version 1 test-download-chart-from-repo: <<: *test-job variables: GIT_STRATEGY: none AUTO_DEVOPS_CHART: gitlab/auto-deploy-app script: - auto-deploy download_chart - ./test/verify-chart-version 0 test-deploy-name: <<: *test-job Loading Loading @@ -443,3 +450,30 @@ test-delete-canary-postgresql: - helm get production-canary && expected_error || failed_as_expected - helm get production - helm get production-postgresql test-chart-major-version-upgrade: extends: test-deploy script: - auto-deploy initialize_tiller # Downloading legacy v0 chart from charts.gitlab.io and the deployment should succeed - AUTO_DEVOPS_CHART=gitlab/auto-deploy-app auto-deploy download_chart - auto-deploy deploy - rm -Rf chart # Copying bundled chart from local storage and the deployment should fail - auto-deploy download_chart - "sed -i 's/version:.*/version: 10.0.0/g' chart/Chart.yaml" - cat chart/Chart.yaml - auto-deploy deploy| tee deploy.log || true - grep -q "Detected a major version difference" deploy.log || exit 1 # Force deploy with the AUTO_DEVOPS_FORCE_DEPLOY option and the deployment should succeed - export AUTO_DEVOPS_FORCE_DEPLOY_V10=true - auto-deploy deploy| tee deploy.log - grep -q "allowed to force deploy" deploy.log || exit 1 rspec: stage: test image: ruby:2.5 before_script: - gem install rspec script: - rspec test/rspec Dockerfile +4 −3 Original line number Diff line number Diff line Loading @@ -6,14 +6,15 @@ FROM "registry.gitlab.com/gitlab-org/cluster-integration/helm-install-image/rele # https://github.com/sgerrand/alpine-pkg-glibc ARG GLIBC_VERSION COPY src/ build/ # Install Dependencies RUN apk add --no-cache openssl curl tar gzip bash jq \ && curl -sSL -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \ && curl -sSL -O https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk \ && apk add glibc-${GLIBC_VERSION}.apk \ && apk add ruby jq \ && apk add ruby jq ruby-json \ && rm glibc-${GLIBC_VERSION}.apk COPY src/ build/ COPY assets/ assets/ RUN ln -s /build/bin/* /usr/local/bin/ README.md +8 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,14 @@ template will use the Docker image generated from this project. Changes from pre * All the other commands should be prepended with `auto-deploy`. For example, `check_kube_domain` now becomes `auto-deploy check_kube_domain`. ### v1.0.0 Before v1.0.0, auto-deploy-image was downloading a chart from [the chart repository](https://charts.gitlab.io/), which was then uploaded by the [auto-deploy-app](https://gitlab.com/gitlab-org/charts/auto-deploy-app) project. Since auto-deploy-image v1.0.0, the auto-deploy-app chart is bundled into the auto-deploy-image docker image as a local asset, and it no longer downloads the chart from the repository. # Generating a new auto-deploy image To generate a new image you must follow the git commit guidelines below, this Loading src/bin/auto-deploy +25 −18 Original line number Diff line number Diff line Loading @@ -13,6 +13,9 @@ if [[ "$AUTO_DEVOPS_POSTGRES_CHANNEL" == "2" ]]; then elif [[ "$AUTO_DEVOPS_POSTGRES_CHANNEL" == "1" ]]; then export POSTGRES_VERSION="${POSTGRES_VERSION:-"9.6.2"}" fi export BIN_DIR="/build/bin" export ASSETS_DIR='/assets' export ASSETS_CHART_DIR="${ASSETS_DIR}/auto-deploy-app" function check_kube_domain() { if [[ -z "$KUBE_INGRESS_BASE_DOMAIN" ]]; then Loading @@ -28,28 +31,31 @@ function check_kube_domain() { } function download_chart() { helm init --client-only if [[ -d chart ]]; then echo "Download is skipped. The bundled chart in user's repository will be used." elif [[ -n "${AUTO_DEVOPS_CHART}${AUTO_DEVOPS_CHART_REPOSITORY_NAME}${AUTO_DEVOPS_CHART_REPOSITORY}" ]]; then echo "Downloading the chart from the chart repository..." local auto_chart local auto_chart_name if [[ ! -d chart ]]; then auto_chart=${AUTO_DEVOPS_CHART:-gitlab/auto-deploy-app} # shellcheck disable=SC2086 # double quote variables to prevent globbing auto_chart_name=$(basename $auto_chart) auto_chart_name=${auto_chart_name%.tgz} auto_chart_name=${auto_chart_name%.tar.gz} else auto_chart="chart" auto_chart_name="chart" fi helm init --client-only # shellcheck disable=SC2086 # double quote variables to prevent globbing # shellcheck disable=SC2140 # ambiguous quoting warning helm repo add ${AUTO_DEVOPS_CHART_REPOSITORY_NAME:-gitlab} ${AUTO_DEVOPS_CHART_REPOSITORY:-https://charts.gitlab.io} ${AUTO_DEVOPS_CHART_REPOSITORY_USERNAME:+"--username" "$AUTO_DEVOPS_CHART_REPOSITORY_USERNAME"} ${AUTO_DEVOPS_CHART_REPOSITORY_PASSWORD:+"--password" "$AUTO_DEVOPS_CHART_REPOSITORY_PASSWORD"} if [[ ! -d "$auto_chart" ]]; then helm fetch ${auto_chart} --untar fi helm fetch "${auto_chart}" --untar if [ "$auto_chart_name" != "chart" ]; then mv ${auto_chart_name} chart mv "${auto_chart_name}" chart fi else echo "Download is skipped. The bundled chart in auto-deploy-image will be used." cp -R $ASSETS_CHART_DIR chart fi helm dependency update chart/ Loading Loading @@ -203,6 +209,8 @@ channel 1 database.' old_postgres_enabled="$POSTGRES_ENABLED" fi ${BIN_DIR}/validate-chart-version "$(helm list --output json)" "chart" "$name" local database_url database_url=$(auto_database_url) Loading Loading @@ -435,7 +443,7 @@ function create_application_secret() { k8s_secrets_file=$(mktemp) /build/bin/auto-deploy-application-secrets-yaml "$k8s_secrets_file" ${BIN_DIR}/auto-deploy-application-secrets-yaml "$k8s_secrets_file" kubectl replace -f "$k8s_secrets_file" -n "$KUBE_NAMESPACE" --force Loading Loading @@ -507,7 +515,6 @@ function get_replicas() { echo 1 fi } ## ## End Helper functions Loading Loading
.gitlab/ci/shellcheck.gitlab-ci.yml +2 −2 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ test-shellcheck: image: koalaman/shellcheck-alpine:stable needs: [] script: - shellcheck src/bin/auto-deploy test/* - shellcheck src/bin/auto-deploy test/verify-application-secret test/verify-deployment-database test-shfmt: stage: test Loading @@ -12,4 +12,4 @@ test-shfmt: entrypoint: ["/bin/sh", "-c"] needs: [] script: - shfmt -i 2 -ci -l -d src/bin/auto-deploy test/* - shfmt -i 2 -ci -l -d src/bin/auto-deploy test/verify-application-secret test/verify-deployment-database
.gitlab/ci/test.gitlab-ci.yml +35 −1 Original line number Diff line number Diff line Loading @@ -57,11 +57,18 @@ test-kube-domain_error: - auto-deploy check_kube_domain && expected_error || failed_as_expected test-download-chart: <<: *test-job script: - auto-deploy download_chart - ./test/verify-chart-version 1 test-download-chart-from-repo: <<: *test-job variables: GIT_STRATEGY: none AUTO_DEVOPS_CHART: gitlab/auto-deploy-app script: - auto-deploy download_chart - ./test/verify-chart-version 0 test-deploy-name: <<: *test-job Loading Loading @@ -443,3 +450,30 @@ test-delete-canary-postgresql: - helm get production-canary && expected_error || failed_as_expected - helm get production - helm get production-postgresql test-chart-major-version-upgrade: extends: test-deploy script: - auto-deploy initialize_tiller # Downloading legacy v0 chart from charts.gitlab.io and the deployment should succeed - AUTO_DEVOPS_CHART=gitlab/auto-deploy-app auto-deploy download_chart - auto-deploy deploy - rm -Rf chart # Copying bundled chart from local storage and the deployment should fail - auto-deploy download_chart - "sed -i 's/version:.*/version: 10.0.0/g' chart/Chart.yaml" - cat chart/Chart.yaml - auto-deploy deploy| tee deploy.log || true - grep -q "Detected a major version difference" deploy.log || exit 1 # Force deploy with the AUTO_DEVOPS_FORCE_DEPLOY option and the deployment should succeed - export AUTO_DEVOPS_FORCE_DEPLOY_V10=true - auto-deploy deploy| tee deploy.log - grep -q "allowed to force deploy" deploy.log || exit 1 rspec: stage: test image: ruby:2.5 before_script: - gem install rspec script: - rspec test/rspec
Dockerfile +4 −3 Original line number Diff line number Diff line Loading @@ -6,14 +6,15 @@ FROM "registry.gitlab.com/gitlab-org/cluster-integration/helm-install-image/rele # https://github.com/sgerrand/alpine-pkg-glibc ARG GLIBC_VERSION COPY src/ build/ # Install Dependencies RUN apk add --no-cache openssl curl tar gzip bash jq \ && curl -sSL -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \ && curl -sSL -O https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk \ && apk add glibc-${GLIBC_VERSION}.apk \ && apk add ruby jq \ && apk add ruby jq ruby-json \ && rm glibc-${GLIBC_VERSION}.apk COPY src/ build/ COPY assets/ assets/ RUN ln -s /build/bin/* /usr/local/bin/
README.md +8 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,14 @@ template will use the Docker image generated from this project. Changes from pre * All the other commands should be prepended with `auto-deploy`. For example, `check_kube_domain` now becomes `auto-deploy check_kube_domain`. ### v1.0.0 Before v1.0.0, auto-deploy-image was downloading a chart from [the chart repository](https://charts.gitlab.io/), which was then uploaded by the [auto-deploy-app](https://gitlab.com/gitlab-org/charts/auto-deploy-app) project. Since auto-deploy-image v1.0.0, the auto-deploy-app chart is bundled into the auto-deploy-image docker image as a local asset, and it no longer downloads the chart from the repository. # Generating a new auto-deploy image To generate a new image you must follow the git commit guidelines below, this Loading
src/bin/auto-deploy +25 −18 Original line number Diff line number Diff line Loading @@ -13,6 +13,9 @@ if [[ "$AUTO_DEVOPS_POSTGRES_CHANNEL" == "2" ]]; then elif [[ "$AUTO_DEVOPS_POSTGRES_CHANNEL" == "1" ]]; then export POSTGRES_VERSION="${POSTGRES_VERSION:-"9.6.2"}" fi export BIN_DIR="/build/bin" export ASSETS_DIR='/assets' export ASSETS_CHART_DIR="${ASSETS_DIR}/auto-deploy-app" function check_kube_domain() { if [[ -z "$KUBE_INGRESS_BASE_DOMAIN" ]]; then Loading @@ -28,28 +31,31 @@ function check_kube_domain() { } function download_chart() { helm init --client-only if [[ -d chart ]]; then echo "Download is skipped. The bundled chart in user's repository will be used." elif [[ -n "${AUTO_DEVOPS_CHART}${AUTO_DEVOPS_CHART_REPOSITORY_NAME}${AUTO_DEVOPS_CHART_REPOSITORY}" ]]; then echo "Downloading the chart from the chart repository..." local auto_chart local auto_chart_name if [[ ! -d chart ]]; then auto_chart=${AUTO_DEVOPS_CHART:-gitlab/auto-deploy-app} # shellcheck disable=SC2086 # double quote variables to prevent globbing auto_chart_name=$(basename $auto_chart) auto_chart_name=${auto_chart_name%.tgz} auto_chart_name=${auto_chart_name%.tar.gz} else auto_chart="chart" auto_chart_name="chart" fi helm init --client-only # shellcheck disable=SC2086 # double quote variables to prevent globbing # shellcheck disable=SC2140 # ambiguous quoting warning helm repo add ${AUTO_DEVOPS_CHART_REPOSITORY_NAME:-gitlab} ${AUTO_DEVOPS_CHART_REPOSITORY:-https://charts.gitlab.io} ${AUTO_DEVOPS_CHART_REPOSITORY_USERNAME:+"--username" "$AUTO_DEVOPS_CHART_REPOSITORY_USERNAME"} ${AUTO_DEVOPS_CHART_REPOSITORY_PASSWORD:+"--password" "$AUTO_DEVOPS_CHART_REPOSITORY_PASSWORD"} if [[ ! -d "$auto_chart" ]]; then helm fetch ${auto_chart} --untar fi helm fetch "${auto_chart}" --untar if [ "$auto_chart_name" != "chart" ]; then mv ${auto_chart_name} chart mv "${auto_chart_name}" chart fi else echo "Download is skipped. The bundled chart in auto-deploy-image will be used." cp -R $ASSETS_CHART_DIR chart fi helm dependency update chart/ Loading Loading @@ -203,6 +209,8 @@ channel 1 database.' old_postgres_enabled="$POSTGRES_ENABLED" fi ${BIN_DIR}/validate-chart-version "$(helm list --output json)" "chart" "$name" local database_url database_url=$(auto_database_url) Loading Loading @@ -435,7 +443,7 @@ function create_application_secret() { k8s_secrets_file=$(mktemp) /build/bin/auto-deploy-application-secrets-yaml "$k8s_secrets_file" ${BIN_DIR}/auto-deploy-application-secrets-yaml "$k8s_secrets_file" kubectl replace -f "$k8s_secrets_file" -n "$KUBE_NAMESPACE" --force Loading Loading @@ -507,7 +515,6 @@ function get_replicas() { echo 1 fi } ## ## End Helper functions Loading