Merge pull request #116 from hazre/feat/cloudflare-workers-iac

feat: add Cloudflare Workers IaC and deployment workflow
This commit is contained in:
7w1 authored and GitHub committed 2026-03-04 21:21:18 -06:00
commit aa9f64fee7
20 files changed
+1884 -70

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
name: Prepare OpenTofu Deployment
description: Prepares OpenTofu in infra/web.
inputs:
opentofu-version:
description: The OpenTofu version to install.
required: false
default: '1.11.5'
runs:
using: composite
steps:
- name: Setup app and build
uses: ./.github/actions/setup
with:
build: 'true'
- name: Setup OpenTofu
uses: opentofu/setup-opentofu@9d84900f3238fab8cd84ce47d658d25dd008be2f # v1.0.8
with:
tofu_version: ${{ inputs.opentofu-version }}
- name: Check formatting
shell: bash
working-directory: ${{ github.workspace }}/infra/web
run: tofu fmt -check
- name: Initialize OpenTofu
shell: bash
working-directory: ${{ github.workspace }}/infra/web
run: tofu init -input=false -reconfigure
- name: Validate configuration
shell: bash
working-directory: ${{ github.workspace }}/infra/web
run: tofu validate -no-color
+40
View File
@@ -0,0 +1,40 @@
name: Setup App
description: Sets up Node.js, installs dependencies, and optionally builds the app.
inputs:
install-command:
description: Command used to install dependencies.
required: false
default: npm ci
build:
description: Whether to build the app after installing dependencies.
required: false
default: 'false'
build-command:
description: Command used when build is enabled.
required: false
default: npm run build
runs:
using: composite
steps:
- name: Setup node
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version-file: '.node-version'
cache: 'npm'
- name: Install dependencies
shell: bash
working-directory: ${{ github.workspace }}
run: ${INPUTS_INSTALL_COMMAND}
env:
INPUTS_INSTALL_COMMAND: ${{ inputs.install-command }}
- name: Build app
if: ${{ inputs.build == 'true' }}
shell: bash
working-directory: ${{ github.workspace }}
run: ${INPUTS_BUILD_COMMAND}
env:
INPUTS_BUILD_COMMAND: ${{ inputs.build-command }}
@@ -0,0 +1,80 @@
name: Cloudflare Infra
on:
pull_request:
paths:
- 'infra/web/**'
- '.github/workflows/cloudflare-web-deploy.yml'
- '.github/actions/prepare-tofu/**'
- '.github/actions/setup/**'
push:
branches:
- dev
workflow_dispatch:
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.TF_CLOUDFLARE_API_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TF_VAR_workers_message: ${{ github.event_name == 'pull_request' && github.event.pull_request.title || github.event.head_commit.message || github.sha }}
TF_VAR_account_id: ${{ secrets.TF_VAR_ACCOUNT_ID }}
TF_VAR_zone_id: ${{ secrets.TF_VAR_ZONE_ID }}
TF_HTTP_ADDRESS: ${{ secrets.TF_HTTP_ADDRESS }}
TF_HTTP_LOCK_ADDRESS: ${{ secrets.TF_HTTP_LOCK_ADDRESS }}
TF_HTTP_UNLOCK_ADDRESS: ${{ secrets.TF_HTTP_UNLOCK_ADDRESS }}
TF_HTTP_USERNAME: ${{ secrets.TF_HTTP_USERNAME }}
TF_HTTP_PASSWORD: ${{ secrets.TF_HTTP_PASSWORD }}
TF_HTTP_LOCK_METHOD: 'POST'
TF_HTTP_UNLOCK_METHOD: 'DELETE'
TF_HTTP_RETRY_WAIT_MIN: '5'
concurrency:
group: cloudflare-infra
cancel-in-progress: false
jobs:
plan:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
defaults:
run:
working-directory: infra/web
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Prepare OpenTofu deployment
uses: ./.github/actions/prepare-tofu
- name: Comment PR plan
uses: dflook/tofu-plan@3f5dc358343fb58cd60f83b019e810315aa8258f # v2.2.3
with:
path: infra/web
label: production
apply:
if: (github.event_name == 'push' && github.ref_name == 'dev') || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
working-directory: infra/web
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Prepare OpenTofu deployment
uses: ./.github/actions/prepare-tofu
- name: Plan infrastructure
run: tofu plan -input=false -no-color
- name: Apply infrastructure
run: tofu apply -input=false -auto-approve
+17 -27
View File
@@ -15,13 +15,10 @@ jobs:
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup node
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version-file: '.node-version'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Setup app
uses: ./.github/actions/setup
- name: Check formatting
run: npm run fmt:check
@@ -35,13 +32,10 @@ jobs:
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup node
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version-file: '.node-version'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Setup app
uses: ./.github/actions/setup
- name: Run ESLint
run: npm run lint
@@ -55,13 +49,10 @@ jobs:
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup node
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version-file: '.node-version'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Setup app
uses: ./.github/actions/setup
- name: Run TypeScript typecheck
run: npm run typecheck -- --pretty false
@@ -75,12 +66,11 @@ jobs:
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup node
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
- name: Setup app
uses: ./.github/actions/setup
with:
node-version-file: '.node-version'
cache: 'npm'
- name: Install dependencies
run: npm ci --ignore-scripts
install-command: npm ci --ignore-scripts
- name: Run Knip
run: npm run knip