From 9c53bfbdd76b905732d714dbf55a8ad65dd635cf Mon Sep 17 00:00:00 2001 From: Lasse Gaardsholt Date: Mon, 16 Oct 2023 15:26:43 +0200 Subject: [PATCH 1/5] will it blend? Signed-off-by: Lasse Gaardsholt --- .circleci/config.yml | 36 +++++++++++++ .github/workflows/release-chart.yml | 84 ----------------------------- 2 files changed, 36 insertions(+), 84 deletions(-) delete mode 100644 .github/workflows/release-chart.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index b109f7f..90afbcd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -95,6 +95,30 @@ jobs: source $BASH_ENV ct install --config ct.yaml --helm-extra-set-args "--set=image.tag=$DEPLOY_TAG" --target-branch master + publish_chart: + executor: + name: cci-common/ci_image + flavor: "-google" + parameters: + version: + type: string + steps: + - checkout + - attach_workspace: + at: /tmp + - cci-common/install_gcloud + - cci-common/gcloud_login + - run: + name: "Package and push helm chart" + command: | + source /tmp/secrets || true + + export GOOGLE_APPLICATION_CREDENTIALS=/tmp/cluster_secret.json + + gcloud auth application-default print-access-token | helm registry login -u oauth2accesstoken --password-stdin https://$K8S_CLUSTER_artifact_registry_url + + helm package charts/nightscaler --version << parameters.version >> + helm push nightscaler-<< parameters.version >>.tgz oci://$K8S_CLUSTER_artifact_registry_url/$K8S_CLUSTER_artifact_registry_project/public-docker workflows: build: @@ -129,3 +153,15 @@ workflows: - cci-common/go_test_unit - cci-common/go_test_sonar - cci-common/build_n_push_docker + publish_prod_chart: + jobs: + - secret-injector/dump-secrets: + <<: *prod_context + - publish_chart: + name: Publish Prod Chart + version: $DEPLOY_TAG + pre-steps: + - generate_docker_tag + <<: *prod_context + requires: + - secret-injector/dump-secrets diff --git a/.github/workflows/release-chart.yml b/.github/workflows/release-chart.yml deleted file mode 100644 index dd3e0da..0000000 --- a/.github/workflows/release-chart.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: Release Chart - -on: - push: - tags: - - "chart-*" - -jobs: - release: - runs-on: ubuntu-latest - permissions: - contents: write - # packages: write - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Configure Git - run: | - git config user.name "$GITHUB_ACTOR" - git config user.email "$GITHUB_ACTOR@users.noreply.github.com" - - - uses: cardinalby/git-get-release-action@v1 - name: Get Latest Chart Release - id: get_chart_release - env: - GITHUB_TOKEN: ${{ github.token }} - with: - latest: true - draft: false - releaseNameRegEx: '^chart-[0-9]+\.[0-9]+\.[0-9]+$' - - - uses: cardinalby/git-get-release-action@v1 - name: Get Latest App Release - id: get_app_release - env: - GITHUB_TOKEN: ${{ github.token }} - with: - latest: true - draft: false - releaseNameRegEx: '^v[0-9]+\.[0-9]+\.[0-9]+$' - - - name: Replace Strings In Chart - run: | - # Remove prefix '-chart' from tag name - CHART_TAG_NAME=${{ steps.get_chart_release.outputs.tag_name }} - CHART_TAG_NAME=${CHART_TAG_NAME#chart-} - APP_TAG_NAME=${{ steps.get_app_release.outputs.tag_name }} - APP_TAG_NAME=${APP_TAG_NAME#v} - - # Replace strings in charts/nightscaler/Chart.yaml - sed -i "s/appVersion: .*/appVersion: $APP_TAG_NAME/" charts/nightscaler/Chart.yaml - sed -i "s/version: .*/version: $CHART_TAG_NAME/" charts/nightscaler/Chart.yaml - - - name: Install Chart Releaser - run: | - # Get the tar file - curl -L -o chart-releaser.tar.gz https://github.com/helm/chart-releaser/releases/download/v1.6.0/chart-releaser_1.6.0_linux_amd64.tar.gz - # Untar the file - tar -zxvf chart-releaser.tar.gz - # Make executable - chmod +x cr - - name: Package and Upload Chart - env: - GH_TOKEN: ${{ github.token }} - run: | - # Package the chart - ./cr package charts/nightscaler - - # Old upload but doesn't work because of release drafter. 'cr upload' create an release. - # ./cr upload -o BESTSELLER -r nightscaler -p .cr-release-packages --release-name-template ${{ steps.get_chart_release.outputs.tag_name }} --token ${{ secrets.GITHUB_TOKEN }} - - # Create small release-tag - CHART_SEMVER=${{ steps.get_chart_release.outputs.tag_name }} - CHART_SEMVER=${CHART_SEMVER#chart-} - - # Upload the chart to the release - gh release upload ${{ steps.get_chart_release.outputs.tag_name }} ".cr-release-packages/nightscaler-$CHART_SEMVER.tgz" - - name: Update Chart index - run: | - mkdir -p .cr-index - ./cr index -o BESTSELLER -r nightscaler --push --release-name-template ${{ steps.get_chart_release.outputs.tag_name }} --token ${{ secrets.GITHUB_TOKEN }} From 2f5ebb4f9fe16ccd109f82f09d667fad906942c8 Mon Sep 17 00:00:00 2001 From: Lasse Gaardsholt Date: Tue, 17 Oct 2023 10:09:27 +0200 Subject: [PATCH 2/5] no need to have two workflows Signed-off-by: Lasse Gaardsholt --- .circleci/config.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 90afbcd..a305eb9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,6 +23,7 @@ commands: else echo "export DEPLOY_TAG=$(echo $CIRCLE_TAG)" >> $BASH_ENV fi + jobs: lint-test: machine: @@ -121,7 +122,7 @@ jobs: helm push nightscaler-<< parameters.version >>.tgz oci://$K8S_CLUSTER_artifact_registry_url/$K8S_CLUSTER_artifact_registry_project/public-docker workflows: - build: + build-n-publish: jobs: - secret-injector/dump-secrets-yaml: secret-file: secrets-ci.yaml @@ -129,7 +130,7 @@ workflows: <<: *prod_context - cci-common/go_test_unit: go_version: "1.21.3" - resource_class: large + resource_class: xlarge requires: - secret-injector/dump-secrets-yaml - cci-common/go_test_sonar: @@ -153,15 +154,10 @@ workflows: - cci-common/go_test_unit - cci-common/go_test_sonar - cci-common/build_n_push_docker - publish_prod_chart: - jobs: - - secret-injector/dump-secrets: - <<: *prod_context - publish_chart: - name: Publish Prod Chart version: $DEPLOY_TAG pre-steps: - generate_docker_tag <<: *prod_context requires: - - secret-injector/dump-secrets + - lint-test From cd424ba47a088b6fa91bbc80e3bbe7a61dede502 Mon Sep 17 00:00:00 2001 From: Lasse Gaardsholt Date: Tue, 17 Oct 2023 10:11:48 +0200 Subject: [PATCH 3/5] chart and app will use the same version now! Signed-off-by: Lasse Gaardsholt --- .github/release-drafter-helm.yml | 43 ---------------------- .github/release-drafter.yml | 7 ---- .github/workflows/release-drafter-helm.yml | 35 ------------------ 3 files changed, 85 deletions(-) delete mode 100644 .github/release-drafter-helm.yml delete mode 100644 .github/workflows/release-drafter-helm.yml diff --git a/.github/release-drafter-helm.yml b/.github/release-drafter-helm.yml deleted file mode 100644 index f9de9f8..0000000 --- a/.github/release-drafter-helm.yml +++ /dev/null @@ -1,43 +0,0 @@ -name-template: "chart-$RESOLVED_VERSION" -tag-template: "chart-$RESOLVED_VERSION" -include-labels: - - helm-chart -tag-prefix: "chart-" -categories: - - title: Breaking Changes 💥 - labels: - - breaking-change - - title: New Features 🎉 - labels: - - new-feature - - title: Bug Fixes 🐛 - labels: - - patch - - title: Dependencies 📌 - labels: - - dependencies - - title: Other Changes 🛠 -change-template: "- $TITLE @$AUTHOR (#$NUMBER)" -change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. -version-resolver: - major: - labels: - - "major" - - "breaking-change" - minor: - labels: - - "minor" - - "new-feature" - patch: - labels: - - "patch" - default: patch -autolabeler: - - label: helm-chart - files: - - "chart/**" -template: | - - $CHANGES - - **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...chart-$RESOLVED_VERSION diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 007f991..8bb99cf 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,7 +1,5 @@ name-template: "v$RESOLVED_VERSION" tag-template: "v$RESOLVED_VERSION" -include-labels: - - app tag-prefix: "v" categories: - title: Breaking Changes 💥 @@ -32,12 +30,7 @@ version-resolver: labels: - "patch" default: patch -autolabeler: - - label: app - files: - - "!chart/**" template: | - $CHANGES **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION diff --git a/.github/workflows/release-drafter-helm.yml b/.github/workflows/release-drafter-helm.yml deleted file mode 100644 index 90e5ead..0000000 --- a/.github/workflows/release-drafter-helm.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Release Drafter Helm - -on: - push: - # branches to consider in the event; optional, defaults to all - branches: - - master - # pull_request event is required only for autolabeler - pull_request: - # Only following types are handled by the action, but one can default to all as well - types: [opened, reopened, synchronize] - # pull_request_target event is required for autolabeler to support PRs from forks - # pull_request_target: - # types: [opened, reopened, synchronize] - -jobs: - update_release_draft: - permissions: - contents: "write" - pull-requests: "write" - runs-on: ubuntu-latest - steps: - # (Optional) GitHub Enterprise requires GHE_HOST variable set - #- name: Set GHE_HOST - # run: | - # echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV - - # Drafts your next Release notes as Pull Requests are merged into "master" - - uses: release-drafter/release-drafter@v5 - # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml - with: - config-name: release-drafter-helm.yml - # disable-autolabeler: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 20ba7ebf891a583b98d1a41d7cca28b30832382f Mon Sep 17 00:00:00 2001 From: Lasse Gaardsholt Date: Tue, 17 Oct 2023 11:21:17 +0200 Subject: [PATCH 4/5] will this work? Signed-off-by: Lasse Gaardsholt --- .circleci/config.yml | 2 +- charts/nightscaler/templates/deployment.yaml | 12 ++++++++---- charts/nightscaler/values.yaml | 5 ++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a305eb9..1a20089 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -119,7 +119,7 @@ jobs: gcloud auth application-default print-access-token | helm registry login -u oauth2accesstoken --password-stdin https://$K8S_CLUSTER_artifact_registry_url helm package charts/nightscaler --version << parameters.version >> - helm push nightscaler-<< parameters.version >>.tgz oci://$K8S_CLUSTER_artifact_registry_url/$K8S_CLUSTER_artifact_registry_project/public-docker + helm push nightscaler-<< parameters.version >>.tgz oci://$K8S_CLUSTER_artifact_registry_url/$K8S_CLUSTER_artifact_registry_project/public-docker/chart workflows: build-n-publish: diff --git a/charts/nightscaler/templates/deployment.yaml b/charts/nightscaler/templates/deployment.yaml index 1f7f916..11ce826 100644 --- a/charts/nightscaler/templates/deployment.yaml +++ b/charts/nightscaler/templates/deployment.yaml @@ -32,15 +32,19 @@ spec: env: - name: NIGHTSCALER_PROJECT_ID value: {{ .Values.pubsub.projectId }} - - name: NIGHTSCALER_TOPIC - value: {{ .Values.pubsub.topic }} - - name: NIGHTSCALER_CLUSTERNAME - value: {{ .Values.pubsub.clustername }} + - name: NIGHTSCALER_LISTEN_TOPIC + value: {{ .Values.pubsub.listen_topic }} + - name: NIGHTSCALER_PUBLISH_TOPIC + value: {{ .Values.pubsub.publish_topic }} - name: NIGHTSCALER_TIMEZONE value: {{ .Values.podEnvVars.timezone }} - name: NIGHTSCALER_DEBUG value: "{{ .Values.podEnvVars.debug }}" - name: NIGHTSCALER_JSON_LOGGING value: "{{ .Values.podEnvVars.jsonLogging }}" + {{- if .Values.pubsub.clustername }} + - name: NIGHTSCALER_CLUSTERNAME + value: {{ .Values.pubsub.clustername }} + {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} diff --git a/charts/nightscaler/values.yaml b/charts/nightscaler/values.yaml index 8bda4d5..ca196c5 100644 --- a/charts/nightscaler/values.yaml +++ b/charts/nightscaler/values.yaml @@ -10,7 +10,10 @@ pubsub: projectId: "" # Pub/Sub topic to subscribe to # REQUIRED - topic: "" + listen_topic: "" + # Pub/Sub topic to publish to + # REQUIRED + publish_topic: "" # Name of the cluster it is running in. Used to identify the cluster in the Pub/Sub message. # REQUIRED clustername: "" From 69cbe6a510eeea7ac925604365b8c6064e022db4 Mon Sep 17 00:00:00 2001 From: Lasse Gaardsholt Date: Tue, 17 Oct 2023 11:40:23 +0200 Subject: [PATCH 5/5] setting app-version as well Signed-off-by: Lasse Gaardsholt --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1a20089..c79c357 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -118,7 +118,7 @@ jobs: gcloud auth application-default print-access-token | helm registry login -u oauth2accesstoken --password-stdin https://$K8S_CLUSTER_artifact_registry_url - helm package charts/nightscaler --version << parameters.version >> + helm package charts/nightscaler --app-version << parameters.version >> --version << parameters.version >> helm push nightscaler-<< parameters.version >>.tgz oci://$K8S_CLUSTER_artifact_registry_url/$K8S_CLUSTER_artifact_registry_project/public-docker/chart workflows: