Skip to content

Commit 25d40df

Browse files
committed
Minor fixes and readme changes
Signed-off-by: Akhil <2100030084@kluniversity.in>
1 parent d06c08b commit 25d40df

File tree

4 files changed

+84
-9
lines changed

4 files changed

+84
-9
lines changed

.github/workflows/deploy.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ jobs:
8383
S3_BUCKET=$(terraform output -raw s3_log_bucket)
8484
echo "INSTANCE_IP=$INSTANCE_IP" >> $GITHUB_ENV
8585
echo "S3_BUCKET=$S3_BUCKET" >> $GITHUB_ENV
86+
8687
echo "📦 App IP: $INSTANCE_IP"
8788
echo "🪣 S3 Bucket: $S3_BUCKET"
8889
@@ -95,14 +96,17 @@ jobs:
9596
# Validate App Health
9697
- name: Validate App Health
9798
run: |
98-
echo "🔎 Checking app health at http://${INSTANCE_IP}:80"
99+
echo -e "\n📦 Full Response from App:\n"
100+
curl -s http://${{ env.INSTANCE_IP }}:80 || echo "❌ Failed to get response"
101+
echo -e "\n"
102+
echo "Checking app health at http://${{ env.INSTANCE_IP }}:80"
99103
for i in {1..10}; do
100-
STATUS=$(curl -o /dev/null -s -w "%{http_code}" http://${INSTANCE_IP}:80)
104+
STATUS=$(curl -o /dev/null -s -w "%{http_code}" http://${{ env.INSTANCE_IP }}:80)
101105
if [[ "$STATUS" == "200" ]]; then
102106
echo "✅ App is healthy (HTTP 200)"
103107
exit 0
104108
else
105-
echo "Attempt $i: HTTP $STATUS"
109+
echo "Attempt $i: got HTTP $STATUS"
106110
sleep 10
107111
fi
108112
done

README.md

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tech_eazy_devops_git-user-9/
1616
├── terraform/ # Terraform configurations
1717
│ ├── main.tf # Main Terraform configuration file
1818
│ ├── outputs.tf # Defines Terraform outputs (e.g., EC2 public IP)
19-
│ ├── variables.tf # Public variables file for EC2 and other details
19+
│ ├── variables.tf # Common variables (e.g., region, key pair name)
2020
│ ├── dev_config.tfvars # Variable values for 'Dev' environment
2121
│ ├── prod_config.tfvars # Variable values for 'Prod' environment
2222
├── scripts/ # Shell scripts for configuration and log validation
@@ -47,6 +47,38 @@ tech_eazy_devops_git-user-9/
4747

4848
---
4949

50+
## 🔑 **Step: Configure Terraform Variables**
51+
52+
Before triggering deployment, update the Terraform configuration files for your AWS environment:
53+
54+
1. Open `terraform/variables.tf`
55+
2. Set the default values for common variables like EC2 Key Pair name:
56+
57+
```hcl
58+
variable "key_name" {
59+
default = "your-ec2-keypair-name" # Set your AWS Key Pair name
60+
}
61+
```
62+
63+
3. Edit `terraform/dev_config.tfvars` and `terraform/prod_config.tfvars`:
64+
65+
* Example (`dev_config.tfvars`):
66+
67+
```hcl
68+
key_name = "your-ec2-keypair-name"
69+
```
70+
71+
* Example (`prod_config.tfvars`):
72+
73+
```hcl
74+
key_name = "your-ec2-keypair-name"
75+
```
76+
77+
⚠️ Ensure your EC2 Key Pair exists in the selected AWS region.
78+
*ap-south-1 (Mumbai) is being used by default in this project, so kindly create a ec2 key pair on this region for smoother experience during execution. Otherwise kindly change ap-south-1 at all places to your preferred region*
79+
80+
---
81+
5082
## 🔐 **How to Get SSH Private Key from .pem File**
5183

5284
When you create an AWS EC2 Key Pair, AWS provides a `.pem` file. To use this in GitHub Actions, you must convert it to a format that can be stored as a secret.
@@ -83,31 +115,70 @@ The deployment is managed via GitHub Actions.
83115
* **Git Tags**: `deploy-dev` (for Dev), `deploy-prod` (for Prod)
84116
* **Manual Trigger**: Run from GitHub Actions → Select Stage (dev/prod)
85117

118+
---
119+
120+
#### 🏷️ **Trigger Deployment via Git Tags**
121+
122+
To deploy to **Dev** or **Prod**, create and push the appropriate Git tag:
123+
124+
*⚠️ Make sure your working directory is clean (git status) before creating tags to avoid pushing unwanted changes.*
125+
126+
##### For Dev Environment:
127+
128+
```bash
129+
git tag deploy-dev
130+
git push origin deploy-dev
131+
```
132+
133+
##### For Prod Environment:
134+
135+
```bash
136+
git tag deploy-prod
137+
git push origin deploy-prod
138+
```
139+
140+
The GitHub Actions workflow will automatically detect the tag and deploy to the respective environment.
141+
142+
---
143+
144+
---
145+
86146
### 📖 Overview of Workflow
87147

88148
The workflow performs the following steps:
89149

90150
1. **Checkout Repository** – Fetches the code from the repository.
151+
91152
2. **Configure AWS Credentials** – Uses GitHub Secrets to authenticate with AWS.
153+
92154
3. **Setup Terraform** – Installs Terraform and initializes configuration.
155+
93156
4. **Determine Stage** – Sets the target environment (dev or prod) based on trigger type.
94-
5. **Provision App EC2 Instance (Write Access)**
157+
158+
5. **Provision App EC2 Instance (Write Access)**
95159

96160
* Deploys the first EC2 instance with **write access to S3**.
97161
* Installs required software (Java, Maven, Git, etc.).
98162
* Pulls source code from the repository and builds the Maven application.
99163
* Runs the application and pushes logs (system and app logs) to the S3 bucket.
100-
6. **Provision Verifier EC2 Instance (Read Access)**
164+
165+
6. **Provision Verifier EC2 Instance (Read Access)**
101166

102167
* Deploys a second EC2 instance with **read-only access to S3**.
103168
* Uses AWS CLI to pull logs from the S3 bucket to the instance.
104-
7. **Log Validation via SSH**
169+
170+
7. **Log Validation via SSH**
105171

106172
* SSH into the Verifier EC2 instance.
107173
* Validates that required logs exist in S3.
108174
* Prints the last 20 lines of each log for inspection.
175+
109176
8. **App Health Check** – Ensures the application is healthy (HTTP 200 response).
177+
110178
9. **Destroy Infrastructure** – After validation, destroys all provisioned resources and cleans up Terraform workspaces.
111179

180+
112181
This workflow fully automates the lifecycle: provisioning, deployment, validation, and cleanup, ensuring no manual intervention is needed during the process.
113182

183+
---
184+

terraform/dev_config.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ key_name = "ssh-key-ec2" #change this to your key-pair name
33
# ami_id = "ami-0f918f7e67a3323f0"
44
stage = "dev"
55
shutdown_minutes = 30
6-
s3_bucket_name = "techeazy-logs-dev-unique123ss" # Change this!
6+
s3_bucket_name = "techeazy-logs-unique123ss" # Change this!
77
aws_region = "ap-south-1"
88
repo_url = "https://github.com/techeazy-consulting/techeazy-devops"
99
verifier_lifetime = 25

terraform/prod_config.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ key_name = "ssh-key-ec2" #change this to your key-pair name
33
# ami_id = "ami-0f918f7e67a3323f0"
44
stage = "prod"
55
shutdown_minutes = 25
6-
s3_bucket_name = "techeazy-logs-prod-unique123ss" # Change this!
6+
s3_bucket_name = "techeazy-logs-unique123ss" # Change this!
77
aws_region = "ap-south-1"
88
repo_url = "https://github.com/techeazy-consulting/techeazy-devops"
99
verifier_lifetime = 25

0 commit comments

Comments
 (0)