Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Deploy Infrastructure

# CI success on a push to main deploys TEST -> STAGE; PROD is skipped.
# Manual dispatch from main deploys TEST -> STAGE -> PROD, with PROD approval.
# Each environment has two stacks: network first, then frontend.
# OpenTofu state is stored per stack in Kubernetes; kOps state is held in Swift.
# Normal deployments reject delete/replacement plans; destruction is separate.
on:
workflow_run:
workflows: [CI]
Expand Down Expand Up @@ -43,7 +48,7 @@ jobs:
OS_INTERFACE: public
OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }}
OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}

# Swift stores the kOps cluster configuration, not OpenTofu state.
KOPS_STATE_STORE: swift://demo-kops

steps:
Expand All @@ -58,7 +63,7 @@ jobs:
- name: Setup OpenTofu
uses: opentofu/setup-opentofu@v2
with:
tofu_version: "1.12.6"
tofu_version_file: .opentofu-version
tofu_wrapper: false

- name: Verify jq installation
Expand Down Expand Up @@ -222,7 +227,8 @@ jobs:
echo "TEST remote state initialization completed."
# Plan and automatically apply safe TEST infrastructure changes.
# Only known non-destructive changes are applied automatically.
# The dedicated destroy workflows handle intentional resource deletion.
- name: Deploy TEST infrastructure
shell: bash
env:
Expand Down Expand Up @@ -265,7 +271,12 @@ jobs:
# Handle planning errors.
if [ "$EXIT_CODE" -ne 0 ] && [ "$EXIT_CODE" -ne 2 ]; then
echo "::error::TEST $STACK planning failed."
echo "::error::TEST $STACK infrastructure planning failed (exit code: $EXIT_CODE)."
echo "The OpenTofu planning process could not complete."
echo "Possible causes include provider/API availability, authentication, or configuration errors."
echo "No infrastructure changes were applied for this stack."
echo "::notice::If the failure may be temporary, try re-running the failed jobs in GitHub Actions."
echo "::notice::If the issue persists, investigate the OpenTofu planning error before retrying."
exit 1
fi
Expand Down Expand Up @@ -339,6 +350,7 @@ jobs:
deploy-stage:
name: Deploy STAGE
# A failed TEST deployment stops the rollout before STAGE.
needs: deploy-test
runs-on: [self-hosted, linux, assignment2]
timeout-minutes: 45
Expand All @@ -352,6 +364,7 @@ jobs:
OS_INTERFACE: public
OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }}
OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}
# Swift stores the kOps cluster configuration, not OpenTofu state.
KOPS_STATE_STORE: swift://demo-kops

steps:
Expand All @@ -365,7 +378,7 @@ jobs:
- name: Setup OpenTofu
uses: opentofu/setup-opentofu@v2
with:
tofu_version: "1.12.6"
tofu_version_file: .opentofu-version
tofu_wrapper: false

- name: Verify jq installation
Expand Down Expand Up @@ -557,7 +570,12 @@ jobs:
set -e
if [ "$EXIT_CODE" -ne 0 ] && [ "$EXIT_CODE" -ne 2 ]; then
echo "::error::STAGE $STACK planning failed."
echo "::error::STAGE $STACK infrastructure planning failed (exit code: $EXIT_CODE)."
echo "The OpenTofu planning process could not complete."
echo "Possible causes include provider/API availability, authentication, or configuration errors."
echo "No infrastructure changes were applied for this stack."
echo "::notice::If the failure may be temporary, try re-running the failed jobs in GitHub Actions."
echo "::notice::If the issue persists, investigate the OpenTofu planning error before retrying."
exit 1
fi
Expand Down Expand Up @@ -615,6 +633,7 @@ jobs:
echo "STAGE infrastructure deployment completed."
# Remove temporary credentials, plans and logs.
- name: Clean up temporary files
if: always()
shell: bash
Expand All @@ -628,6 +647,7 @@ jobs:
deploy-prod:
name: Deploy PROD
# PROD depends on STAGE and requires approval through the PROD environment.
needs: deploy-stage

