From 8004871d58aca0c02a4656a7115b887fa40780ac Mon Sep 17 00:00:00 2001 From: Nils Ove Tendenes Date: Fri, 29 Nov 2024 08:34:57 +0100 Subject: [PATCH] chore: kustomize deploy --- .github/workflows/deploy-prod&demo.yaml | 21 ++++++-- .github/workflows/deploy-staging.yaml | 24 +++++++--- ...dk-dataset-preview-service-deployment.yaml | 48 +++++++++++++++++++ .../fdk-dataset-preview-service-service.yaml | 14 ++++++ deploy/base/kustomization.yaml | 10 ++++ deploy/demo/env.yaml | 28 +++++++++++ deploy/demo/kustomization.yaml | 9 ++++ deploy/prod/env.yaml | 28 +++++++++++ deploy/prod/kustomization.yaml | 9 ++++ deploy/staging/env.yaml | 28 +++++++++++ deploy/staging/kustomization.yaml | 9 ++++ 11 files changed, 216 insertions(+), 12 deletions(-) create mode 100644 deploy/base/fdk-dataset-preview-service-deployment.yaml create mode 100644 deploy/base/fdk-dataset-preview-service-service.yaml create mode 100644 deploy/base/kustomization.yaml create mode 100644 deploy/demo/env.yaml create mode 100644 deploy/demo/kustomization.yaml create mode 100644 deploy/prod/env.yaml create mode 100644 deploy/prod/kustomization.yaml create mode 100644 deploy/staging/env.yaml create mode 100644 deploy/staging/kustomization.yaml diff --git a/.github/workflows/deploy-prod&demo.yaml b/.github/workflows/deploy-prod&demo.yaml index e20493f..81db4e7 100644 --- a/.github/workflows/deploy-prod&demo.yaml +++ b/.github/workflows/deploy-prod&demo.yaml @@ -7,24 +7,35 @@ on: workflow_dispatch: jobs: - build-and-deploy-production: + build-fdk-dataset-preview-service: name: Deploy to prod on merge to main branch - uses: Informasjonsforvaltning/workflows/.github/workflows/build-deploy-maven.yaml@main + uses: Informasjonsforvaltning/workflows/.github/workflows/build-push.yaml@main with: app_name: fdk-dataset-preview-service java_version: '21' + coverage_file_path: ./target/site/jacoco/jacoco.xml + environment: prod + secrets: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + deploy-prod: + name: Deploy to prod environment + needs: [ build-fdk-dataset-preview-service ] + uses: Informasjonsforvaltning/workflows/.github/workflows/kustomize-deploy.yaml@main + with: + app_name: fdk-dataset-preview-service environment: prod cluster: digdir-fdk-prod secrets: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GCP_SA_DIGDIR_FDK_GCR_KEY: ${{ secrets.GCP_SA_DIGDIR_FDK_GCR_KEY }} DIGDIR_FDK_AUTODEPLOY: ${{ secrets.DIGDIR_FDK_PROD_AUTODEPLOY }} SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} deploy-to-demo: - needs: build-and-deploy-production + needs: deploy-prod name: Deploy to demo if prod-deploy is successful - uses: Informasjonsforvaltning/workflows/.github/workflows/deploy.yaml@main + uses: Informasjonsforvaltning/workflows/.github/workflows/kustomize-deploy.yaml@main with: app_name: fdk-dataset-preview-service environment: demo diff --git a/.github/workflows/deploy-staging.yaml b/.github/workflows/deploy-staging.yaml index 6e73609..e945352 100644 --- a/.github/workflows/deploy-staging.yaml +++ b/.github/workflows/deploy-staging.yaml @@ -7,26 +7,36 @@ on: - main jobs: - build-and-deploy-staging: - name: Call reusable workflow when pull request is created + build-fdk-dataset-preview-service: + name: Build when pull request is created if: ${{ github.actor != 'dependabot[bot]' && github.event.pull_request.draft == false }} - uses: Informasjonsforvaltning/workflows/.github/workflows/build-deploy-maven.yaml@main + uses: Informasjonsforvaltning/workflows/.github/workflows/build-push.yaml@main with: app_name: fdk-dataset-preview-service java_version: '21' + coverage_file_path: ./target/site/jacoco/jacoco.xml + environment: staging + secrets: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + deploy-to-staging: + name: Deploy to staging environment + if: ${{ github.actor != 'dependabot[bot]' && github.event.pull_request.draft == false }} + needs: [ build-fdk-dataset-preview-service ] + uses: Informasjonsforvaltning/workflows/.github/workflows/kustomize-deploy.yaml@main + with: + app_name: fdk-dataset-preview-service environment: staging cluster: digdir-fdk-dev secrets: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GCP_SA_DIGDIR_FDK_GCR_KEY: ${{ secrets.GCP_SA_DIGDIR_FDK_GCR_KEY }} DIGDIR_FDK_AUTODEPLOY: ${{ secrets.DIGDIR_FDK_DEV_AUTODEPLOY }} SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} dependabot-build: name: Build image on PR from dependabot - if: ${{ github.actor == 'dependabot[bot]' }} + if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }} uses: Informasjonsforvaltning/workflows/.github/workflows/build.yaml@main with: java_version: '21' - secrets: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/deploy/base/fdk-dataset-preview-service-deployment.yaml b/deploy/base/fdk-dataset-preview-service-deployment.yaml new file mode 100644 index 0000000..92d7185 --- /dev/null +++ b/deploy/base/fdk-dataset-preview-service-deployment.yaml @@ -0,0 +1,48 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + fdk.service: fdk-dataset-preview-service + name: fdk-dataset-preview-service +spec: + replicas: 1 + selector: + matchLabels: + fdk.service: fdk-dataset-preview-service + strategy: + type: RollingUpdate + template: + metadata: + labels: + fdk.service: fdk-dataset-preview-service + spec: + containers: + - name: fdk-dataset-preview-service + image: fdk-dataset-preview-service + imagePullPolicy: Always + ports: + - containerPort: 8080 + resources: + requests: + memory: "750Mi" + cpu: "10m" + limits: + memory: "750Mi" + livenessProbe: + httpGet: + path: /ping + port: 8080 + initialDelaySeconds: 20 + periodSeconds: 30 + successThreshold: 1 + failureThreshold: 5 + readinessProbe: + httpGet: + path: /ready + port: 8080 + initialDelaySeconds: 150 + periodSeconds: 30 + successThreshold: 1 + failureThreshold: 5 + restartPolicy: Always diff --git a/deploy/base/fdk-dataset-preview-service-service.yaml b/deploy/base/fdk-dataset-preview-service-service.yaml new file mode 100644 index 0000000..0177e9c --- /dev/null +++ b/deploy/base/fdk-dataset-preview-service-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + fdk.service: fdk-dataset-preview-service + name: fdk-dataset-preview-service +spec: + type: NodePort + ports: + - name: "8080" + port: 8080 + targetPort: 8080 + selector: + fdk.service: fdk-dataset-preview-service diff --git a/deploy/base/kustomization.yaml b/deploy/base/kustomization.yaml new file mode 100644 index 0000000..fad9e48 --- /dev/null +++ b/deploy/base/kustomization.yaml @@ -0,0 +1,10 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - fdk-dataset-preview-service-deployment.yaml + - fdk-dataset-preview-service-service.yaml +images: + - name: fdk-dataset-preview-service + newName: ghcr.io/informasjonsforvaltning/fdk-dataset-preview-service + newTag: $(GIT_COMMIT_SHA) diff --git a/deploy/demo/env.yaml b/deploy/demo/env.yaml new file mode 100644 index 0000000..e59a0e9 --- /dev/null +++ b/deploy/demo/env.yaml @@ -0,0 +1,28 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: fdk-dataset-preview-service + labels: + app: fdk-dataset-preview-service +spec: + template: + spec: + containers: + - name: fdk-dataset-preview-service + env: + - name: NAMESPACE + valueFrom: + secretKeyRef: + name: common-demo + key: NAMESPACE + - name: API_KEY + valueFrom: + secretKeyRef: + name: common-demo + key: FDK_DATASET_PREVIEW_API_KEY + - name: ALLOWED_ORIGINS + valueFrom: + secretKeyRef: + name: common-demo + key: FDK_DATASET_PREVIEW_ALLOWED_ORIGINS diff --git a/deploy/demo/kustomization.yaml b/deploy/demo/kustomization.yaml new file mode 100644 index 0000000..83f2c77 --- /dev/null +++ b/deploy/demo/kustomization.yaml @@ -0,0 +1,9 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: demo +resources: + - ../base + +patches: + - path: env.yaml diff --git a/deploy/prod/env.yaml b/deploy/prod/env.yaml new file mode 100644 index 0000000..156c440 --- /dev/null +++ b/deploy/prod/env.yaml @@ -0,0 +1,28 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: fdk-dataset-preview-service + labels: + app: fdk-dataset-preview-service +spec: + template: + spec: + containers: + - name: fdk-dataset-preview-service + env: + - name: NAMESPACE + valueFrom: + secretKeyRef: + name: common-prod + key: NAMESPACE + - name: API_KEY + valueFrom: + secretKeyRef: + name: common-prod + key: FDK_DATASET_PREVIEW_API_KEY + - name: ALLOWED_ORIGINS + valueFrom: + secretKeyRef: + name: common-prod + key: FDK_DATASET_PREVIEW_ALLOWED_ORIGINS diff --git a/deploy/prod/kustomization.yaml b/deploy/prod/kustomization.yaml new file mode 100644 index 0000000..913810f --- /dev/null +++ b/deploy/prod/kustomization.yaml @@ -0,0 +1,9 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: prod +resources: + - ../base + +patches: + - path: env.yaml diff --git a/deploy/staging/env.yaml b/deploy/staging/env.yaml new file mode 100644 index 0000000..5be69b9 --- /dev/null +++ b/deploy/staging/env.yaml @@ -0,0 +1,28 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: fdk-dataset-preview-service + labels: + app: fdk-dataset-preview-service +spec: + template: + spec: + containers: + - name: fdk-dataset-preview-service + env: + - name: NAMESPACE + valueFrom: + secretKeyRef: + name: common-staging + key: NAMESPACE + - name: API_KEY + valueFrom: + secretKeyRef: + name: common-staging + key: FDK_DATASET_PREVIEW_API_KEY + - name: ALLOWED_ORIGINS + valueFrom: + secretKeyRef: + name: common-staging + key: FDK_DATASET_PREVIEW_ALLOWED_ORIGINS diff --git a/deploy/staging/kustomization.yaml b/deploy/staging/kustomization.yaml new file mode 100644 index 0000000..71c8924 --- /dev/null +++ b/deploy/staging/kustomization.yaml @@ -0,0 +1,9 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: staging +resources: + - ../base + +patches: + - path: env.yaml