8
8
pr_number :
9
9
description : " PR number"
10
10
required : true
11
+ skip_build :
12
+ description : " Skip build job"
13
+ required : false
14
+ default : false
11
15
12
16
env :
13
17
REPO : ghcr.io/coder/coder-preview
62
66
63
67
- name : Comment on PR
64
68
id : comment_id
69
+ if : github.event_name == 'issue_comment'
65
70
uses : peter-evans/create-or-update-comment@v3
66
71
with :
67
72
issue-number : ${{ steps.pr_info.outputs.PR_NUMBER }}
72
77
73
78
build :
74
79
needs : pr_commented
80
+ # Skips the build job if the workflow was triggered by a workflow_dispatch event and the skip_build input is set to true
81
+ # or if the workflow was triggered by an issue_comment event and the comment body contains --skip-build
82
+ if : (github.event_name == 'workflow_dispatch' && github.event.inputs.skip_build == 'false') || (github.event_name == 'issue_comment' && contains(github.event.comment.body, '--skip-build') != true)
75
83
runs-on : ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
76
84
env :
77
85
DOCKER_CLI_EXPERIMENTAL : " enabled"
@@ -119,16 +127,32 @@ jobs:
119
127
120
128
deploy :
121
129
needs : [build, pr_commented]
122
- if : needs.build.result == 'success'
130
+ # Run deploy job only if build job was successful or skipped
131
+ if : always() && (needs.build.result == 'success' || needs.build.result == 'skipped')
123
132
runs-on : " ubuntu-latest"
124
133
env :
125
134
CODER_IMAGE_TAG : ${{ needs.pr_commented.outputs.CODER_IMAGE_TAG }}
126
135
PR_NUMBER : ${{ needs.pr_commented.outputs.PR_NUMBER }}
127
136
PR_TITLE : ${{ needs.pr_commented.outputs.PR_TITLE }}
128
137
PR_URL : ${{ needs.pr_commented.outputs.PR_URL }}
138
+ PR_BRANCH : ${{ needs.pr_commented.outputs.PR_BRANCH }}
139
+ PR_DEPLOYMENT_ACCESS_URL : " https://pr${{ needs.pr_commented.outputs.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
129
140
steps :
141
+ - name : Check if image exists
142
+ run : |
143
+ set -euxo pipefail
144
+ foundTag=$(curl -fsSL https://github.com/coder/coder/pkgs/container/coder-preview | grep -o ${{ env.CODER_IMAGE_TAG }} | head -n 1)
145
+ if [ -z "$foundTag" ]; then
146
+ echo "Image not found"
147
+ echo "${{ env.CODER_IMAGE_TAG }} not found in ghcr.io/coder/coder-preview"
148
+ echo "Please remove --skip-build from the comment or ./scripts/deploy-pr.sh"
149
+ exit 1
150
+ fi
151
+
130
152
- name : Checkout
131
153
uses : actions/checkout@v3
154
+ with :
155
+ ref : ${{ env.PR_BRANCH }}
132
156
133
157
- name : Set up kubeconfig
134
158
run : |
@@ -157,6 +181,7 @@ jobs:
157
181
spec:
158
182
tls:
159
183
- hosts:
184
+ - "${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
160
185
- "*.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
161
186
secretName: pr${{ env.PR_NUMBER }}-tls
162
187
rules:
@@ -173,32 +198,39 @@ jobs:
173
198
EOF
174
199
kubectl apply -f ingress.yaml
175
200
201
+ - name : Create values.yaml
202
+ run : |
203
+ cat <<EOF > pr-deploy-values.yaml
204
+ coder:
205
+ image:
206
+ repo: ${{ env.REPO }}
207
+ tag: pr${{ env.PR_NUMBER }}
208
+ pullPolicy: Always
209
+ service:
210
+ type: ClusterIP
211
+ env:
212
+ - name: "CODER_ACCESS_URL"
213
+ value: "https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
214
+ - name: "CODER_WILDCARD_ACCESS_URL"
215
+ value: "*--pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
216
+ - name: "CODER_EXPERIMENTS"
217
+ value: "*"
218
+ - name: "CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS"
219
+ value: "true"
220
+ - name: "CODER_OAUTH2_GITHUB_CLIENT_ID"
221
+ value: "${{ secrets.PR_DEPLOYMENTS_GITHUB_OAUTH_CLIENT_ID }}"
222
+ - name: "CODER_OAUTH2_GITHUB_CLIENT_SECRET"
223
+ value: "${{ secrets.PR_DEPLOYMENTS_GITHUB_OAUTH_CLIENT_SECRET }}"
224
+ - name: "CODER_OAUTH2_GITHUB_ALLOWED_ORGS"
225
+ value: "coder"
226
+ EOF
227
+
176
228
- name : Install Helm chart
177
229
run : |
178
- helm upgrade --install pr${{ env.PR_NUMBER }} ./helm \
230
+ helm upgrade --install " pr${{ env.PR_NUMBER }}" ./helm \
179
231
--namespace "pr${{ env.PR_NUMBER }}" \
180
- --set coder.image.repo=${{ env.REPO }} \
181
- --set coder.image.tag=pr${{ env.PR_NUMBER }} \
182
- --set coder.service.type=ClusterIP \
183
- --set coder.serviceAccount.enableDeployments=true \
184
- --set coder.env[0].name=CODER_ACCESS_URL \
185
- --set coder.env[0].value="https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}" \
186
- --set coder.env[1].name=CODER_WILDCARD_ACCESS_URL \
187
- --set coder.env[1].value="*--pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}" \
188
- --set coder.env[2].name=CODER_EXPERIMENTS \
189
- --set coder.env[2].value="*" \
232
+ --values ./pr-deploy-values.yaml \
190
233
--force
191
- # Uncomment this when https://github.com/coder/coder/issues/8714 is resolved
192
- # --set coder.env[3].name=CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS \
193
- # --set coder.env[3].value=true \
194
- # --set coder.env[4].name=CODER_OAUTH2_GITHUB_CLIENT_ID \
195
- # --set coder.env[4].value=${{ secrets.PR_DEPLOYMENTS_GITHUB_OAUTH_CLIENT_ID }} \
196
- # --set coder.env[5].name=CODER_OAUTH2_GITHUB_CLIENT_SECRET \
197
- # --set coder.env[5].value=${{ secrets.PR_DEPLOYMENTS_GITHUB_OAUTH_CLIENT_SECRET }} \
198
- # --set coder.env[6].name=CODER_OAUTH2_GITHUB_ALLOWED_ORGS \
199
- # --set coder.env[6].value=coder \
200
- # --set coder.env[7].name=CODER_OAUTH2_GITHUB_REDIRECT_URI \
201
- # --set coder.env[7].value="https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}/gitauth/github/callback
202
234
203
235
- name : Install coder-logstream-kube
204
236
run : |
@@ -207,28 +239,95 @@ jobs:
207
239
--namespace "pr${{ env.PR_NUMBER }}" \
208
240
--set url="https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
209
241
242
+ - name : Get Coder binary
243
+ run : |
244
+ set -euxo pipefail
245
+
246
+ DEST="${HOME}/coder"
247
+ URL="${{ env.PR_DEPLOYMENT_ACCESS_URL }}/bin/coder-linux-amd64"
248
+
249
+ mkdir -p "$(dirname ${DEST})"
250
+
251
+ COUNT=0
252
+ until $(curl --output /dev/null --silent --head --fail "$URL"); do
253
+ printf '.'
254
+ sleep 5
255
+ COUNT=$((COUNT+1))
256
+ if [ $COUNT -ge 60 ]; then
257
+ echo "Timed out waiting for URL to be available"
258
+ exit 1
259
+ fi
260
+ done
261
+
262
+ curl -fsSL "$URL" -o "${DEST}"
263
+ chmod +x "${DEST}"
264
+ "${DEST}" version
265
+
266
+ - name : Create first user, template and workspace
267
+ id : setup_deployment
268
+ run : |
269
+ set -euxo pipefail
270
+
271
+ # Create first user
272
+
273
+ # create a masked random password 12 characters long
274
+ password=$(openssl rand -base64 16 | tr -d "=+/" | cut -c1-12)
275
+
276
+ # add mask so that the password is not printed to the logs
277
+ echo "::add-mask::$password"
278
+ echo "password=$password" >> $GITHUB_OUTPUT
279
+
280
+ /home/runner/coder login \
281
+ --first-user-username pr${{ env.PR_NUMBER }} \
282
+ --first-user-email ${{ env.PR_NUMBER }}@coder.com \
283
+ --first-user-password $password \
284
+ --first-user-trial \
285
+ --use-token-as-session \
286
+ ${{ env.PR_DEPLOYMENT_ACCESS_URL }}
287
+
288
+ # Create template
289
+ /home/runner/coder templates init --id kubernetes && cd ./kubernetes/ && /home/runner/coder templates create -y --variable namespace=pr${{ env.PR_NUMBER }}
290
+
291
+ # Create workspace
292
+ cat <<EOF > workspace.yaml
293
+ cpu: "2"
294
+ memory: "4"
295
+ home_disk_size: "2"
296
+ EOF
297
+
298
+ /home/runner/coder create --template="kubernetes" pr${{ env.PR_NUMBER }} --rich-parameter-file ./workspace.yaml -y
299
+ /home/runner/coder stop pr${{ env.PR_NUMBER }} -y
300
+
210
301
- name : Send Slack notification
211
302
run : |
212
303
curl -s -o /dev/null -X POST -H 'Content-type: application/json' \
213
- -d '{
214
- "pr_number": "'"${{ env.PR_NUMBER }}"'",
215
- "pr_url": "'"${{ env.PR_URL }}"'",
216
- "pr_title": "'"${{ env.PR_TITLE }}"'",
217
- "pr_access_url": "'"${{ env.PR_DEPLOYMENT_ACCESS_URL }}"'" }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }}
304
+ -d \
305
+ '{
306
+ "pr_number": "'"${{ env.PR_NUMBER }}"'",
307
+ "pr_url": "'"${{ env.PR_URL }}"'",
308
+ "pr_title": "'"${{ env.PR_TITLE }}"'",
309
+ "pr_access_url": "'"${{ env.PR_DEPLOYMENT_ACCESS_URL }}"'",
310
+ "pr_username": "'"pr${{ env.PR_NUMBER }}"'",
311
+ "pr_email": "'"${{ env.PR_NUMBER }}@coder.com"'",
312
+ "pr_password": "'"${{ steps.setup_deployment.outputs.password }}"'",
313
+ "pr_actor": "'"${{ github.actor }}"'"
314
+ }' \
315
+ ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }}
218
316
echo "Slack notification sent"
219
- env :
220
- PR_DEPLOYMENT_ACCESS_URL : " https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
221
317
222
318
- name : Find Comment
223
319
uses : peter-evans/find-comment@v2
320
+ if : github.event_name == 'issue_comment'
224
321
id : fc
225
322
with :
226
323
issue-number : ${{ env.PR_NUMBER }}
227
324
comment-author : " github-actions[bot]"
228
325
body-includes : This deployment will be deleted when the PR is closed
326
+ direction : last
229
327
230
328
- name : Comment on PR
231
329
uses : peter-evans/create-or-update-comment@v3
330
+ if : github.event_name == 'issue_comment'
232
331
with :
233
332
issue-number : ${{ env.PR_NUMBER }}
234
333
edit-mode : replace
@@ -238,6 +337,3 @@ jobs:
238
337
:rocket: Access the deployment link [here](${{ env.PR_DEPLOYMENT_ACCESS_URL }}).
239
338
:warning: This deployment will be deleted when the PR is closed.
240
339
reactions : rocket
241
-
242
- env :
243
- PR_DEPLOYMENT_ACCESS_URL : " https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
0 commit comments