-
Notifications
You must be signed in to change notification settings - Fork 158
199 lines (167 loc) · 6.55 KB
/
preview-branches.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Deploy Preview Branch
on:
pull_request:
# Use runs on `ubuntu-latest-8-cores`. All of our self hosted runners use this tag.
# Our runners pick up jobs first, and if all our runners are being used or are down
# it will automatically back up to using GitHub hosted runners.
# Require previous builds and deployments to finish before starting a new one
# Not sure how Pulumi would handle being terminated when changing a stack.
concurrency:
group: pr-${{ github.event.pull_request.number }}
jobs:
infra:
needs:
- files_preview
- multiplayer_preview
- connection_preview
name: Create or Update Infrastructure with Pulumi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- uses: pulumi/actions@v4
- name: Update Pulumi Infrastructure
working-directory: infra
run: |
npm ci
pulumi org set-default quadratic
STACK_NAME="preview-pr-${{ env.PR_ID }}"
if ! pulumi stack ls | grep -q "^$STACK_NAME"; then
echo "Stack $STACK_NAME does not exist. Initializing..."
pulumi stack init $STACK_NAME
else
echo "Stack $STACK_NAME already exists."
pulumi stack select $STACK_NAME
fi
# Point to the Pulumi ESC Environment
cat <<EOF | tee Pulumi.$STACK_NAME.yaml
environment:
- aws-infra-development
EOF
pulumi config set multiplayer-subdomain multiplayer-pr-${{ env.PR_ID }}
pulumi config set files-subdomain files-pr-${{ env.PR_ID }}
pulumi config set connection-subdomain connection-pr-${{ env.PR_ID }}
pulumi config set docker-image-tag pr-${{ env.PR_ID }}
pulumi config set quadratic-api-uri https://quadratic-api-dev-pr-${{ env.PR_ID }}.herokuapp.com
pulumi config set is-preview true
pulumi up -y
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_DEVELOPMENT }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEVELOPMENT }}
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
PR_ID: ${{ github.event.pull_request.number }}
multiplayer_preview:
runs-on: ubuntu-latest-8-cores
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEVELOPMENT }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEVELOPMENT }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build, Tag, and Push Image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: quadratic-multiplayer-development
IMAGE_TAG: pr-${{ github.event.pull_request.number }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f quadratic-multiplayer/Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
files_preview:
runs-on: ubuntu-latest-8-cores
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEVELOPMENT }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEVELOPMENT }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build, Tag, and Push Image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: quadratic-files-development
IMAGE_TAG: pr-${{ github.event.pull_request.number }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f quadratic-files/Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
connection_preview:
runs-on: ubuntu-latest-8-cores
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEVELOPMENT }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEVELOPMENT }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build, Tag, and Push Image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: quadratic-connection-development
IMAGE_TAG: pr-${{ github.event.pull_request.number }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f quadratic-connection/Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
# client_preview:
# needs: infra
# runs-on: ubuntu-latest-8-cores
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with:
# node-version: 18
# - name: Set up Rust
# uses: moonrepo/setup-rust@v1
# with:
# cache: false
# - uses: jetli/[email protected]
# with:
# version: 'latest'
# - name: Build Client
# working-directory: quadratic-client
# run: |
# npm ci
# npm run build:wasm:javascript
# npm run build:wasm:types
# npm run build
# env:
# VITE_ENVIRONMENT: preview
# VITE_QUADRATIC_API_URL: https://quadratic-api-dev-pr-${{ github.event.pull_request.number }}.herokuapp.com
# VITE_SENTRY_DSN: ${{ secrets.VITE_SENTRY_DSN }}
# VITE_AUTH0_CLIENT_ID: ${{ secrets.VITE_AUTH0_CLIENT_ID }}
# VITE_AUTH0_AUDIENCE: ${{ secrets.VITE_AUTH0_AUDIENCE }}
# VITE_AUTH0_ISSUER: ${{ secrets.VITE_AUTH0_ISSUER }}
# VITE_AUTH0_DOMAIN: ${{ secrets.VITE_AUTH0_DOMAIN }}
# # Set up AWS credentials
# - name: Set up AWS credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-region: your-aws-region
# # Deploy to S3
# - name: Deploy to S3
# run: |
# aws s3 sync ./path-to-your-static-files/ s3://your-s3-bucket-name --delete