Skip to content

Commit 0880121

Browse files
committed
Add pulumi to the project to start deploying infrastructure
We're using Pulumi here to deploy two things - A Cloudfront distribution - An OIDC provider This required a small amount of reconfiguration of the linters to allow for the slightly different settings that Pulumi requires. We've added pulumi to the dev container so that it can be run from there. We're also adding a GitHub Actions workflow to deploy the infrastructure when the code is pushed to the main branch, using the OIDC provider (which has been applied manually to bootstrap the process).
1 parent b8dea17 commit 0880121

18 files changed

Lines changed: 1592 additions & 26 deletions

.devcontainer/Dockerfile.devcontainer

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ FROM ghcr.io/iainlane/dotfiles-rust-tools:git-24a7c0cfa3e9b909f954a85dd0b4163f60
22

33
FROM public.ecr.aws/aws-cli/aws-cli:2.16.3 AS aws-cli
44

5+
FROM pulumi/pulumi-base:3.118.0 AS pulumi
6+
57
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:1-22-bookworm
68

79
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
@@ -13,6 +15,8 @@ RUN ln -s /usr/local/aws-cli/v2/current/bin/aws /usr/local/bin/aws
1315

1416
COPY --from=rust-tools /usr/local/bin/* /usr/local/bin/
1517

18+
COPY --from=pulumi /pulumi/bin/* /usr/bin/
19+
1620
RUN corepack enable
1721

1822
USER node

.devcontainer/devcontainer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"source=${localWorkspaceFolderBasename}-node_modules-met.no,target=${containerWorkspaceFolder}/gen/met.no/node_modules,type=volume",
1111
"source=${localWorkspaceFolderBasename}-node_modules-geojs,target=${containerWorkspaceFolder}/gen/geojs/node_modules,type=volume",
1212
"source=${localWorkspaceFolderBasename}-yarn_cache,target=/home/node/.cache/yarn,type=volume",
13-
"source=${localWorkspaceFolderBasename}-node_cache,target=/home/node/.cache/node,type=volume"
13+
"source=${localWorkspaceFolderBasename}-node_cache,target=/home/node/.cache/node,type=volume",
14+
"source=${localWorkspaceFolderBasename}-pulumi-config,target=/home/node/.pulumi,type=volume"
1415
],
1516

1617
"containerUser": "node",
@@ -20,6 +21,8 @@
2021
"AWS_SDK_LOAD_CONFIG": "true"
2122
},
2223

24+
"runArgs": ["--env-file", ".devcontainer/.env"],
25+
2326
"onCreateCommand": "${containerWorkspaceFolder}/.devcontainer/onCreateCommand.sh",
2427

2528
"customizations": {

.devcontainer/onCreateCommand.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ sudo chown node:node /home/node/.cache
66
sudo chown node:node /home/node/.cache/node
77
sudo chown node:node /home/node/.cache/yarn
88
sudo chown node:node node_modules */*/node_modules
9+
sudo chown node:node /home/node/.pulumi
910

1011
yarn install --immutable < /dev/null
11-
yarn serverless dynamodb install
12+
yarn serverless dynamodb install --stage=local

.github/workflows/oidc.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
on:
2+
pull_request:
3+
4+
push:
5+
branches:
6+
- main
7+
8+
name: Authenticate with AWS
9+
10+
jobs:
11+
oidc:
12+
permissions:
13+
contents: read
14+
id-token: write
15+
pull-requests: write
16+
17+
runs-on: ubuntu-latest
18+
19+
env:
20+
AWS_REGION: eu-west-2
21+
STATE_BUCKET: coldoutsi.de-pulumi-state
22+
23+
steps:
24+
- name: Configure AWS credentials
25+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
26+
with:
27+
audience: coldoutsi.de-dev
28+
aws-region: ${{ env.AWS_REGION }}
29+
role-to-assume: arn:aws:iam::072248381277:role/oidcRole-715afe8
30+
31+
- name: Print session info
32+
run: aws sts get-caller-identity
33+
34+
- name: Check out
35+
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
36+
37+
- name: Enable corepack
38+
run: |
39+
corepack enable
40+
41+
- name: Set up Node.js
42+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
43+
with:
44+
node-version-file: "package.json"
45+
cache: "yarn"
46+
47+
- name: Install dependencies
48+
run: yarn workspace pulumi install --immutable
49+
50+
- name: Pulumi preview
51+
uses: pulumi/actions@18b5a33fc447ab919feb61f2bb41147a1b30ab40 # v5.2.4
52+
with:
53+
cloud-url:
54+
s3://${{ env.STATE_BUCKET }}?region=${{ env.AWS_REGION }}&awssdk=v2
55+
stack-name: organization/coldoutsi.de/dev
56+
command: preview
57+
comment-on-pr: true
58+
comment-on-summary: true
59+
work-dir: pulumi

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ coverage/
88

99
# Personal settings
1010
.vscode/settings.json
11+
.devcontainer/.env
1112

1213
# Secrets in here
1314
.env*

CONTRIBUTING.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ environment which supports [dev containers][devcontainers].
3939
git clone https://github.com/iainlane/coldoutsi.de.git
4040
```
4141

42-
2. Open the project in the IDE
42+
2. If using AWS SSO and a non-default profile and/or region, create a file
43+
`.devcontainer/.env` and set `AWS_PROFILE` and/or `AWS_REGION` accordingly.
4344

44-
3. If using VS Code, click "Reopen in Container" when prompted. This will build
45+
3. Open the project in the IDE
46+
47+
4. If using VS Code, click "Reopen in Container" when prompted. This will build
4548
and start the container with all the necessary dependencies installed.
4649

4750
[devcontainers]: https://containers.dev/

eslint.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export default tseslint.config(
7878
"unicorn/no-typeof-undefined": "error",
7979
},
8080
},
81+
{
82+
files: ["pulumi/**/*.ts"],
83+
rules: {
84+
"@typescript-eslint/no-unused-vars": "off",
85+
},
86+
},
8187
{
8288
files: ["**/*.test.ts"],
8389
...jestPlugin.configs["flat/recommended"],

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"workspaces": {
77
"packages": [
88
"app",
9-
"gen/*"
9+
"gen/*",
10+
"pulumi"
1011
]
1112
},
1213
"type": "module",

pulumi/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/
2+
node_modules/

pulumi/Pulumi.dev.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
secretsprovider: awskms://12e131e6-2150-4361-913b-803c04bd5ed5?region=eu-west-2&awssdk=v2
2+
encryptedkey: AQICAHhLE3kXzgyhKhfd8kMt7I2EBNdrJw7DPra9AQz3o1duvwFP5X23eeRpxqRKtjmP4VNoAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMDGX3lZXomIJHHVIMAgEQgDuk/UkIZt7A+8db7RGO9aWvexlDZxGmSK6m7Wda/LXX0gblOSKbjyYxW+cheqvz0Jvx8fkHNPep0dZgSA==
3+
config:
4+
gitHubRepo: iainlane/coldoutsi.de
5+
targetDomain: dev
6+
targetZone: coldoutsi.de

0 commit comments

Comments
 (0)