Skip to content

Commit

Permalink
chore: deploy with kustomize
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsOveTen committed Nov 27, 2024
1 parent cd343cf commit 0fd0742
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 9 deletions.
19 changes: 15 additions & 4 deletions .github/workflows/deploy-prod&demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,35 @@ on:
workflow_dispatch:

jobs:
build-and-deploy-production:
build-user-api:
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: user-api
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-user-api ]
uses: Informasjonsforvaltning/workflows/.github/workflows/kustomize-deploy.yaml@main
with:
app_name: user-api
environment: prod
cluster: digdir-fdk-prod
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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: user-api
environment: demo
Expand Down
28 changes: 23 additions & 5 deletions .github/workflows/deploy-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,36 @@ on:
- main

jobs:
build-and-deploy-staging:
name: Call reusable workflow when pull request is created
if: github.event.pull_request.draft == false
uses: Informasjonsforvaltning/workflows/.github/workflows/build-deploy-maven.yaml@main
build-user-api:
name: Build when pull request is created
if: ${{ github.actor != 'dependabot[bot]' && github.event.pull_request.draft == false }}
uses: Informasjonsforvaltning/workflows/.github/workflows/build-push.yaml@main
with:
app_name: user-api
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-user-api ]
uses: Informasjonsforvaltning/workflows/.github/workflows/kustomize-deploy.yaml@main
with:
app_name: user-api
environment: staging
cluster: digdir-fdk-dev
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DIGDIR_FDK_AUTODEPLOY: ${{ secrets.DIGDIR_FDK_DEV_AUTODEPLOY }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
DEPENDABOT_SLACK_WEBHOOK_URL: ${{ secrets.DEPENDABOT_SLACK_WEBHOOK_URL }}

dependabot-build:
name: Build image on PR from dependabot
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }}
uses: Informasjonsforvaltning/workflows/.github/workflows/build.yaml@main
with:
java_version: '21'
10 changes: 10 additions & 0 deletions deploy/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- user-api-deployment.yaml
- user-api-service.yaml
images:
- name: user-api
newName: ghcr.io/informasjonsforvaltning/user-api
newTag: $(GIT_COMMIT_SHA)
48 changes: 48 additions & 0 deletions deploy/base/user-api-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
fdk.service: user-api
name: user-api
spec:
replicas: 1
selector:
matchLabels:
fdk.service: user-api
strategy:
type: RollingUpdate
template:
metadata:
labels:
fdk.service: user-api
spec:
containers:
- name: user-api
image: user-api
imagePullPolicy: Always
ports:
- containerPort: 8080
resources:
requests:
memory: "500Mi"
cpu: "10m"
limits:
memory: "500Mi"
livenessProbe:
httpGet:
path: /ping
port: 8080
initialDelaySeconds: 20
periodSeconds: 30
successThreshold: 1
failureThreshold: 5
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 20
periodSeconds: 30
successThreshold: 1
failureThreshold: 5
restartPolicy: Always
14 changes: 14 additions & 0 deletions deploy/base/user-api-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
labels:
fdk.service: user-api
name: user-api
spec:
type: NodePort
ports:
- name: "8080"
port: 8080
targetPort: 8080
selector:
fdk.service: user-api
73 changes: 73 additions & 0 deletions deploy/demo/env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: user-api
labels:
app: user-api
spec:
template:
spec:
containers:
- name: user-api
env:
- name: ALTINN_PROXY_HOST
valueFrom:
secretKeyRef:
name: commonurl-demo
key: ALTINN_PROXY_URL
- name: ORGNR_WHITELIST
valueFrom:
secretKeyRef:
name: user-api-demo
key: ORGNR_WHITELIST
- name: ORGFORM_WHITELIST
valueFrom:
secretKeyRef:
name: user-api-demo
key: ORGFORM_WHITELIST
- name: ADMIN_LIST
valueFrom:
secretKeyRef:
name: user-api-demo
key: ADMIN_LIST
- name: SSO_API_KEY
valueFrom:
secretKeyRef:
name: common-demo
key: SSO_API_KEY
- name: USER_API_KEY
valueFrom:
secretKeyRef:
name: common-demo
key: USER_API_KEY
- name: WRITE_GROUP_BRREG
valueFrom:
secretKeyRef:
name: user-api-demo
key: BRREG_OIDC_WRITE_GROUP
- name: ADMIN_GROUP_BRREG
valueFrom:
secretKeyRef:
name: user-api-demo
key: BRREG_OIDC_ADMIN_GROUP
- name: ADMIN_GROUP_SKATT
valueFrom:
secretKeyRef:
name: user-api-demo
key: SKATT_OIDC_ADMIN_GROUP
- name: WRITE_GROUP_SKATT
valueFrom:
secretKeyRef:
name: user-api-demo
key: SKATT_OIDC_WRITE_GROUP
- name: READ_GROUP_SKATT
valueFrom:
secretKeyRef:
name: user-api-demo
key: SKATT_OIDC_READ_GROUP
- name: TERMS_AND_CONDITIONS_HOST
valueFrom:
secretKeyRef:
name: commonurl-demo
key: FDK_TERMS_AND_CONDITIONS_BASE_URI
9 changes: 9 additions & 0 deletions deploy/demo/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: demo
resources:
- ../base

