8
8
description : GitHub Environment Name
9
9
default : prod
10
10
required : false
11
- url :
12
- type : string
13
- description : GitHub Environment Url (without scheme)
14
- required : true
15
11
docker-images-version :
16
12
type : string
17
13
description : Docker Images Version
18
14
default : latest
19
15
required : false
20
- cors :
21
- type : string
22
- description : CORS
23
- required : true
24
- release :
25
- type : string
26
- description : Release Name
27
- required : true
28
- namespace :
29
- type : string
30
- description : Namespace Name
31
- required : true
32
16
gke-cluster :
33
17
type : string
34
18
description : Google Kubernetes Engine Cluster
58
42
deploy :
59
43
name : Deploy
60
44
runs-on : ubuntu-latest
61
- environment :
62
- name : ${{ inputs.environment }}
63
- url : https://${{ inputs.url }}
64
45
permissions :
65
46
contents : ' read'
66
47
id-token : ' write'
90
71
helm repo add bitnami https://charts.bitnami.com/bitnami/
91
72
helm repo add stable https://charts.helm.sh/stable/
92
73
helm dependency build ./helm/api-platform
74
+ - name : Define namespace
75
+ run : |
76
+ set -o pipefail
77
+ if [[ "${{ github.ref }}" == 'refs/heads/prod' ]]; then
78
+ # Tags are deployed in prod
79
+ echo "CONTEXT=prod" >> "$GITHUB_ENV"
80
+ echo "RELEASE_NAME=website-prod" >> "$GITHUB_ENV"
81
+ echo "URL=api-platform.com" >> "$GITHUB_ENV"
82
+ echo "CORS='[\"https://api-platform.com\", \"http://localhost\", \"https://localhost\", \"http://localhost:3000\"]'" >> "$GITHUB_ENV"
83
+ echo "NAMESPACE=prod-website" >> "$GITHUB_ENV"
84
+ else
85
+ CONTEXT=nonprod
86
+ if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
87
+ echo RELEASE_NAME=pr-$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH") >> "$GITHUB_ENV"
88
+ export RELEASE_NAME=pr-$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
89
+ else
90
+ echo "RELEASE_NAME=${{ github.ref_name }}" >> "$GITHUB_ENV"
91
+ export RELEASE_NAME=${{ github.ref_name }}
92
+ fi
93
+ echo "URL=$RELEASE_NAME.apip.preprod-tilleuls.ovh" >> "$GITHUB_ENV"
94
+ echo "NAMESPACE=nonprod-website" >> "$GITHUB_ENV"
95
+ echo 'CORS=["https://${{ env.RELEASE_NAME}}.apip.preprod-tilleuls.ovh", "http://localhost", "https://localhost", "http://localhost:3000"]' >> "$GITHUB_ENV"
96
+ fi
93
97
- name : Check for existing namespace
94
98
id : k8s-namespace
95
- run : echo "namespace=$(kubectl get namespace ${{ inputs.namespace }} | tr -d '\n' 2> /dev/null)" >> $GITHUB_OUTPUT
99
+ run : echo "namespace=$(kubectl get namespace ${{ env.NAMESPACE }} | tr -d '\n' 2> /dev/null)" >> $GITHUB_OUTPUT
96
100
# Release name MUST start with a letter
97
101
# GitHub doesn't support multilines environment variables (JWT_*_KEY)
98
102
- name : Deploy in new namespace
@@ -101,14 +105,14 @@ jobs:
101
105
set -o pipefail
102
106
JWT_PASSPHRASE=$(openssl rand -base64 32)
103
107
JWT_SECRET_KEY=$(openssl genpkey -pass file:<(echo "$JWT_PASSPHRASE") -aes256 -algorithm rsa -pkeyopt rsa_keygen_bits:4096)
104
- helm upgrade ${{ inputs.release }} ./helm/api-platform \
108
+ helm upgrade ${{ env.RELEASE_NAME }} ./helm/api-platform \
105
109
--reuse-values \
106
110
--install \
107
111
--create-namespace \
108
112
--debug \
109
113
--wait \
110
114
--atomic \
111
- --namespace=${{ inputs.namespace }} \
115
+ --namespace=${{ env.NAMESPACE }} \
112
116
--set=app.version=${{ github.sha }} \
113
117
--set=php.image.repository=eu.gcr.io/${{ secrets.gke-project }}/website/php \
114
118
--set=php.image.tag=${{ inputs.docker-images-version }} \
@@ -123,18 +127,18 @@ jobs:
123
127
--set=bucket.s3Name=api-platform-website-v3 \
124
128
--set=service.type=NodePort \
125
129
--set=ingress.enabled=true \
126
- --set=ingress.hosts[0].host=${{ inputs.url }} \
130
+ --set=ingress.hosts[0].host=${{ env.URL }} \
127
131
--set=ingress.hosts[0].paths[0].path=/ \
128
132
--set=ingress.hosts[0].paths[0].pathType=ImplementationSpecific \
129
- --set=ingress.tls[0].hosts[0]=${{ inputs.url }} \
133
+ --set=ingress.tls[0].hosts[0]=${{ env.URL }} \
130
134
--set=ingress.annotations."cert-manager\.io/cluster-issuer"=letsencrypt-production \
131
- --set=ingress.tls[0].secretName=website-ssl \
135
+ --set=ingress.tls[0].secretName=${{ env.RELEASE_NAME }}- website-ssl \
132
136
--set=php.jwt.secretKey="$JWT_SECRET_KEY" \
133
137
--set=php.jwt.publicKey="$(openssl pkey -in <(echo "$JWT_SECRET_KEY") -passin file:<(echo "$JWT_PASSPHRASE") -pubout)" \
134
138
--set=php.jwt.passphrase=$JWT_PASSPHRASE \
135
- --set=php.corsAllowOrigin="^$(echo "${{ join(fromJSON(inputs.cors ), '|') }}" | sed 's/\./\\./g')$" \
136
- --set=php.host=${{ inputs.url }} \
137
- --set=next.rootUrl=${{ inputs.url }} \
139
+ --set=php.corsAllowOrigin="^$(echo "${{ join(fromJSON(env.CORS ), '|') }}" | sed 's/\./\\./g')$" \
140
+ --set=php.host=${{ env.URL }} \
141
+ --set=next.rootUrl=${{ env.URL }} \
138
142
--set=github.key=${{ secrets.gh-key }} \
139
143
--set=ressources.requests.cpu=250m \
140
144
--set=ressources.requests.memory=256Mi \
@@ -146,14 +150,14 @@ jobs:
146
150
if : steps.k8s-namespace.outputs.namespace != ''
147
151
run : |
148
152
set -o pipefail
149
- helm upgrade ${{ inputs.release }} ./helm/api-platform \
153
+ helm upgrade ${{ env.RELEASE_NAME }} ./helm/api-platform \
150
154
--reuse-values \
151
155
--install \
152
156
--create-namespace \
153
157
--debug \
154
158
--wait \
155
159
--atomic \
156
- --namespace=${{ inputs.namespace }} \
160
+ --namespace=${{ env.NAMESPACE }} \
157
161
--set=app.version=${{ github.sha }} \
158
162
--set=php.image.repository=eu.gcr.io/${{ secrets.gke-project }}/website/php \
159
163
--set=php.image.tag=${{ inputs.docker-images-version }} \
@@ -164,9 +168,9 @@ jobs:
164
168
--set=pwa.image.repository=eu.gcr.io/${{ secrets.gke-project }}/website/pwa \
165
169
--set=pwa.image.tag=${{ inputs.docker-images-version }} \
166
170
--set=pwa.image.pullPolicy=Always \
167
- --set=php.corsAllowOrigin="^$(echo "${{ join(fromJSON(inputs.cors ), '|') }}" | sed 's/\./\\./g')$" \
171
+ --set=php.corsAllowOrigin="^$(echo "${{ join(fromJSON(env.CORS ), '|') }}" | sed 's/\./\\./g')$" \
168
172
--set=github.key=${{ secrets.gh-key }} \
169
- --set=next.rootUrl=${{ inputs.url }} \
173
+ --set=next.rootUrl=${{ env.URL }} \
170
174
--set=ressources.requests.cpu=250m \
171
175
--set=ressources.requests.memory=256Mi \
172
176
--set=ressources.limits.memory=700Mi \
@@ -175,4 +179,4 @@ jobs:
175
179
| sed --unbuffered '/USER-SUPPLIED VALUES/,$d'
176
180
- name : Debug kube events
177
181
if : failure()
178
- run : kubectl get events --namespace=${{ inputs.namespace }} --sort-by .metadata.creationTimestamp
182
+ run : kubectl get events --namespace=${{ env.NAMESPACE }} --sort-by .metadata.creationTimestamp
0 commit comments