-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (141 loc) · 6.11 KB
/
ai-days-website.yml
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Documentation: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses
name: ai_days_website_github_workflow
run-name: AI Days Website GitHub Workflow
env:
## Development environment variables
# The Kubernetes namespace that the service should be deployed to
DEV_NAMESPACE: ${{ vars.DEV_NAMESPACE }}
# Kube configuration
DEV_KUBE_CONFIG: ${{ secrets.DEV_KUBE_CONFIG }}
# The URL that the service (dev) should be accessible at
DEV_FRONTEND_HOST: ${{ vars.DEV_FRONTEND_HOST }}
## Production environment variables
# The Kubernetes namespace that the service should be deployed to
PROD_NAMESPACE: ${{ vars.PROD_NAMESPACE }}
# Kube configuration
PROD_KUBE_CONFIG: ${{ secrets.PROD_KUBE_CONFIG }}
# The URL that the service (prod) should be accessible at
PROD_FRONTEND_HOST: ${{ vars.PROD_FRONTEND_HOST }}
# Allow one concurrent deployment
concurrency:
group: "ai-days-website"
cancel-in-progress: true
on:
push:
branches:
- main
pull_request:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
run-workflow-dev:
runs-on: ubuntu-latest
if: ${{ vars.RUN_CICD == 'true' }}
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Set up Node.js 20.11.1
uses: actions/setup-node@v3
with:
node-version: 20.11.1
- name: Install dependencies
working-directory: .
run: npm ci
- name: Build app
working-directory: .
env:
# So it does not treat warnings as errors
CI: false
run: npm run build
- name: Build and push Docker image to GitHub
id: build-and-push-docker-image-to-github
if: ${{ vars.RUN_CICD == 'true' && success() && github.ref == 'refs/heads/main' && vars.DEPLOY_DEV == 'true' }}
uses: swiss-ai-center/common-code/.github/actions/build-and-push-docker-image-to-github@main
with:
docker-registry-username: ${{ github.actor }}
docker-registry-password: ${{ secrets.GITHUB_TOKEN }}
docker-image-name: ${{ github.repository }}-dev
docker-image-context: .
- name: Prepare configuration files
if: ${{ vars.RUN_CICD == 'true' && success() && github.ref == 'refs/heads/main' && vars.DEPLOY_DEV == 'true' }}
shell: bash
working-directory: ./kubernetes
env:
DEV_FRONTEND_HOST: ${{ env.DEV_FRONTEND_HOST }}
run: |
# Set version
docker_image_tags=(${{ steps.build-and-push-docker-image-to-github.outputs.docker-image-tags }})
docker_image_sha_tag="${docker_image_tags[1]}"
yq -i ".spec.template.spec.containers[0].image = \"$docker_image_sha_tag\"" stateful.yml
# Set configuration (Ingress)
yq -i "del(.metadata.annotations.cert-manager\.io/cluster-issuer)" ingress.yml
yq -i "del(.spec.ingressClassName)" ingress.yml
yq -i ".spec.rules[0].host = \"${DEV_FRONTEND_HOST#*://}\"" ingress.yml
yq -i ".spec.tls[0].hosts[0] = \"${DEV_FRONTEND_HOST#*://}\"" ingress.yml
yq -i "del(.spec.tls[0].secretName)" ingress.yml
- name: Deploy Website on the Kubernetes cluster
if: ${{ vars.RUN_CICD == 'true' && success() && github.ref == 'refs/heads/main' && vars.DEPLOY_DEV == 'true' }}
uses: swiss-ai-center/common-code/.github/actions/execute-command-on-kubernetes-cluster@main
with:
kube-config: ${{ env.DEV_KUBE_CONFIG }}
kube-namespace: ${{ env.DEV_NAMESPACE }}
kubectl-context: ./kubernetes
kubectl-args: |
apply \
-f stateful.yml \
-f service.yml \
-f ingress.yml
run-workflow-prod:
runs-on: ubuntu-latest
if: ${{ vars.RUN_CICD == 'true' }}
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Set up Node.js 20.11.1
uses: actions/setup-node@v3
with:
node-version: 20.11.1
- name: Install dependencies
working-directory: .
run: npm ci
- name: Build app
working-directory: .
env:
# So it does not treat warnings as errors
CI: false
run: npm run build
- name: Build and push Docker image to GitHub
id: build-and-push-docker-image-to-github
if: ${{ vars.RUN_CICD == 'true' && success() && github.ref == 'refs/heads/main' && vars.DEPLOY_PROD == 'true' }}
uses: swiss-ai-center/common-code/.github/actions/build-and-push-docker-image-to-github@main
with:
docker-registry-username: ${{ github.actor }}
docker-registry-password: ${{ secrets.GITHUB_TOKEN }}
docker-image-name: ${{ github.repository }}
docker-image-context: .
- name: Prepare configuration files
if: ${{ vars.RUN_CICD == 'true' && success() && github.ref == 'refs/heads/main' && vars.DEPLOY_PROD == 'true' }}
shell: bash
working-directory: ./kubernetes
env:
PROD_FRONTEND_HOST: ${{ env.PROD_FRONTEND_HOST }}
run: |
# Set version
docker_image_tags=(${{ steps.build-and-push-docker-image-to-github.outputs.docker-image-tags }})
docker_image_sha_tag="${docker_image_tags[1]}"
yq -i ".spec.template.spec.containers[0].image = \"$docker_image_sha_tag\"" stateful.yml
# Set configuration (Ingress)
yq -i ".spec.rules[0].host = \"${PROD_FRONTEND_HOST#*://}\"" ingress.yml
yq -i ".spec.tls[0].hosts[0] = \"${PROD_FRONTEND_HOST#*://}\"" ingress.yml
- name: Deploy Website on the Kubernetes cluster
if: ${{ vars.RUN_CICD == 'true' && success() && github.ref == 'refs/heads/main' && vars.DEPLOY_PROD == 'true' }}
uses: swiss-ai-center/common-code/.github/actions/execute-command-on-kubernetes-cluster@main
with:
kube-config: ${{ env.PROD_KUBE_CONFIG }}
kube-namespace: ${{ env.PROD_NAMESPACE }}
kubectl-context: ./kubernetes
kubectl-args: |
apply \
-f stateful.yml \
-f service.yml \
-f ingress.yml