29
29
PR_TITLE : ${{ steps.pr_number.outputs.PR_TITLE }}
30
30
PR_URL : ${{ steps.pr_number.outputs.PR_URL }}
31
31
PR_BRANCH : ${{ steps.pr_number.outputs.PR_BRANCH }}
32
- COMMENT_ID : ${{ steps.comment_id.outputs.comment-id }}
33
32
CODER_BASE_IMAGE_TAG : ${{ steps.set_tags.outputs.CODER_BASE_IMAGE_TAG }}
34
33
CODER_IMAGE_TAG : ${{ steps.set_tags.outputs.CODER_IMAGE_TAG }}
35
34
39
38
id : pr_number
40
39
run : |
41
40
set -euxo pipefail
42
- PR_NUMBER=$(gh pr view ${{ github.event.inputs.pr_number }} --json number | jq -r '.number')
41
+ if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then
42
+ PR_NUMBER=${{ github.event.inputs.pr_number }}"
43
+ else
44
+ PR_NUMBER=${{ github.event.issue.number }}"
45
+ fi
43
46
PR_TITLE=$(gh pr view $PR_NUMBER --json title | jq -r '.title')
44
47
PR_BRANCH=$(gh pr view $PR_NUMBER --json headRefName | jq -r '.headRefName')
45
48
echo "PR_URL=https://github.com/coder/coder/pull/$PR_NUMBER" >> $GITHUB_OUTPUT
@@ -59,24 +62,15 @@ jobs:
59
62
CODER_BASE_IMAGE_TAG : ghcr.io/coder/coder-preview-base:pr${{ steps.pr_number.outputs.PR_NUMBER }}
60
63
CODER_IMAGE_TAG : ghcr.io/coder/coder-preview:pr${{ steps.pr_number.outputs.PR_NUMBER }}
61
64
62
- - name : Find Comment
63
- uses : peter-evans/find-comment@v2
64
- id : fc
65
- with :
66
- issue-number : ${{ steps.pr_number.outputs.PR_NUMBER }}
67
- comment-author : " github-actions[bot]"
68
- body-includes : This deployment will be deleted when the PR is closed
69
-
70
65
- name : Comment on PR
71
66
id : comment_id
72
67
uses : peter-evans/create-or-update-comment@v3
73
68
with :
74
- comment-id : ${{ steps.fc.outputs.comment-id }}
75
69
issue-number : ${{ steps.pr_number.outputs.PR_NUMBER }}
76
- edit-mode : replace
77
70
body : |
78
71
:rocket: Deploying PR ${{ steps.pr_number.outputs.PR_NUMBER }} ...
79
72
:warning: This deployment will be deleted when the PR is closed.
73
+ reactions : " -1"
80
74
81
75
build :
82
76
needs : pr_commented
@@ -142,7 +136,7 @@ jobs:
142
136
run : |
143
137
set -euxo pipefail
144
138
mkdir -p ~/.kube
145
- echo "${{ secrets.DELIVERYBOT_KUBECONFIG }}" > ~/.kube/config
139
+ echo "${{ secrets.PR_DEPLOYMENTS_KUBECONFIG }}" > ~/.kube/config
146
140
export KUBECONFIG=~/.kube/config
147
141
148
142
- name : Create PR namespace
@@ -152,6 +146,35 @@ jobs:
152
146
kubectl delete namespace "pr${{ env.PR_NUMBER }}" || true
153
147
kubectl create namespace "pr${{ env.PR_NUMBER }}"
154
148
149
+ - name : Setup ingress
150
+ run : |
151
+ cat <<EOF > ingress.yaml
152
+ apiVersion: networking.k8s.io/v1
153
+ kind: Ingress
154
+ metadata:
155
+ name: pr${{ env.PR_NUMBER }}
156
+ namespace: pr${{ env.PR_NUMBER }}
157
+ annotations:
158
+ cert-manager.io/cluster-issuer: letsencrypt
159
+ spec:
160
+ tls:
161
+ - hosts:
162
+ - "*.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
163
+ secretName: pr${{ env.PR_NUMBER }}-tls
164
+ rules:
165
+ - host: "pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
166
+ http:
167
+ paths:
168
+ - pathType: Prefix
169
+ path: "/"
170
+ backend:
171
+ service:
172
+ name: coder
173
+ port:
174
+ number: 80
175
+ EOF
176
+ kubectl apply -f ingress.yaml
177
+
155
178
- name : Install Helm chart
156
179
run : |
157
180
helm upgrade --install pr${{ env.PR_NUMBER }} ./helm \
@@ -161,25 +184,30 @@ jobs:
161
184
--set coder.service.type=ClusterIP \
162
185
--set coder.serviceAccount.enableDeployments=true \
163
186
--set coder.env[0].name=CODER_ACCESS_URL \
164
- --set coder.env[0].value="" \
187
+ --set coder.env[0].value="pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}" \
188
+ --set coder.env[1].name=CODER_WILDCARD_ACCESS_URL \
189
+ --set coder.env[1].value="*--pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}" \
190
+ --set coder.env[2].name=CODER_EXPERIMENTS \
191
+ --set coder.env[2].value="*" \
192
+ # Uncomment this when https://github.com/coder/coder/issues/8714 is resolved
193
+ # --set coder.env[3].name=CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS \
194
+ # --set coder.env[3].value=true \
195
+ # --set coder.env[4].name=CODER_OAUTH2_GITHUB_CLIENT_ID \
196
+ # --set coder.env[4].value=${{ secrets.PR_DEPLOYMENTS_GITHUB_OAUTH_CLIENT_ID }} \
197
+ # --set coder.env[5].name=CODER_OAUTH2_GITHUB_CLIENT_SECRET \
198
+ # --set coder.env[5].value=${{ secrets.PR_DEPLOYMENTS_GITHUB_OAUTH_CLIENT_SECRET }} \
199
+ # --set coder.env[6].name=CODER_OAUTH2_GITHUB_ALLOWED_ORGS \
200
+ # --set coder.env[6].value=coder \
201
+ # --set coder.env[7].name=CODER_OAUTH2_GITHUB_REDIRECT_URI \
202
+ # --set coder.env[7].value="https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}/gitauth/github/callback \
165
203
--force
166
204
167
- - name : Get deployment URL
168
- id : deployment_url
169
- run : |
170
- set -euo pipefail
171
- kubectl rollout status deployment/coder --namespace "pr${{ env.PR_NUMBER }}"
172
- POD_NAME=$(kubectl get pods -n "pr${{ env.PR_NUMBER }}" | awk 'NR==2{print $1}')
173
- CODER_ACCESS_URL=$(kubectl logs $POD_NAME -n "pr${{ env.PR_NUMBER }}" | grep "Web UI:" | awk -F ':' '{print $2":"$3}' | awk '{$1=$1};1')
174
- echo "::add-mask::$CODER_ACCESS_URL"
175
- echo "CODER_ACCESS_URL=$CODER_ACCESS_URL" >> $GITHUB_OUTPUT
176
-
177
205
- name : Install coder-logstream-kube
178
206
run : |
179
207
helm repo add coder-logstream-kube https://helm.coder.com/logstream-kube
180
- helm install coder-logstream-kube coder-logstream-kube/coder-logstream-kube \
208
+ helm upgrade -- install coder-logstream-kube coder-logstream-kube/coder-logstream-kube \
181
209
--namespace "pr${{ env.PR_NUMBER }}" \
182
- --set url="${{ steps.deployment_url.outputs.CODER_ACCESS_URL }}"
210
+ --set url="https://pr ${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
183
211
184
212
- name : Send Slack notification
185
213
run : |
@@ -188,17 +216,33 @@ jobs:
188
216
"pr_number": "'"${{ env.PR_NUMBER }}"'",
189
217
"pr_url": "'"${{ env.PR_URL }}"'",
190
218
"pr_title": "'"${{ env.PR_TITLE }}"'",
191
- "pr_access_url": "'"${{ steps.deployment_url.outputs.CODER_ACCESS_URL }}" '" }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }}
219
+ "pr_access_url": "'"${{ env.PR_DEPLOYMENT_ACCESS_URL }}'" }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }}
192
220
echo "Slack notification sent"
221
+ env :
222
+ PR_DEPLOYMENT_ACCESS_URL : " https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
223
+
224
+ - name : Find Comment
225
+ uses : peter-evans/find-comment@v2
226
+ id : fc
227
+ with :
228
+ issue-number : ${{ env.PR_NUMBER }}
229
+ comment-author : " github-actions[bot]"
230
+ body-includes : This deployment will be deleted when the PR is closed
193
231
194
232
- name : Comment on PR
195
233
uses : peter-evans/create-or-update-comment@v3
196
234
with :
197
235
issue-number : ${{ env.PR_NUMBER }}
198
236
edit-mode : replace
199
- comment-id : ${{ needs.pr_commented .outputs.COMMENT_ID }}
237
+ comment-id : ${{ steps.fc .outputs.comment-id }}
200
238
body : |
201
239
:heavy_check_mark: Deployed PR ${{ env.PR_NUMBER }} successfully.
202
- :rocket: Access the deployment link [here](https://codercom.slack.com/archives/C05DNE982E8 ).
240
+ :rocket: Access the deployment link [here](${{ env.PR_DEPLOYMENT_ACCESS_URL }} ).
203
241
:warning: This deployment will be deleted when the PR is closed.
204
- reactions : " +1"
242
+ reactions : |
243
+ +1
244
+ rocket
245
+ reactions-edit-mode : replace
246
+
247
+ env :
248
+ PR_DEPLOYMENT_ACCESS_URL : " https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
0 commit comments