Skip to content

Commit c4e628c

Browse files
authored
chore: update staging deployment workflow (#847)
* chore: update staging deploy with the required env vars * chore: add deploy commands for various envs * chore: add docs * chore: add isomer migrators * chore: add rds passwrod for dd * chore: update role
1 parent bd3bd03 commit c4e628c

File tree

6 files changed

+92
-38
lines changed

6 files changed

+92
-38
lines changed

.github/workflows/aws_deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ jobs:
206206
sed -i 's/<CPU>/${{ inputs.environment == 'production' && 1024 || 512 }}/g' ${{ inputs.ecs-task-definition-path }}
207207
sed -i 's/<MEMORY>/${{ inputs.environment == 'production' && 2048 || 1024 }}/g' ${{ inputs.ecs-task-definition-path }}
208208
sed -i 's/<RDS_READER_ENDPOINT>/${{ secrets.RDS_READER_ENDPOINT }}/g' ${{ inputs.ecs-task-definition-path }}
209+
sed -i 's/<RDS_DATADOG_PASSWORD>/${{ secrets.RDS_DATADOG_PASSWORD}}/g' ${{ inputs.ecs-task-definition-path }}
209210
sed -i 's/<DD_COMMIT_SHA>/${{ github.sha }}/g' ${{ inputs.ecs-task-definition-path }}
210211
sed -i 's/<ECS_TASK_ROLE>/${{ inputs.ecs-task-role }}/g' ${{ inputs.ecs-task-definition-path }}
211212
sed -i 's/<ECS_TASK_EXEC_ROLE>/${{ inputs.ecs-task-exec-role }}/g' ${{ inputs.ecs-task-definition-path }}

.github/workflows/deploy_staging.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,27 @@ jobs:
1818
with:
1919
aws-region: "ap-southeast-1"
2020
aws-account-id: "058264420411"
21-
cicd-role: "arn:aws:iam::058264420411:role/isomer-next-infra-github-oidc-role-b58f3de"
21+
cicd-role: "arn:aws:iam::058264420411:role/isomer-next-infra-github-oidc-role-aaefdfd"
2222
ecr-repository: "isomer-next-infra-stg-ecr"
23-
ecs-cluster-name: "isomer-next-infra-ecs"
24-
ecs-service-name: "isomer-next-infra-ecs-service"
23+
ecs-cluster-name: "studio-staging-ecs"
24+
ecs-service-name: "studio-staging-ecs-service"
2525
ecs-container-name: "studio"
2626
ecs-container-port: 3000
2727
environment: "staging"
2828
shortEnv: "stg"
2929
codedeploy-appspec-path: .aws/deploy/appspec.json
3030
ecs-task-definition-path: .aws/deploy/task-definition.json
31-
codedeploy-application: "isomer-next-infra-ecs-app"
32-
codedeploy-deployment-group: "isomer-next-infra-ecs-dg"
33-
ecs-task-role: isomer-next-infra-ecs-task-role
34-
ecs-task-exec-role: isomer-next-infra-ecs-task-exec-role
31+
codedeploy-application: "studio-staging-ecs-app"
32+
codedeploy-deployment-group: "studio-staging-ecs-dg"
33+
ecs-task-role: studio-staging-ecs-task-role
34+
ecs-task-exec-role: studio-staging-ecs-task-exec-role
35+
app-url: "https://staging-studio.isomer.gov.sg"
36+
app-name: "Isomer Studio (Staging)"
37+
app-version: ${{ github.sha }}
38+
app-enable-sgid: false
39+
app-s3-region: "ap-southeast-1"
40+
app-s3-assets-bucket-name: "isomer-next-infra-stg-assets-private-61710b8"
41+
app-s3-assets-domain-name: "isomer-user-content-stg.by.gov.sg"
3542

3643
secrets:
3744
DD_API_KEY: ${{ secrets.DD_API_KEY_GITHUB_ACTIONS }}

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,32 @@ There are a few steps to getting started:
2828
4. Add the user to the `isomerpages` organisation by adding them to the file [here](https://github.com/opengovsg/isomer-infra/blob/main/src/github/constants.ts)
2929
5. Add the user to the relevant github teams [here](https://github.com/orgs/opengovsg/teams?query=isomer) by asking the maintainer
3030

31+
### Cutting a release
32+
33+
We run releases via the `publish` event. Hence, in order to cut a release, we have to go through the following steps:
34+
35+
1. first, select the release commit
36+
2. generate a tag for the release commit from the previous tag as follows:
37+
- if you're making a hotfix, add a 0.0.1 to the previous version
38+
- if you're making a minor upgrade, add a 0.1 to the previous version.
39+
- for all purposes, all our releases are minor upgrades so we will not be incrementing the major version number
40+
3. push the tag to the remote origin
41+
4. go to github and click on `Tags`
42+
5. next, click on releases and draft a new release
43+
6. choose the tag you have previously created
44+
7. generate release notes (this can be done automatically via the button)
45+
8. publish the release
46+
47+
### Running database migrations
48+
49+
1. first, add the relevant `.pem` file to the `apps/studio/ssh` folder
50+
- this can be found by searching for `AWS Isomer Next <env> Bastion SSH Key` in your 1Password vault
51+
2. Next, duplicate the `.env.example` in `apps/studio` to `.ssh/.env.<env>`
52+
3. Fill in the relevant information by searching for `Isomer Next <env> Database` inside 1password
53+
4. Next, run `npm run jump:<env>` from within the `apps/studio` folder
54+
5. Next, run `npm run migrate:<env>` from within the `apps/studio` folder
55+
6. (Optional) If you need to run a seed, run `npm run db:seed`
56+
3157
### Extra tools
3258

3359
1. Vercel

apps/studio/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DB_HOST=
2+
SSH_USER=ec2-user
3+
SSH_HOST=

apps/studio/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
"clean": "git clean -xdf .next .turbo node_modules build",
4242
"jump:vapt": "source .ssh/.env.vapt && ssh -L 5433:$DB_HOST:5432 $SSH_USER@$SSH_HOST -i .ssh/studio-vapt-bastion.pem",
4343
"migrate:vapt": "source .ssh/.env.vapt && npx prisma migrate deploy",
44-
"jump": "source .ssh/.env.prod && ssh -L 5433:$DB_HOST:5432 $SSH_USER@$SSH_HOST -i .ssh/studio-prod-bastion.pem"
44+
"jump": "source .ssh/.env.prod && ssh -L 5433:$DB_HOST:5432 $SSH_USER@$SSH_HOST -i .ssh/studio-prod-bastion.pem",
45+
"jump:staging": "source .ssh/.env.staging && ssh -L 5433:$DB_HOST:5432 $SSH_USER@$SSH_HOST -i .ssh/studio-staging-bastion.pem",
46+
"migrate:staging": "source .ssh/.env.staging && npx prisma migrate deploy"
4547
},
4648
"prisma": {
4749
"seed": "tsx prisma/seed.ts"

apps/studio/prisma/seed.ts

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ const ISOMER_ADMINS = [
2323
"adriangoh",
2424
]
2525

26+
const ISOMER_MIGRATORS = [
27+
"tingshian",
28+
"hakeem",
29+
"elora",
30+
"jinhui",
31+
"junxiang",
32+
"rayyan",
33+
"yongteng",
34+
"huaying",
35+
"weiping",
36+
]
37+
2638
const EDITOR_USER = "editor"
2739
const PUBLISHER_USER = "publisher"
2840

@@ -248,37 +260,40 @@ async function main() {
248260
.executeTakeFirstOrThrow()
249261

250262
await Promise.all(
251-
[...ISOMER_ADMINS, EDITOR_USER, PUBLISHER_USER].map(async (name) => {
252-
const user = await db
253-
.insertInto("User")
254-
.values({
255-
id: cuid2.createId(),
256-
name,
257-
email: `${name}@open.gov.sg`,
258-
phone: MOCK_PHONE_NUMBER,
259-
})
260-
.onConflict((oc) =>
261-
oc
262-
.column("email")
263-
.doUpdateSet((eb) => ({ email: eb.ref("excluded.email") })),
264-
)
265-
.returning(["id", "name"])
266-
.executeTakeFirstOrThrow()
267-
const role = ISOMER_ADMINS.includes(user.name)
268-
? RoleType.Admin
269-
: user.name === EDITOR_USER
270-
? RoleType.Editor
271-
: RoleType.Publisher
263+
[...ISOMER_ADMINS, ...ISOMER_MIGRATORS, EDITOR_USER, PUBLISHER_USER].map(
264+
async (name) => {
265+
const user = await db
266+
.insertInto("User")
267+
.values({
268+
id: cuid2.createId(),
269+
name,
270+
email: `${name}@open.gov.sg`,
271+
phone: MOCK_PHONE_NUMBER,
272+
})
273+
.onConflict((oc) =>
274+
oc
275+
.column("email")
276+
.doUpdateSet((eb) => ({ email: eb.ref("excluded.email") })),
277+
)
278+
.returning(["id", "name"])
279+
.executeTakeFirstOrThrow()
272280

273-
await db
274-
.insertInto("ResourcePermission")
275-
.values({
276-
userId: user.id,
277-
siteId,
278-
role,
279-
})
280-
.execute()
281-
}),
281+
const role = [...ISOMER_ADMINS, ...ISOMER_MIGRATORS].includes(user.name)
282+
? RoleType.Admin
283+
: user.name === EDITOR_USER
284+
? RoleType.Editor
285+
: RoleType.Publisher
286+
287+
await db
288+
.insertInto("ResourcePermission")
289+
.values({
290+
userId: user.id,
291+
siteId,
292+
role,
293+
})
294+
.execute()
295+
},
296+
),
282297
)
283298
}
284299

0 commit comments

Comments
 (0)