Skip to content

Commit 6cba38f

Browse files
committed
wip: stats
1 parent 3cb715e commit 6cba38f

4 files changed

Lines changed: 58 additions & 1 deletion

File tree

.github/workflows/deploy.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ on:
99

1010
concurrency: ${{ github.workflow }}-${{ github.ref }}
1111

12+
permissions:
13+
contents: read
14+
id-token: write
15+
1216
jobs:
1317
deploy:
18+
if: github.repository == 'anomalyco/opencode' && (github.ref_name == 'dev' || github.ref_name == 'production')
1419
runs-on: ubuntu-latest
20+
environment: ${{ github.ref_name }}
1521
steps:
1622
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
1723

@@ -21,6 +27,12 @@ jobs:
2127
with:
2228
node-version: "24"
2329

30+
- uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4.3.1
31+
with:
32+
role-to-assume: ${{ vars.AWS_DEPLOY_ROLE_ARN }}
33+
role-session-name: opencode-${{ github.run_id }}
34+
aws-region: us-east-1
35+
2436
- run: bun sst deploy --stage=${{ github.ref_name }}
2537
env:
2638
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

infra/stage.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,49 @@ export const domain = (() => {
66

77
export const zoneID = "430ba34c138cfb5360826c4909f99be8"
88

9+
const githubActionsDeployRole = (() => {
10+
if ($app.stage !== "dev" && $app.stage !== "production") return
11+
12+
const provider = new aws.iam.OpenIdConnectProvider("GithubActionsOidcProvider", {
13+
url: "https://token.actions.githubusercontent.com",
14+
clientIdLists: ["sts.amazonaws.com"],
15+
})
16+
const role = new aws.iam.Role("GithubActionsDeployRole", {
17+
name: `opencode-${$app.stage}-github-actions-deploy`,
18+
maxSessionDuration: 3600,
19+
assumeRolePolicy: aws.iam.getPolicyDocumentOutput({
20+
statements: [
21+
{
22+
effect: "Allow",
23+
actions: ["sts:AssumeRoleWithWebIdentity"],
24+
principals: [{ type: "Federated", identifiers: [provider.arn] }],
25+
conditions: [
26+
{
27+
test: "StringEquals",
28+
variable: "token.actions.githubusercontent.com:aud",
29+
values: ["sts.amazonaws.com"],
30+
},
31+
{
32+
test: "StringEquals",
33+
variable: "token.actions.githubusercontent.com:sub",
34+
values: [`repo:anomalyco/opencode:environment:${$app.stage}`],
35+
},
36+
],
37+
},
38+
],
39+
}).json,
40+
})
41+
42+
new aws.iam.RolePolicyAttachment("GithubActionsDeployRoleAdmin", {
43+
role: role.name,
44+
policyArn: "arn:aws:iam::aws:policy/AdministratorAccess",
45+
})
46+
47+
return role
48+
})()
49+
50+
export const githubActionsDeployRoleArn = githubActionsDeployRole?.arn
51+
952
new cloudflare.RegionalHostname("RegionalHostname", {
1053
hostname: domain,
1154
regionKey: "us",

sst-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,4 @@ declare module "sst" {
341341
}
342342

343343
import "sst"
344-
export {}
344+
export {}

sst.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default $config({
2828
}
2929
},
3030
async run() {
31+
const stage = await import("./infra/stage.js")
3132
await import("./infra/app.js")
3233
await import("./infra/lake.js")
3334
const stats = await import("./infra/stats.js")
@@ -40,6 +41,7 @@ export default $config({
4041
return {
4142
StatWorkerUrl: stat.url,
4243
StatsUrl: stats.app.url,
44+
...(stage.githubActionsDeployRoleArn ? { GithubActionsDeployRoleArn: stage.githubActionsDeployRoleArn } : {}),
4345
}
4446
},
4547
})

0 commit comments

Comments
 (0)