From dc4e0fe9aa58fa979b9d0d5dcfc5afc21324df65 Mon Sep 17 00:00:00 2001 From: Rose Yemelyanova Date: Wed, 3 Aug 2022 12:52:50 +0000 Subject: [PATCH 01/10] testing output of metadata action --- .github/workflows/helm.yml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/helm.yml b/.github/workflows/helm.yml index 6181661..091e311 100644 --- a/.github/workflows/helm.yml +++ b/.github/workflows/helm.yml @@ -3,7 +3,7 @@ name: Helm CI on: ['push'] env: - GCR_IMAGE: ghcr.io/rayemelyanova/diffcalc_api_helm + GCR_IMAGE: ghcr.io/rayemelyanova/diffcalc-api HELM_VERSION: 0.1.0 jobs: @@ -22,8 +22,19 @@ jobs: run: | echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${{ env.GCR_IMAGE }} --username ${{ github.repository_owner }} --password-stdin - - name: package chart and push it + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: print stuff run: | - helm dependencies update helm/diffcalc-api - helm package helm/diffcalc-api -d /tmp/ - helm push /tmp/diffcalc-api-${{ env.HELM_VERSION }}.tgz oci://ghcr.io/rayemelyanova/charts \ No newline at end of file + echo ${{ steps.meta.outputs.labels }} + echo ${{ steps.meta.outputs.tags }} + + # - name: package chart and push it + # run: | + # helm dependencies update helm/diffcalc-api + # helm package helm/diffcalc-api -d /tmp/ + # helm push /tmp/diffcalc-api-${{ env.HELM_VERSION }}.tgz oci://ghcr.io/rayemelyanova/charts \ No newline at end of file From 4d1ec5f00450376994e8a73cdb662072bcb57e8f Mon Sep 17 00:00:00 2001 From: Rose Yemelyanova Date: Wed, 3 Aug 2022 13:37:14 +0000 Subject: [PATCH 02/10] changed helm/container CI to only run on push of tag, specified helm version to install from metadata action outputs --- .github/workflows/container.yml | 7 +++++-- .github/workflows/helm.yml | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index a7d3d4b..a428cbc 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -1,6 +1,9 @@ name: Container CI -on: ['push'] +on: + push: + tags: + - 'v*' env: REGISTRY: ghcr.io @@ -35,5 +38,5 @@ jobs: with: context: . push: true - tags: ${{ steps.meta.outputs.tags }} + tags: ${{ steps.meta.outputs.tags }}, latest labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/helm.yml b/.github/workflows/helm.yml index 091e311..ff81473 100644 --- a/.github/workflows/helm.yml +++ b/.github/workflows/helm.yml @@ -1,6 +1,9 @@ name: Helm CI -on: ['push'] +on: + push: + tags: + - 'v*' env: GCR_IMAGE: ghcr.io/rayemelyanova/diffcalc-api @@ -27,14 +30,13 @@ jobs: uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=tag + - - name: print stuff + - name: package chart and push it run: | - echo ${{ steps.meta.outputs.labels }} - echo ${{ steps.meta.outputs.tags }} - - # - name: package chart and push it - # run: | - # helm dependencies update helm/diffcalc-api - # helm package helm/diffcalc-api -d /tmp/ - # helm push /tmp/diffcalc-api-${{ env.HELM_VERSION }}.tgz oci://ghcr.io/rayemelyanova/charts \ No newline at end of file + helm dependencies update helm/diffcalc-api + helm package helm/diffcalc-api --version ${{ fromJSON(steps.meta.outputs.json).args["DOCKER_META_VERSION"] }} -d /tmp/ + helm push /tmp/diffcalc-api-${{ fromJSON(steps.meta.outputs.json).args["DOCKER_META_VERSION"] }}.tgz oci://ghcr.io/rayemelyanova/charts \ No newline at end of file From 12ad07ab5199f4677bca1cf6c7d2791f826e2dac Mon Sep 17 00:00:00 2001 From: Rose Yemelyanova Date: Wed, 3 Aug 2022 13:40:50 +0000 Subject: [PATCH 03/10] changed to single quotes for workflow --- .github/workflows/helm.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/helm.yml b/.github/workflows/helm.yml index ff81473..2647142 100644 --- a/.github/workflows/helm.yml +++ b/.github/workflows/helm.yml @@ -38,5 +38,5 @@ jobs: - name: package chart and push it run: | helm dependencies update helm/diffcalc-api - helm package helm/diffcalc-api --version ${{ fromJSON(steps.meta.outputs.json).args["DOCKER_META_VERSION"] }} -d /tmp/ - helm push /tmp/diffcalc-api-${{ fromJSON(steps.meta.outputs.json).args["DOCKER_META_VERSION"] }}.tgz oci://ghcr.io/rayemelyanova/charts \ No newline at end of file + helm package helm/diffcalc-api --version ${{ fromJSON(steps.meta.outputs.json).args['DOCKER_META_VERSION'] }} -d /tmp/ + helm push /tmp/diffcalc-api-${{ fromJSON(steps.meta.outputs.json).args['DOCKER_META_VERSION'] }}.tgz oci://ghcr.io/rayemelyanova/charts \ No newline at end of file From bd10756265fd6a3557dc1b5f5f43fcc821847490 Mon Sep 17 00:00:00 2001 From: Rose Yemelyanova Date: Wed, 3 Aug 2022 13:44:41 +0000 Subject: [PATCH 04/10] changed to using output tags from metadata-action --- .github/workflows/helm.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/helm.yml b/.github/workflows/helm.yml index 2647142..1f0ed30 100644 --- a/.github/workflows/helm.yml +++ b/.github/workflows/helm.yml @@ -38,5 +38,5 @@ jobs: - name: package chart and push it run: | helm dependencies update helm/diffcalc-api - helm package helm/diffcalc-api --version ${{ fromJSON(steps.meta.outputs.json).args['DOCKER_META_VERSION'] }} -d /tmp/ - helm push /tmp/diffcalc-api-${{ fromJSON(steps.meta.outputs.json).args['DOCKER_META_VERSION'] }}.tgz oci://ghcr.io/rayemelyanova/charts \ No newline at end of file + helm package helm/diffcalc-api --version ${{ steps.meta.outputs.tags. }} -d /tmp/ + helm push /tmp/diffcalc-api-${{ steps.meta.outputs.tags }}.tgz oci://ghcr.io/rayemelyanova/charts \ No newline at end of file From 1ed5dc5eaa33fba89bd2d091053145e8a4216b5f Mon Sep 17 00:00:00 2001 From: Rose Yemelyanova Date: Wed, 3 Aug 2022 13:46:08 +0000 Subject: [PATCH 05/10] fixed syntax error --- .github/workflows/helm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/helm.yml b/.github/workflows/helm.yml index 1f0ed30..b32762d 100644 --- a/.github/workflows/helm.yml +++ b/.github/workflows/helm.yml @@ -38,5 +38,5 @@ jobs: - name: package chart and push it run: | helm dependencies update helm/diffcalc-api - helm package helm/diffcalc-api --version ${{ steps.meta.outputs.tags. }} -d /tmp/ + helm package helm/diffcalc-api --version ${{ steps.meta.outputs.tags }} -d /tmp/ helm push /tmp/diffcalc-api-${{ steps.meta.outputs.tags }}.tgz oci://ghcr.io/rayemelyanova/charts \ No newline at end of file From 917f5669ab11971712c9a9f6a5be822262325d54 Mon Sep 17 00:00:00 2001 From: Rose Yemelyanova Date: Wed, 3 Aug 2022 13:56:58 +0000 Subject: [PATCH 06/10] added env variable for tag to eliminate the characters in metadata-action outputs --- .github/workflows/helm.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/helm.yml b/.github/workflows/helm.yml index b32762d..7da9b1e 100644 --- a/.github/workflows/helm.yml +++ b/.github/workflows/helm.yml @@ -36,7 +36,10 @@ jobs: - name: package chart and push it + env: + TAG: echo ${{ steps.meta.outputs.tags }} | grep -oP 'v[0-9.]+' run: | + echo '$TAG' helm dependencies update helm/diffcalc-api - helm package helm/diffcalc-api --version ${{ steps.meta.outputs.tags }} -d /tmp/ - helm push /tmp/diffcalc-api-${{ steps.meta.outputs.tags }}.tgz oci://ghcr.io/rayemelyanova/charts \ No newline at end of file + helm package helm/diffcalc-api --version $TAG -d /tmp/ + helm push /tmp/diffcalc-api-$TAG.tgz oci://ghcr.io/rayemelyanova/charts \ No newline at end of file From 423318e5bf08c88d5e25a3f7c121c2d0ef000b40 Mon Sep 17 00:00:00 2001 From: Rose Yemelyanova Date: Wed, 3 Aug 2022 14:04:37 +0000 Subject: [PATCH 07/10] using github_ref --- .github/workflows/helm.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/helm.yml b/.github/workflows/helm.yml index 7da9b1e..bc81309 100644 --- a/.github/workflows/helm.yml +++ b/.github/workflows/helm.yml @@ -33,13 +33,10 @@ jobs: tags: | type=ref,event=branch type=ref,event=tag - + - name: package chart and push it - env: - TAG: echo ${{ steps.meta.outputs.tags }} | grep -oP 'v[0-9.]+' run: | - echo '$TAG' helm dependencies update helm/diffcalc-api - helm package helm/diffcalc-api --version $TAG -d /tmp/ - helm push /tmp/diffcalc-api-$TAG.tgz oci://ghcr.io/rayemelyanova/charts \ No newline at end of file + helm package helm/diffcalc-api --version ${GITHUB_REF##*/} -d /tmp/ + helm push /tmp/diffcalc-api-${GITHUB_REF##*/}.tgz oci://ghcr.io/rayemelyanova/charts \ No newline at end of file From 454ae2c87f9dd242a440eb40978aa3de54548bac Mon Sep 17 00:00:00 2001 From: Rose Yemelyanova Date: Wed, 3 Aug 2022 14:14:40 +0000 Subject: [PATCH 08/10] added separate job for latest image --- .github/workflows/container.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index a428cbc..c4acec0 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -33,10 +33,18 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - name: Build and push Docker image + - name: Build and push Docker tagged image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: context: . push: true - tags: ${{ steps.meta.outputs.tags }}, latest + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Build and push Docker latest image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + push: true + tags: latest labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file From 2c21a2677e3317fd25257c03c9d9e5c8b43097b6 Mon Sep 17 00:00:00 2001 From: Rose Yemelyanova Date: Wed, 3 Aug 2022 14:19:29 +0000 Subject: [PATCH 09/10] removed latest image tag generation --- .github/workflows/container.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index c4acec0..6259b9c 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -39,12 +39,4 @@ jobs: context: . push: true tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - - name: Build and push Docker latest image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - with: - context: . - push: true - tags: latest labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file From 3c1f86bb79d2f17dde244f8397769441421b1b2a Mon Sep 17 00:00:00 2001 From: Rose Yemelyanova Date: Thu, 4 Aug 2022 08:59:43 +0000 Subject: [PATCH 10/10] added helper function to automatically work out mongodb url in helm chart --- helm/diffcalc-api/templates/_helpers.tpl | 7 +++++++ helm/diffcalc-api/templates/deployment.yaml | 2 +- helm/diffcalc-api/values.yaml | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/helm/diffcalc-api/templates/_helpers.tpl b/helm/diffcalc-api/templates/_helpers.tpl index 6aa10d8..d808f3e 100644 --- a/helm/diffcalc-api/templates/_helpers.tpl +++ b/helm/diffcalc-api/templates/_helpers.tpl @@ -5,6 +5,13 @@ Expand the name of the chart. {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} {{- end }} +{{/* +Set the kubernetes service that diffcalc-api will use to communicate to mongo. +*/}} +{{- define "diffcalc-api.mongoUrl" }} +{{- .Values.mongodb.urlOverride | default (tpl "{{ .Release.Name }}-mongodb:27017" . ) }} +{{- end }} + {{/* Create a default fully qualified app name. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). diff --git a/helm/diffcalc-api/templates/deployment.yaml b/helm/diffcalc-api/templates/deployment.yaml index 1148f18..bbbfc03 100644 --- a/helm/diffcalc-api/templates/deployment.yaml +++ b/helm/diffcalc-api/templates/deployment.yaml @@ -35,7 +35,7 @@ spec: imagePullPolicy: {{ .Values.image.pullPolicy }} env: - name: mongo_url - value: {{ .Values.mongodb.url }} + value: {{ include "diffcalc-api.mongoUrl" . }} ports: - name: http containerPort: 8000 diff --git a/helm/diffcalc-api/values.yaml b/helm/diffcalc-api/values.yaml index 44f0ff6..6c02802 100644 --- a/helm/diffcalc-api/values.yaml +++ b/helm/diffcalc-api/values.yaml @@ -5,7 +5,7 @@ replicaCount: 1 image: - repository: gcr.io/diamond-pubreg/diffcalc/api + repository: ghcr.io/rayemelyanova/charts/diffcalc-api pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. tag: latest @@ -83,7 +83,7 @@ affinity: {} mongodb: enabled: true - url: diffcalc-api-mongodb:27017 + urlOverride: "" serviceAccount: create: false # architecture: standalone