diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c16a6b0..b040624 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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] @@ -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: @@ -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 @@ -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: @@ -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 @@ -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 @@ -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: @@ -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 @@ -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 @@ -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 @@ -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. @@ -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: @@ -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 @@ -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 diff --git a/.github/workflows/destroy-prod.yml b/.github/workflows/destroy-prod.yml index e0aa6fd..5f03afd 100644 --- a/.github/workflows/destroy-prod.yml +++ b/.github/workflows/destroy-prod.yml @@ -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: @@ -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 diff --git a/.github/workflows/destroy-stage.yml b/.github/workflows/destroy-stage.yml index b173bbb..25b65fd 100644 --- a/.github/workflows/destroy-stage.yml +++ b/.github/workflows/destroy-stage.yml @@ -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: @@ -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 diff --git a/.github/workflows/destroy-test.yml b/.github/workflows/destroy-test.yml index e5249d1..8ee668a 100644 --- a/.github/workflows/destroy-test.yml +++ b/.github/workflows/destroy-test.yml @@ -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: @@ -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 diff --git a/.github/workflows/destroy.yml b/.github/workflows/destroy.yml index e9a78c1..fd76d2d 100644 --- a/.github/workflows/destroy.yml +++ b/.github/workflows/destroy.yml @@ -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: @@ -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 diff --git a/.github/workflows/runner-test.yml b/.github/workflows/runner-test.yml deleted file mode 100644 index 4d9ba72..0000000 --- a/.github/workflows/runner-test.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Runner Test - -on: - workflow_dispatch: - -permissions: - contents: read - -jobs: - test: - runs-on: [self-hosted, linux, assignment2] - timeout-minutes: 10 - - steps: - - name: Checkout repository - uses: actions/checkout@v5 - with: - persist-credentials: false - - - name: Setup OpenTofu - uses: opentofu/setup-opentofu@v2 - with: - tofu_version: "1.12.6" - tofu_wrapper: false - - - name: Verify runner - run: | - echo "Runner is working" - hostname - whoami - uname -a - - - name: Verify OpenTofu - run: tofu version \ No newline at end of file