Skip to content

Commit acbc5fa

Browse files
committed
feat: add uvicorn start command and improve config examples
1 parent 3bfd1fb commit acbc5fa

4 files changed

Lines changed: 113 additions & 4 deletions

File tree

terraform/.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Terraform files
2+
*.tfstate
3+
*.tfstate.*
4+
*.tfvars
5+
!terraform.tfvars.example
6+
.terraform/
7+
.terraform.lock.hcl
8+
9+
# Crash log files
10+
crash.log
11+
crash.*.log
12+
13+
# Exclude all .tfvars files, which are likely to contain sensitive data
14+
*.tfvars.json
15+
16+
# Ignore override files as they are usually used to override resources locally and so
17+
# are not checked in
18+
override.tf
19+
override.tf.json
20+
*_override.tf
21+
*_override.tf.json
22+
23+
# Include override files you do wish to add to version control using negated pattern
24+
# !example_override.tf
25+
26+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
27+
*tfplan*
28+
29+
# Ignore CLI configuration files
30+
.terraformrc
31+
terraform.rc

terraform/deploy.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
# Terraform deployment script for DevColor Backend
4+
5+
echo "🚀 Starting Terraform deployment for DevColor Backend..."
6+
7+
# Check if terraform.tfvars exists
8+
if [ ! -f "terraform.tfvars" ]; then
9+
echo "❌ terraform.tfvars not found!"
10+
echo "📝 Please copy terraform.tfvars.example to terraform.tfvars and update with your values:"
11+
echo " cp terraform.tfvars.example terraform.tfvars"
12+
echo " # Then edit terraform.tfvars with your database details"
13+
exit 1
14+
fi
15+
16+
# Initialize Terraform
17+
echo "🔧 Initializing Terraform..."
18+
terraform init
19+
20+
if [ $? -ne 0 ]; then
21+
echo "❌ Terraform init failed!"
22+
exit 1
23+
fi
24+
25+
# Validate configuration
26+
echo "✅ Validating Terraform configuration..."
27+
terraform validate
28+
29+
if [ $? -ne 0 ]; then
30+
echo "❌ Terraform validation failed!"
31+
exit 1
32+
fi
33+
34+
# Plan deployment
35+
echo "📋 Planning Terraform deployment..."
36+
terraform plan -out=tfplan
37+
38+
if [ $? -ne 0 ]; then
39+
echo "❌ Terraform plan failed!"
40+
exit 1
41+
fi
42+
43+
# Ask for confirmation
44+
echo ""
45+
echo "🤔 Do you want to apply this plan? (y/N)"
46+
read -r response
47+
48+
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
49+
echo "🚀 Applying Terraform configuration..."
50+
terraform apply tfplan
51+
52+
if [ $? -eq 0 ]; then
53+
echo ""
54+
echo "✅ Deployment completed successfully!"
55+
echo ""
56+
echo "📊 Important outputs:"
57+
echo "ECR Repository URL:"
58+
terraform output ecr_repository_url
59+
echo ""
60+
echo "App Runner Service URL:"
61+
terraform output apprunner_service_url
62+
echo ""
63+
echo "App Runner Service ARN (for GitHub secrets):"
64+
terraform output apprunner_service_arn
65+
echo ""
66+
echo "🔑 Next steps:"
67+
echo "1. Add the App Runner Service ARN to your GitHub secrets as 'APPRUNNER_SERVICE_ARN'"
68+
echo "2. Push to main branch to trigger deployment"
69+
else
70+
echo "❌ Terraform apply failed!"
71+
exit 1
72+
fi
73+
else
74+
echo "❌ Deployment cancelled by user"
75+
rm -f tfplan
76+
exit 0
77+
fi

terraform/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ resource "aws_apprunner_service" "devcolor00_school" {
124124
DB_PASSWORD = var.db_password
125125
DB_PORT = var.db_port
126126
}
127+
start_command = "uvicorn api.main:app --host 0.0.0.0 --port 8000"
127128
}
128129
image_identifier = "${aws_ecr_repository.devcolor00_school.repository_url}:latest"
129130
image_repository_type = "ECR"

terraform/terraform.tfvars.example

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Database configuration
2-
db_host = "your-database-host"
3-
db_user = "your-database-user"
4-
db_password = "your-database-password"
1+
# Database configuration - Update these with your actual database details
2+
db_host = "your-mysql-host.com"
3+
db_user = "your-db-username"
4+
db_password = "your-secure-password"
55
db_port = "3306"
66

77
# AWS configuration

0 commit comments

Comments
 (0)