@@ -25,28 +25,26 @@ jobs:
25
25
pr_commented :
26
26
if : (github.event_name == 'issue_comment' && contains(github.event.comment.body, '/deploy-pr') && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'OWNER')) || github.event_name == 'workflow_dispatch'
27
27
outputs :
28
- PR_NUMBER : ${{ steps.pr_number.outputs.PR_NUMBER }}
29
- PR_TITLE : ${{ steps.pr_number.outputs.PR_TITLE }}
30
- PR_URL : ${{ steps.pr_number.outputs.PR_URL }}
31
- PR_BRANCH : ${{ steps.pr_number.outputs.PR_BRANCH }}
32
- COMMENT_ID : ${{ steps.comment_id.outputs.comment-id }}
28
+ PR_NUMBER : ${{ steps.pr_info.outputs.PR_NUMBER }}
29
+ PR_TITLE : ${{ steps.pr_info.outputs.PR_TITLE }}
30
+ PR_URL : ${{ steps.pr_info.outputs.PR_URL }}
31
+ PR_BRANCH : ${{ steps.pr_info.outputs.PR_BRANCH }}
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
36
35
runs-on : " ubuntu-latest"
37
36
steps :
38
37
- name : Get PR number, title, and branch name
39
- id : pr_number
38
+ id : pr_info
40
39
run : |
41
40
set -euxo pipefail
42
41
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
43
42
PR_NUMBER=${{ github.event.inputs.pr_number }}
44
- PR_TITLE=$(gh pr view $PR_NUMBER --json title | jq -r '.title')
45
43
else
46
44
PR_NUMBER=${{ github.event.issue.number }}
47
- PR_TITLE='${{ github.event.issue.title }}'
48
45
fi
49
- PR_BRANCH=$(gh pr view $PR_NUMBER --json headRefName | jq -r '.headRefName')
46
+ PR_TITLE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/coder/coder/pulls/$PR_NUMBER | jq -r '.title')
47
+ PR_BRANCH=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/coder/coder/pulls/$PR_NUMBER | jq -r '.head.ref')
50
48
echo "PR_URL=https://github.com/coder/coder/pull/$PR_NUMBER" >> $GITHUB_OUTPUT
51
49
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT
52
50
echo "PR_TITLE=$PR_TITLE" >> $GITHUB_OUTPUT
@@ -59,36 +57,27 @@ jobs:
59
57
echo "CODER_BASE_IMAGE_TAG=$CODER_BASE_IMAGE_TAG" >> $GITHUB_OUTPUT
60
58
echo "CODER_IMAGE_TAG=$CODER_IMAGE_TAG" >> $GITHUB_OUTPUT
61
59
env :
62
- CODER_BASE_IMAGE_TAG : ghcr.io/coder/coder-preview-base:pr${{ steps.pr_number.outputs.PR_NUMBER }}
63
- CODER_IMAGE_TAG : ghcr.io/coder/coder-preview:pr${{ steps.pr_number.outputs.PR_NUMBER }}
64
-
65
- - name : Find Comment
66
- uses : peter-evans/find-comment@v2
67
- id : fc
68
- with :
69
- issue-number : ${{ steps.pr_number.outputs.PR_NUMBER }}
70
- comment-author : " github-actions[bot]"
71
- body-includes : This deployment will be deleted when the PR is closed
60
+ CODER_BASE_IMAGE_TAG : ghcr.io/coder/coder-preview-base:pr${{ steps.pr_info.outputs.PR_NUMBER }}
61
+ CODER_IMAGE_TAG : ghcr.io/coder/coder-preview:pr${{ steps.pr_info.outputs.PR_NUMBER }}
72
62
73
63
- name : Comment on PR
74
64
id : comment_id
75
65
uses : peter-evans/create-or-update-comment@v3
76
66
with :
77
- comment-id : ${{ steps.fc.outputs.comment-id }}
78
- issue-number : ${{ steps.pr_number.outputs.PR_NUMBER }}
79
- edit-mode : replace
67
+ issue-number : ${{ steps.pr_info.outputs.PR_NUMBER }}
80
68
body : |
81
- :rocket: Deploying PR ${{ steps.pr_number .outputs.PR_NUMBER }} ...
69
+ :rocket: Deploying PR ${{ steps.pr_info .outputs.PR_NUMBER }} ...
82
70
:warning: This deployment will be deleted when the PR is closed.
71
+ reactions : " +1"
83
72
84
73
build :
85
74
needs : pr_commented
86
75
runs-on : ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
87
76
env :
88
77
DOCKER_CLI_EXPERIMENTAL : " enabled"
89
- CODER_IMAGE_TAG : ${{ needs.pr_commented.outputs.coder_image_tag }}
90
- PR_NUMBER : ${{ needs.pr_commented.outputs.pr_number }}
91
- PR_BRANCH : ${{ needs.pr_commented.outputs.pr_branch }}
78
+ CODER_IMAGE_TAG : ${{ needs.pr_commented.outputs.CODER_IMAGE_TAG }}
79
+ PR_NUMBER : ${{ needs.pr_commented.outputs.PR_NUMBER }}
80
+ PR_BRANCH : ${{ needs.pr_commented.outputs.PR_BRANCH }}
92
81
steps :
93
82
- name : Checkout
94
83
uses : actions/checkout@v3
@@ -145,7 +134,7 @@ jobs:
145
134
run : |
146
135
set -euxo pipefail
147
136
mkdir -p ~/.kube
148
- echo "${{ secrets.DELIVERYBOT_KUBECONFIG }}" > ~/.kube/config
137
+ echo "${{ secrets.PR_DEPLOYMENTS_KUBECONFIG }}" > ~/.kube/config
149
138
export KUBECONFIG=~/.kube/config
150
139
151
140
- name : Create PR namespace
@@ -155,6 +144,35 @@ jobs:
155
144
kubectl delete namespace "pr${{ env.PR_NUMBER }}" || true
156
145
kubectl create namespace "pr${{ env.PR_NUMBER }}"
157
146
147
+ - name : Setup ingress
148
+ run : |
149
+ cat <<EOF > ingress.yaml
150
+ apiVersion: networking.k8s.io/v1
151
+ kind: Ingress
152
+ metadata:
153
+ name: pr${{ env.PR_NUMBER }}
154
+ namespace: pr${{ env.PR_NUMBER }}
155
+ annotations:
156
+ cert-manager.io/cluster-issuer: letsencrypt
157
+ spec:
158
+ tls:
159
+ - hosts:
160
+ - "*.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
161
+ secretName: pr${{ env.PR_NUMBER }}-tls
162
+ rules:
163
+ - host: "pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
164
+ http:
165
+ paths:
166
+ - pathType: Prefix
167
+ path: "/"
168
+ backend:
169
+ service:
170
+ name: coder
171
+ port:
172
+ number: 80
173
+ EOF
174
+ kubectl apply -f ingress.yaml
175
+
158
176
- name : Install Helm chart
159
177
run : |
160
178
helm upgrade --install pr${{ env.PR_NUMBER }} ./helm \
@@ -164,25 +182,30 @@ jobs:
164
182
--set coder.service.type=ClusterIP \
165
183
--set coder.serviceAccount.enableDeployments=true \
166
184
--set coder.env[0].name=CODER_ACCESS_URL \
167
- --set coder.env[0].value="" \
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="*" \
168
190
--force
169
-
170
- - name : Get deployment URL
171
- id : deployment_url
172
- run : |
173
- set -euo pipefail
174
- kubectl rollout status deployment/coder --namespace "pr${{ env.PR_NUMBER }}"
175
- POD_NAME=$(kubectl get pods -n "pr${{ env.PR_NUMBER }}" | awk 'NR==2{print $1}')
176
- CODER_ACCESS_URL=$(kubectl logs $POD_NAME -n "pr${{ env.PR_NUMBER }}" | grep "Web UI:" | awk -F ':' '{print $2":"$3}' | awk '{$1=$1};1')
177
- echo "::add-mask::$CODER_ACCESS_URL"
178
- echo "CODER_ACCESS_URL=$CODER_ACCESS_URL" >> $GITHUB_OUTPUT
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
179
202
180
203
- name : Install coder-logstream-kube
181
204
run : |
182
205
helm repo add coder-logstream-kube https://helm.coder.com/logstream-kube
183
- helm install coder-logstream-kube coder-logstream-kube/coder-logstream-kube \
206
+ helm upgrade -- install coder-logstream-kube coder-logstream-kube/coder-logstream-kube \
184
207
--namespace "pr${{ env.PR_NUMBER }}" \
185
- --set url="${{ steps.deployment_url.outputs.CODER_ACCESS_URL }}"
208
+ --set url="https://pr ${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
186
209
187
210
- name : Send Slack notification
188
211
run : |
@@ -191,17 +214,30 @@ jobs:
191
214
"pr_number": "'"${{ env.PR_NUMBER }}"'",
192
215
"pr_url": "'"${{ env.PR_URL }}"'",
193
216
"pr_title": "'"${{ env.PR_TITLE }}"'",
194
- "pr_access_url": "'"${{ steps.deployment_url.outputs.CODER_ACCESS_URL }}"'" }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }}
217
+ "pr_access_url": "'"${{ env.PR_DEPLOYMENT_ACCESS_URL }}"'" }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }}
195
218
echo "Slack notification sent"
219
+ env :
220
+ PR_DEPLOYMENT_ACCESS_URL : " https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
221
+
222
+ - name : Find Comment
223
+ uses : peter-evans/find-comment@v2
224
+ id : fc
225
+ with :
226
+ issue-number : ${{ env.PR_NUMBER }}
227
+ comment-author : " github-actions[bot]"
228
+ body-includes : This deployment will be deleted when the PR is closed
196
229
197
230
- name : Comment on PR
198
231
uses : peter-evans/create-or-update-comment@v3
199
232
with :
200
233
issue-number : ${{ env.PR_NUMBER }}
201
234
edit-mode : replace
202
- comment-id : ${{ needs.pr_commented .outputs.COMMENT_ID }}
235
+ comment-id : ${{ steps.fc .outputs.comment-id }}
203
236
body : |
204
237
:heavy_check_mark: Deployed PR ${{ env.PR_NUMBER }} successfully.
205
- :rocket: Access the deployment link [here](https://codercom.slack.com/archives/C05DNE982E8 ).
238
+ :rocket: Access the deployment link [here](${{ env.PR_DEPLOYMENT_ACCESS_URL }} ).
206
239
:warning: This deployment will be deleted when the PR is closed.
207
- reactions : " +1"
240
+ reactions : rocket
241
+
242
+ env :
243
+ PR_DEPLOYMENT_ACCESS_URL : " https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
0 commit comments