6
6
- devops/a3
7
7
tags :
8
8
- deploy-dev
9
- - deploy-qa
10
9
- deploy-prod
11
10
12
11
workflow_dispatch :
18
17
type : choice
19
18
options :
20
19
- dev
21
- - qa
22
20
- prod
23
21
24
22
env :
@@ -47,23 +45,21 @@ jobs:
47
45
- name : Setup Terraform
48
46
uses : hashicorp/setup-terraform@v3
49
47
50
- # Determin Stage - dev/prod/qa defaults to dev
51
- # - name: Determine Stage
52
- # id: set_stage
53
- # run: |
54
- # if [[ "${GITHUB_REF}" == "refs/tags/deploy-dev" ]]; then
55
- # echo "STAGE=dev" >> $GITHUB_ENV
56
- # elif [[ "${GITHUB_REF}" == "refs/tags/deploy-qa" ]]; then
57
- # echo "STAGE=qa" >> $GITHUB_ENV
58
- # elif [[ "${GITHUB_REF}" == "refs/tags/deploy-prod" ]]; then
59
- # echo "STAGE=prod" >> $GITHUB_ENV
60
- # elif [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
61
- # echo "STAGE=${{ github.event.inputs.stage }}" >> $GITHUB_ENV
62
- # else
63
- # echo "STAGE=dev" >> $GITHUB_ENV # default fallback
64
- # fi
65
-
66
- # echo "🛠️ Deployment stage: $STAGE"
48
+ # Determine Stage - dev/prod defaults to dev
49
+ - name : Determine Stage
50
+ id : set_stage
51
+ run : |
52
+ if [[ "${GITHUB_REF}" == "refs/tags/deploy-dev" ]]; then
53
+ echo "STAGE=dev" >> $GITHUB_ENV
54
+ elif [[ "${GITHUB_REF}" == "refs/tags/deploy-prod" ]]; then
55
+ echo "STAGE=prod" >> $GITHUB_ENV
56
+ elif [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
57
+ echo "STAGE=${{ github.event.inputs.stage }}" >> $GITHUB_ENV
58
+ else
59
+ echo "STAGE=dev" >> $GITHUB_ENV # default fallback
60
+ fi
61
+
62
+ echo "🛠️ Deployment stage: $STAGE"
67
63
68
64
# Terraform Init & Workspace
69
65
- name : Terraform Init & Workspace
87
83
# echo "INSTANCE_IP=$(terraform output -raw instance_public_ip)" >> $GITHUB_ENV
88
84
# echo "VERIFIER_IP=$(terraform output -raw verifier_instance_public_ip)" >> $GITHUB_ENV
89
85
# echo "S3_BUCKET=$(terraform output -raw s3_log_bucket)" >> $GITHUB_ENV
86
+
87
+
90
88
# Assign to local shell variables
91
89
INSTANCE_IP=$(terraform output -raw instance_public_ip)
92
90
VERIFIER_IP=$(terraform output -raw verifier_instance_public_ip)
@@ -112,9 +110,12 @@ jobs:
112
110
# Validate App Health
113
111
- name : Validate App Health
114
112
run : |
113
+ echo -e "\n📦 Full Response from App:\n"
114
+ curl -s http://${{ env.INSTANCE_IP }}:80 || echo "❌ Failed to get response"
115
+ echo -e "\n"
115
116
echo "Checking app health at http://${{ env.INSTANCE_IP }}:80"
116
117
for i in {1..10}; do
117
- STATUS=$(curl -o /dev/null -s -w "%{http_code}" http://$INSTANCE_IP:80)
118
+ STATUS=$(curl -o /dev/null -s -w "%{http_code}" http://${{ env. INSTANCE_IP }} :80)
118
119
if [[ "$STATUS" == "200" ]]; then
119
120
echo "✅ App is healthy (HTTP 200)"
120
121
exit 0
@@ -126,19 +127,16 @@ jobs:
126
127
echo "❌ App failed health check"
127
128
exit 1
128
129
129
- echo -e "\n📦 Full Response from App:\n"
130
- curl -s http://${{ env.INSTANCE_IP }}:80 || echo "❌ Failed to get response"
131
- echo -e "\n"
132
130
133
131
# Verify Logs in S3
134
132
- name : Verify Logs in S3
135
133
run : |
136
134
echo "📦 Checking for logs in S3 bucket: $S3_BUCKET"
137
- aws s3 ls s3://$S3_BUCKET/system/cloud-init.log || { echo "❌ system logs missing"; exit 1; }
138
- aws s3 ls s3://$S3_BUCKET/app/my-app.log || { echo "❌ app logs missing"; exit 1; }
135
+ aws s3 ls s3://$S3_BUCKET/${{ github.event.inputs.stage }}/ system/cloud-init.log || { echo "❌ system logs missing"; exit 1; }
136
+ aws s3 ls s3://$S3_BUCKET/${{ github.event.inputs.stage }}/ app/my-app.log || { echo "❌ app logs missing"; exit 1; }
139
137
echo "✅ Logs found in S3 bucket"
140
138
141
- # Destroy (disabled by default )
139
+ # Destroy (automatically always to avoid manual deletion )
142
140
- name : Destroy infrastructure
143
141
if : always()
144
142
working-directory : ${{ env.TF_WORKING_DIR }}
0 commit comments