patches:
- path: env.yaml
73 changes: 73 additions & 0 deletions deploy/prod/env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: user-api
labels:
app: user-api
spec:
template:
spec:
containers:
- name: user-api
env:
- name: ALTINN_PROXY_HOST
valueFrom:
secretKeyRef:
name: commonurl-prod
key: ALTINN_PROXY_URL
- name: ORGNR_WHITELIST
valueFrom:
secretKeyRef:
name: user-api-prod
key: ORGNR_WHITELIST
- name: ORGFORM_WHITELIST
valueFrom:
secretKeyRef:
name: user-api-prod
key: ORGFORM_WHITELIST
- name: ADMIN_LIST
valueFrom:
secretKeyRef:
name: user-api-prod
key: ADMIN_LIST
- name: SSO_API_KEY
valueFrom:
secretKeyRef:
name: common-prod
key: SSO_API_KEY
- name: USER_API_KEY
valueFrom:
secretKeyRef:
name: common-prod
key: USER_API_KEY
- name: WRITE_GROUP_BRREG
valueFrom:
secretKeyRef:
name: user-api-prod
key: BRREG_OIDC_WRITE_GROUP
- name: ADMIN_GROUP_BRREG
valueFrom:
secretKeyRef:
name: user-api-prod
key: BRREG_OIDC_ADMIN_GROUP
- name: ADMIN_GROUP_SKATT
valueFrom:
secretKeyRef:
name: user-api-prod
key: SKATT_OIDC_ADMIN_GROUP
- name: WRITE_GROUP_SKATT
valueFrom:
secretKeyRef:
name: user-api-prod
key: SKATT_OIDC_WRITE_GROUP
- name: READ_GROUP_SKATT
valueFrom:
secretKeyRef:
name: user-api-prod
key: SKATT_OIDC_READ_GROUP
- name: TERMS_AND_CONDITIONS_HOST
valueFrom:
secretKeyRef:
name: commonurl-prod
key: FDK_TERMS_AND_CONDITIONS_BASE_URI
9 changes: 9 additions & 0 deletions deploy/prod/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: prod
resources:
- ../base

patches:
- path: env.yaml
73 changes: 73 additions & 0 deletions deploy/staging/env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: user-api
labels:
app: user-api
spec:
template:
spec:
containers:
- name: user-api
env:
- name: ALTINN_PROXY_HOST
valueFrom:
secretKeyRef:
name: commonurl-staging
key: ALTINN_PROXY_URL
- name: ORGNR_WHITELIST
valueFrom:
secretKeyRef:
name: user-api-staging
key: ORGNR_WHITELIST
- name: ORGFORM_WHITELIST
valueFrom:
secretKeyRef:
name: user-api-staging
key: ORGFORM_WHITELIST
- name: ADMIN_LIST
valueFrom:
secretKeyRef:
name: user-api-staging
key: ADMIN_LIST
- name: SSO_API_KEY
valueFrom:
secretKeyRef:
name: common-staging
key: SSO_API_KEY
- name: USER_API_KEY
valueFrom:
secretKeyRef:
name: common-staging
key: USER_API_KEY
- name: WRITE_GROUP_BRREG
valueFrom:
secretKeyRef:
name: user-api-staging
key: BRREG_OIDC_WRITE_GROUP
- name: ADMIN_GROUP_BRREG
valueFrom:
secretKeyRef:
name: user-api-staging
key: BRREG_OIDC_ADMIN_GROUP
- name: ADMIN_GROUP_SKATT
valueFrom:
secretKeyRef:
name: user-api-staging
key: SKATT_OIDC_ADMIN_GROUP
- name: WRITE_GROUP_SKATT
valueFrom:
secretKeyRef:
name: user-api-staging
key: SKATT_OIDC_WRITE_GROUP
- name: READ_GROUP_SKATT
valueFrom:
secretKeyRef:
name: user-api-staging
key: SKATT_OIDC_READ_GROUP
- name: TERMS_AND_CONDITIONS_HOST
valueFrom:
secretKeyRef:
name: commonurl-staging
key: FDK_TERMS_AND_CONDITIONS_BASE_URI
Loading

0 comments on commit 0fd0742

Please sign in to comment.