Skip to content

Commit 995ca7a

Browse files
committed
setup first user and template and workspace
1 parent d5fc1cf commit 995ca7a

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

.github/workflows/pr-deploy.yaml

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ jobs:
128128
PR_TITLE: ${{ needs.pr_commented.outputs.PR_TITLE }}
129129
PR_URL: ${{ needs.pr_commented.outputs.PR_URL }}
130130
PR_BRANCH: ${{ needs.pr_commented.outputs.PR_BRANCH }}
131+
PR_DEPLOYMENT_ACCESS_URL: "https://pr${{ needs.pr_commented.outputs.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
131132
steps:
132133
- name: Checkout
133134
uses: actions/checkout@v3
@@ -218,17 +219,57 @@ jobs:
218219
--namespace "pr${{ env.PR_NUMBER }}" \
219220
--set url="https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
220221
222+
- name: Wait 30 seconds
223+
run: |
224+
sleep 30
225+
226+
- name: Create first user, template and workspace
227+
id: setup_deployment
228+
run: |
229+
set -euxo pipefail
230+
231+
# Create first user
232+
233+
# create a masked random password 12 characters long
234+
password=$(openssl rand -base64 6 | tr -d "=+/" | cut -c1-12)
235+
236+
# add mask so that the password is not printed to the logs
237+
echo "::add-mask::$password"
238+
echo "password=$password" >> $GITHUB_OUTPUT
239+
240+
coder login \
241+
--first-user-username ${{ env.PR_NUMBER }} \
242+
--first-user-email ${{ env.PR_NUMBER }}@coder.com \
243+
--first-user-password $password \
244+
--first-user-trial \
245+
--use-token-as-session \
246+
${{ env.PR_DEPLOYMENT_ACCESS_URL }}
247+
248+
# Create template
249+
coder templates init --id kubernetes && cd ./kubernetes/ && coder templates create -y --variable namespace=pr${{ env.PR_NUMBER }}
250+
251+
# Create workspace
252+
cat <<EOF > workspace.yaml
253+
cpu: "2"
254+
memory: "4"
255+
home_disk_size: "2"
256+
EOF
257+
258+
coder create --template="kubernetes" pr${{ env.PR_NUMBER }} --rich-parameter-file ./workspace.yaml -y
259+
coder stop pr${{ env.PR_NUMBER }} -y
260+
221261
- name: Send Slack notification
222262
run: |
223263
curl -s -o /dev/null -X POST -H 'Content-type: application/json' \
224264
-d '{
225265
"pr_number": "'"${{ env.PR_NUMBER }}"'",
226266
"pr_url": "'"${{ env.PR_URL }}"'",
227267
"pr_title": "'"${{ env.PR_TITLE }}"'",
228-
"pr_access_url": "'"${{ env.PR_DEPLOYMENT_ACCESS_URL }}"'" }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }}
268+
"pr_access_url": "'"${{ env.PR_DEPLOYMENT_ACCESS_URL }}"'",
269+
"pr_username": "'"${{ env.PR_NUMBER }}"'",
270+
"pr_email": "'"${{ env.PR_NUMBER }}@coder.com"'",
271+
"pr_password": "'"${{ steps.setup_deployment.outputs.password }}"'" }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }}
229272
echo "Slack notification sent"
230-
env:
231-
PR_DEPLOYMENT_ACCESS_URL: "https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
232273
233274
- name: Find Comment
234275
uses: peter-evans/find-comment@v2
@@ -252,5 +293,3 @@ jobs:
252293
:rocket: Access the deployment link [here](${{ env.PR_DEPLOYMENT_ACCESS_URL }}).
253294
:warning: This deployment will be deleted when the PR is closed.
254295
reactions: rocket
255-
env:
256-
PR_DEPLOYMENT_ACCESS_URL: "https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"

0 commit comments

Comments
 (0)