Skip to content

Commit 76e77c1

Browse files
pasibunCopilot
andcommitted
feat: add workflows for production and test deployment [deploy-test]
Co-authored-by: Copilot <copilot@github.com>
1 parent 4b78290 commit 76e77c1

2 files changed

Lines changed: 203 additions & 0 deletions

File tree

.github/workflows/deploy-prod.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Deploy to Production
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
env:
10+
IMAGE_NAME: ghcr.io/${{ github.repository }}
11+
INFRA_REPO: ${{ vars.INFRA_REPO }}
12+
KUSTOMIZE_PATH: ${{ vars.KUSTOMIZE_PATH }}
13+
DEPLOY_ENV: prod
14+
15+
jobs:
16+
create-infra-pr:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Parse infra repository
20+
id: infra-repo
21+
run: |
22+
INFRA_REPO="${{ env.INFRA_REPO }}"
23+
24+
if [[ -z "$INFRA_REPO" || "$INFRA_REPO" != */* ]]; then
25+
echo "INFRA_REPO moet de vorm owner/repo hebben, huidige waarde: '$INFRA_REPO'" >&2
26+
exit 1
27+
fi
28+
29+
echo "owner=${INFRA_REPO%%/*}" >> "$GITHUB_OUTPUT"
30+
echo "repo=${INFRA_REPO#*/}" >> "$GITHUB_OUTPUT"
31+
32+
- name: Genereer app token (Release proces app)
33+
id: app-token
34+
uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859
35+
with:
36+
app-id: ${{ secrets.RELEASE_PROCES_APP_ID }}
37+
private-key: ${{ secrets.RELEASE_PROCES_APP_PRIVATE_KEY }}
38+
owner: ${{ steps.infra-repo.outputs.owner }}
39+
repositories: ${{ steps.infra-repo.outputs.repo }}
40+
41+
- name: Checkout don-infra
42+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
43+
with:
44+
repository: ${{ env.INFRA_REPO }}
45+
token: ${{ steps.app-token.outputs.token }}
46+
47+
- name: Maak release branch aan in don-infra
48+
id: branch
49+
run: |
50+
BRANCH="release/don-site-${{ github.sha }}"
51+
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
52+
git checkout -b "$BRANCH"
53+
54+
- name: Update image tag in prod overlay
55+
run: |
56+
KUSTOMIZATION_FILE="${{ env.KUSTOMIZE_PATH }}${{ env.DEPLOY_ENV }}/kustomization.yaml"
57+
58+
yq e '(.images[] | select(.newName == "${{ env.IMAGE_NAME }}")).newTag = "${{ github.sha }}"' -i "$KUSTOMIZATION_FILE"
59+
60+
- name: Commit en push release branch
61+
run: |
62+
KUSTOMIZATION_FILE="${{ env.KUSTOMIZE_PATH }}${{ env.DEPLOY_ENV }}/kustomization.yaml"
63+
64+
git config user.name "${{ github.actor }}"
65+
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
66+
git add "$KUSTOMIZATION_FILE"
67+
git commit -m "release: don-tools-api → ${{ github.sha }}
68+
69+
Commit: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}"
70+
git push origin "${{ steps.branch.outputs.branch }}"
71+
72+
- name: Maak PR aan in don-infra
73+
env:
74+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
75+
run: |
76+
gh pr create \
77+
--repo "${{ env.INFRA_REPO }}" \
78+
--base main \
79+
--head "${{ steps.branch.outputs.branch }}" \
80+
--title "Release: don-tools-api → ${GITHUB_SHA::7}" \
81+
--body "## don-tools-api productie deploy
82+
83+
**Image:** \`${{ env.IMAGE_NAME }}:${{ github.sha }}\`
84+
**Branch:** \`${{ github.ref_name }}\`
85+
**Commit:** ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}
86+
87+
Merge deze PR om de nieuwe versie naar productie te deployen."

.github/workflows/deploy-test.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Deploy to Test
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches-ignore:
7+
- main
8+
9+
env:
10+
IMAGE_NAME: ghcr.io/${{ github.repository }}
11+
INFRA_REPO: ${{ vars.INFRA_REPO }}
12+
KUSTOMIZE_PATH: ${{ vars.KUSTOMIZE_PATH }}
13+
DEPLOY_ENV: test
14+
15+
jobs:
16+
check-keyword:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
deploy: ${{ steps.check.outputs.deploy }}
20+
steps:
21+
- name: Check commit message for deploy keyword
22+
id: check
23+
env:
24+
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
25+
run: |
26+
# Keyword: [deploy-test] anywhere in de commit message
27+
# Voorbeeld: "feat: nieuwe feature [deploy-test]"
28+
if echo "$COMMIT_MESSAGE" | grep -qi "\[deploy-test\]"; then
29+
echo "deploy=true" >> $GITHUB_OUTPUT
30+
echo "Deploy keyword gevonden in commit message."
31+
else
32+
echo "deploy=false" >> $GITHUB_OUTPUT
33+
echo "Geen deploy keyword gevonden, sla deploy over."
34+
fi
35+
36+
build-and-push:
37+
needs: check-keyword
38+
if: |
39+
needs.check-keyword.outputs.deploy == 'true'
40+
runs-on: ubuntu-latest
41+
permissions:
42+
contents: read
43+
packages: write
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
47+
48+
- name: Set up Docker Buildx
49+
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd
50+
51+
- name: Login to container registry
52+
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2
53+
with:
54+
registry: ghcr.io
55+
username: ${{ github.actor }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
58+
- name: Build and push image
59+
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294
60+
with:
61+
context: .
62+
push: true
63+
tags: |
64+
${{ env.IMAGE_NAME }}:test
65+
${{ env.IMAGE_NAME }}:${{ github.sha }}
66+
67+
update-infra-test:
68+
needs: build-and-push
69+
runs-on: ubuntu-latest
70+
steps:
71+
- name: Parse infra repository
72+
id: infra-repo
73+
run: |
74+
INFRA_REPO="${{ env.INFRA_REPO }}"
75+
76+
if [[ -z "$INFRA_REPO" || "$INFRA_REPO" != */* ]]; then
77+
echo "INFRA_REPO moet de vorm owner/repo hebben, huidige waarde: '$INFRA_REPO'" >&2
78+
exit 1
79+
fi
80+
81+
echo "owner=${INFRA_REPO%%/*}" >> "$GITHUB_OUTPUT"
82+
echo "repo=${INFRA_REPO#*/}" >> "$GITHUB_OUTPUT"
83+
84+
- name: Genereer app token (Release proces app)
85+
id: app-token
86+
uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859
87+
with:
88+
app-id: ${{ secrets.RELEASE_PROCES_APP_ID }}
89+
private-key: ${{ secrets.RELEASE_PROCES_APP_PRIVATE_KEY }}
90+
owner: ${{ steps.infra-repo.outputs.owner }}
91+
repositories: ${{ steps.infra-repo.outputs.repo }}
92+
93+
- name: Checkout don-infra
94+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
95+
with:
96+
repository: ${{ env.INFRA_REPO }}
97+
token: ${{ steps.app-token.outputs.token }}
98+
99+
- name: Update image tag in test overlay
100+
run: |
101+
KUSTOMIZATION_FILE="${{ env.KUSTOMIZE_PATH }}${{ env.DEPLOY_ENV }}/kustomization.yaml"
102+
103+
yq e '(.images[] | select(.newName == "${{ env.IMAGE_NAME }}")).newTag = "${{ github.sha }}"' -i "$KUSTOMIZATION_FILE"
104+
105+
- name: Commit en push naar don-infra
106+
run: |
107+
KUSTOMIZATION_FILE="${{ env.KUSTOMIZE_PATH }}${{ env.DEPLOY_ENV }}/kustomization.yaml"
108+
109+
git config user.name "${{ github.actor }}"
110+
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
111+
git add "$KUSTOMIZATION_FILE"
112+
git commit -m "test: don-tools-api → ${{ github.sha }}
113+
114+
Branch: ${{ github.ref_name }}
115+
Commit: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}"
116+
git push

0 commit comments

Comments
 (0)