Skip to content

Commit 6542038

Browse files
refactor: simplify to pure prod.tfvars workflow
1 parent d52aba3 commit 6542038

File tree

3 files changed

+26
-49
lines changed

3 files changed

+26
-49
lines changed

.github/workflows/release-prod.yml

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ on:
44
push:
55
branches: [main]
66
paths:
7-
- 'versions.yaml'
8-
- '.github/workflows/release-prod.yml'
7+
- 'infra/prod.tfvars'
98
workflow_dispatch:
109

1110
# CRITICAL: Concurrency Control
@@ -18,7 +17,7 @@ permissions:
1817
id-token: write
1918

2019
jobs:
21-
# Phase 1: Extract and verify configuration from versions.yaml
20+
# Phase 1: Extract and verify configuration
2221
config:
2322
runs-on: ubuntu-latest
2423
outputs:
@@ -30,28 +29,28 @@ jobs:
3029
steps:
3130
- uses: actions/checkout@v4
3231

33-
- name: Parse versions.yaml and Environment Config
32+
- name: Parse Configuration
3433
id: parse
3534
run: |
36-
# Read the SHA from versions.yaml (dev section)
37-
DEV_SHA=$(grep -A 1 "^dev:" versions.yaml | grep "image_version:" | sed 's/.*image_version: *//' | tr -d '" ')
35+
# Read all config from prod.tfvars
36+
PROJECT_ID=$(grep -E '^\s*project_id\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"]+)".*/\1/')
37+
SA=$(grep -E '^\s*service_account\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"]+)".*/\1/')
38+
BUCKET=$(grep -E '^\s*state_bucket\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"]+)".*/\1/')
39+
# Read the version you manually set in prod.tfvars
40+
VERSION=$(grep -E '^\s*image_version\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"]+)".*/\1/')
3841
39-
# Read from prod.tfvars
40-
PROJECT_ID=$(grep -E '^\s*project_id\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"+)".*/\1/')
41-
SA=$(grep -E '^\s*service_account\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"+)".*/\1/')
42-
BUCKET=$(grep -E '^\s*state_bucket\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"+)".*/\1/')
42+
# Derive dev project ID from prod service account
43+
# Format: tofu-provisioner@hubspoke-demo-dev-b87d.iam.gserviceaccount.com
44+
DEV_PROJECT_ID=$(echo "$SA" | sed -E 's/.*@([^\.]+)\.iam\.gserviceaccount\.com/\1/' | sed 's/-prod-[a-f0-9]\{4\}/-dev-b87d/')
4345
44-
# Derive dev project ID (strip -prod- suffix and add -dev- pattern)
45-
DEV_PROJECT_ID=$(echo "$PROJECT_ID" | sed 's/-prod-[a-f0-9]\{4\}/-dev-b87d/')
46-
47-
echo "version=$DEV_SHA" >> $GITHUB_OUTPUT
46+
echo "version=$VERSION" >> $GITHUB_OUTPUT
4847
echo "service_account=$SA" >> $GITHUB_OUTPUT
4948
echo "state_bucket=$BUCKET" >> $GITHUB_OUTPUT
5049
echo "project_id=$PROJECT_ID" >> $GITHUB_OUTPUT
5150
echo "dev_project_id=$DEV_PROJECT_ID" >> $GITHUB_OUTPUT
5251
5352
echo "📋 Configuration:"
54-
echo " Version (from versions.yaml): $DEV_SHA"
53+
echo " Version (from prod.tfvars): $VERSION"
5554
echo " Prod Project: $PROJECT_ID"
5655
echo " Dev Project: $DEV_PROJECT_ID"
5756
@@ -127,7 +126,6 @@ jobs:
127126
echo "📋 Running tofu plan..."
128127
tofu plan \
129128
-var-file="prod.tfvars" \
130-
-var="image_version=${{ needs.config.outputs.version }}" \
131129
-no-color \
132130
-out=tfplan
133131
@@ -138,22 +136,6 @@ jobs:
138136
echo "🚀 Applying infrastructure changes..."
139137
tofu apply tfplan -no-color
140138
141-
- name: Update versions.yaml Prod Section
142-
if: success()
143-
run: |
144-
VERSION="${{ needs.config.outputs.version }}"
145-
TIMESTAMP=$(date -Iseconds)
146-
147-
# Update versions.yaml with prod deployment info
148-
sed -i "/^prod:/,/^[^ ]/{s/image_version:.*/image_version: \"$VERSION\"/}" versions.yaml
149-
sed -i "/^prod:/,/^[^ ]/{s/promoted_at:.*/promoted_at: \"$TIMESTAMP\"/}" versions.yaml
150-
151-
git config --local user.email "github-actions[bot]@users.noreply.github.com"
152-
git config --local user.name "github-actions[bot]"
153-
git add versions.yaml
154-
git commit -m "docs: update prod version to $VERSION [skip ci]"
155-
git push
156-
157139
- name: Deployment Summary
158140
if: always()
159141
run: |

infra/prod.tfvars

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Production Environment Configuration
22
# Protected by CODEOWNERS - requires approval from @brancengregory
3+
#
4+
# MANUAL PROMOTION WORKFLOW:
5+
# 1. Check latest successful dev build in GitHub Actions (SHA shown in workflow output)
6+
# 2. Verify that SHA has both artifacts in dev:
7+
# - Container: us-central1-docker.pkg.dev/hubspoke-demo-dev-b87d/repo/hubspoke-demo:[SHA]
8+
# - GCE Image: gs://hubspoke-demo-dev-nixos-images/nixos-image-[SHA].tar.gz
9+
# 3. Update image_version below with that full SHA (40 characters)
10+
# 4. Commit and push - triggers promotion workflow
11+
# 5. Workflow will: copy artifacts to prod, deploy to Cloud Run + GCE
12+
#
13+
# Current SHA: c5668ae (verified in dev, has both container and GCE image)
314

415
project_id = "hubspoke-demo-prod-f01c"
516
service_account = "tofu-provisioner@hubspoke-demo-prod-f01c.iam.gserviceaccount.com"
@@ -10,8 +21,7 @@ state_bucket = "hubspoke-demo-prod-tfstate"
1021
# Artifact Storage (for NixOS images)
1122
artifact_bucket = "hubspoke-demo-prod-nixos-images"
1223

13-
# Git SHA from dev build (must exist in BOTH container registry AND GCS bucket)
14-
# Available SHAs with both artifacts: c5668ae, 9bc606d, 896fc64, 34ea7a0, etc.
24+
# Version to deploy - must match a successful dev build (update manually)
1525
image_version = "c5668ae"
1626
region = "us-central1"
1727
environment = "prod"

versions.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)