# Only deploy PROD when manually triggered from main.
Expand All @@ -649,7 +669,7 @@ jobs:
OS_INTERFACE: public
OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }}
OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}

# Swift stores the kOps cluster configuration, not OpenTofu state.
KOPS_STATE_STORE: swift://demo-kops

steps:
Expand All @@ -664,7 +684,7 @@ jobs:
- name: Setup OpenTofu
uses: opentofu/setup-opentofu@v2
with:
tofu_version: "1.12.6"
tofu_version_file: .opentofu-version
tofu_wrapper: false

- name: Verify jq installation
Expand Down Expand Up @@ -869,7 +889,12 @@ jobs:
# Handle planning errors.
if [ "$EXIT_CODE" -ne 0 ] && [ "$EXIT_CODE" -ne 2 ]; then
echo "::error::PROD $STACK planning failed."
echo "::error::PROD $STACK infrastructure planning failed (exit code: $EXIT_CODE)."
echo "The OpenTofu planning process could not complete."
echo "Possible causes include provider/API availability, authentication, or configuration errors."
echo "No infrastructure changes were applied for this stack."
echo "::notice::If the failure may be temporary, try re-running the failed jobs in GitHub Actions."
echo "::notice::If the issue persists, investigate the OpenTofu planning error before retrying."
exit 1
fi
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/destroy-prod.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Destroy Infrastructure (PROD)

# Destructive PROD operation: manual trigger only; must run from main.
# Manually destroys PROD infrastructure from main after environment approval.
# Uses PROD-specific credentials and verifies the expected Kubernetes state.
# Removes frontend before network using saved destruction plans.
# Shares the deployment concurrency lock to prevent overlapping operations.
on:
workflow_dispatch:

Expand Down Expand Up @@ -200,6 +203,7 @@ jobs:
echo "::endgroup::"
done
# Remove temporary Kubernetes credentials and saved destruction plans.
- name: Clean up temporary files
if: always()
shell: bash
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/destroy-stage.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Destroy Infrastructure (STAGE)

# Destructive operation: manually triggered on main; targets only STAGE.
# Manually destroys STAGE infrastructure from main.
# Removes frontend before network to respect dependencies.
# Verifies the remote state target before applying a saved destroy plan.
on:
workflow_dispatch:

Expand Down Expand Up @@ -199,6 +201,7 @@ jobs:
echo "::endgroup::"
done
# Remove temporary Kubernetes credentials and saved destruction plans.
- name: Clean up temporary files
if: always()
shell: bash
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/destroy-test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Destroy Infrastructure (TEST)

# Manually destroys TEST infrastructure from main.
# Removes frontend before network to respect dependencies.
# Verifies the remote state target before applying a saved destroy plan.
on:
workflow_dispatch:

Expand Down Expand Up @@ -158,7 +161,8 @@ jobs:
rm -f "$PLAN_FILE" "$PLAN_JSON"
echo "::endgroup::"
done
# Remove temporary Kubernetes credentials and saved destruction plans.
- name: Clean up temporary files
if: always()
shell: bash
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/destroy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Destroy Infrastructure (TEST, STAGE)

# Manually destroys TEST and STAGE infrastructure.
# Uses environment-specific credentials and separate remote states.
# Environments are processed one at a time; order is not guaranteed.
# Within each environment, frontend is destroyed before network.
# Only runs from main and shares the deployment concurrency lock.
on:
workflow_dispatch:

Expand Down Expand Up @@ -209,6 +214,7 @@ jobs:
echo "::endgroup::"
done
# Remove temporary Kubernetes credentials and saved destruction plans.
- name: Clean up temporary files
if: always()
shell: bash
Expand Down
34 changes: 0 additions & 34 deletions .github/workflows/runner-test.yml

This file was deleted.