-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (86 loc) · 3.09 KB
/
Copy pathdeploy-k8s-client-preview.yml
File metadata and controls
99 lines (86 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: PR Preview
on:
pull_request:
types: [opened, synchronize, reopened, closed]
paths:
- 'web-client/**'
- 'infra/k8s/preview/**'
- '.github/workflows/deploy-k8s-client-preview.yml'
concurrency:
group: preview-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
contents: read
packages: write
pull-requests: write
env:
# gets prefixed with the PR number
PREVIEW_DOMAIN: devsecops.stud.k8s.aet.cit.tum.de
jobs:
deploy:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
environment: kubernetes
steps:
- name: Checkout PR head
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Image prefix
run: echo "IMAGE_PREFIX=ghcr.io/$(echo "$GITHUB_REPOSITORY" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build web-client
uses: docker/build-push-action@v6
with:
context: web-client
push: true
tags: ${{ env.IMAGE_PREFIX }}/web-client:preview-pr-${{ github.event.pull_request.number }}
- name: Set up kubectl
uses: azure/setup-kubectl@v4
- name: Configure kubeconfig
run: |
mkdir -p ~/.kube
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config
- name: Deploy preview
id: deploy
env:
WEB_CLIENT_IMAGE: ${{ env.IMAGE_PREFIX }}/web-client:preview-pr-${{ github.event.pull_request.number }}
run: |
url=$(infra/k8s/preview/deploy.sh "${{ github.event.pull_request.number }}")
echo "url=$url" >> "$GITHUB_OUTPUT"
- name: Comment preview URL
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.pull_request.number }}
header: preview
message: 🚀 [Frontend preview ↗](${{ steps.deploy.outputs.url }}) · commit `${{ github.event.pull_request.head.sha }}`
teardown:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
environment: kubernetes
steps:
- uses: actions/checkout@v4
- name: Set up kubectl
uses: azure/setup-kubectl@v4
- name: Configure kubeconfig
run: |
mkdir -p ~/.kube
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config
- name: Tear down preview
run: |
PR="${{ github.event.pull_request.number }}"
kubectl delete deployment,service,ingress -n app -l "preview-pr=$PR"
kubectl delete secret "preview-pr-$PR-tls" -n app --ignore-not-found
- name: Update comment
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.pull_request.number }}
header: preview
message: 🧹 The preview environment was removed because this PR was closed.