diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml new file mode 100644 index 0000000..6259b9c --- /dev/null +++ b/.github/workflows/container.yml @@ -0,0 +1,42 @@ +name: Container CI + +on: + push: + tags: + - 'v*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker tagged image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/helm.yml b/.github/workflows/helm.yml new file mode 100644 index 0000000..bc81309 --- /dev/null +++ b/.github/workflows/helm.yml @@ -0,0 +1,42 @@ +name: Helm CI + +on: + push: + tags: + - 'v*' + +env: + GCR_IMAGE: ghcr.io/rayemelyanova/diffcalc-api + HELM_VERSION: 0.1.0 + +jobs: + build: + name: publish gcr + runs-on: ubuntu-latest + environment: prod + steps: + - name: checkout repo + uses: actions/checkout@v2 + + - name: install helm + uses: Azure/setup-helm@v1 + + - name: login to acr using helm + run: | + echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${{ env.GCR_IMAGE }} --username ${{ github.repository_owner }} --password-stdin + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=tag + + + - name: package chart and push it + run: | + helm dependencies update helm/diffcalc-api + 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 diff --git a/.github/workflows/images.yml b/.github/workflows/images.yml deleted file mode 100644 index 22bbb21..0000000 --- a/.github/workflows/images.yml +++ /dev/null @@ -1,76 +0,0 @@ -name: Container and Helm CI - -# on: -# push: -# tags: -# - 'v*' - -on: ["push"] - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - build-and-push-container-image: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Log in to the Container registry - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - - name: Build and push Docker image - uses: docker/build-push-action@v3 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - package-and-publish-helm-chart: - needs: build-and-push-container-image - runs-on: ubuntu-latest - environment: prod - steps: - - name: checkout repo - uses: actions/checkout@v2 - - - name: install helm - uses: Azure/setup-helm@v1 - - - name: login to acr using helm - run: | - echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${{ env.GCR_IMAGE }} --username ${{ github.repository_owner }} --password-stdin - - - name: Extract metadata (tags, labels) - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - - name: test meta - 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 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