Skip to content

Commit 7eadd94

Browse files
committed
Add ECR deployment script and update deployment documentation
1 parent 10fed6e commit 7eadd94

2 files changed

Lines changed: 132 additions & 12 deletions

File tree

QUICK_DEPLOY.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,34 @@ After GitHub Action completes:
5353
PORT: 8000
5454
```
5555
56-
### Alternative: Manual ECR Push (if GitHub Actions fails)
57-
58-
If you prefer manual deployment:
56+
### Alternative: Manual ECR Push (Local Deployment)
57+
58+
### Prerequisites
59+
1. **Install Docker Desktop** (if not installed)
60+
2. **AWS CLI Setup:**
61+
```powershell
62+
# AWS CLI already installed via pip in venv
63+
.\.venv\Scripts\python.exe -m awscli configure
64+
```
5965

66+
### Manual Deployment Steps
6067
```powershell
61-
# Install AWS CLI first if not installed
62-
choco install awscli -y
68+
# Run the automated deployment script
69+
.\deploy-ecr.ps1
6370
64-
# Configure AWS
65-
aws configure
71+
# Or manual steps:
72+
# 1. Test AWS credentials
73+
.\.venv\Scripts\python.exe -m awscli sts get-caller-identity
6674
67-
# Get account ID
68-
$AWS_ACCOUNT_ID = aws sts get-caller-identity --query Account --output text
75+
# 2. Create ECR repository
76+
.\.venv\Scripts\python.exe -m awscli ecr create-repository --repository-name permit-api --region ap-southeast-2
6977
70-
# Login to ECR (after Docker is installed)
71-
aws ecr get-login-password --region ap-southeast-2 | docker login --username AWS --password-stdin "$AWS_ACCOUNT_ID.dkr.ecr.ap-southeast-2.amazonaws.com"
78+
# 3. Get ECR login
79+
$AWS_ACCOUNT_ID = (.\.venv\Scripts\python.exe -m awscli sts get-caller-identity --query Account --output text)
80+
$LOGIN_PASSWORD = (.\.venv\Scripts\python.exe -m awscli ecr get-login-password --region ap-southeast-2)
81+
echo $LOGIN_PASSWORD | docker login --username AWS --password-stdin "$AWS_ACCOUNT_ID.dkr.ecr.ap-southeast-2.amazonaws.com"
7282
73-
# Build and push (after Docker is ready)
83+
# 4. Build and push
7484
docker build -f Dockerfile.apprunner -t permit-api .
7585
docker tag permit-api "$AWS_ACCOUNT_ID.dkr.ecr.ap-southeast-2.amazonaws.com/permit-api:latest"
7686
docker push "$AWS_ACCOUNT_ID.dkr.ecr.ap-southeast-2.amazonaws.com/permit-api:latest"

deploy-ecr.ps1

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# PowerShell script for ECR deployment (Windows)
2+
param(
3+
[string]$AWSRegion = "ap-southeast-2",
4+
[string]$ECRRepository = "permit-api",
5+
[string]$ImageTag = "latest"
6+
)
7+
8+
Write-Host "🔐 AWS CLI ECR Deployment Script" -ForegroundColor Green
9+
Write-Host "Region: $AWSRegion" -ForegroundColor Yellow
10+
11+
# Use AWS CLI from venv
12+
$AWS_CMD = ".\.venv\Scripts\python.exe -m awscli"
13+
14+
# Test AWS credentials
15+
Write-Host "🔍 Testing AWS credentials..." -ForegroundColor Cyan
16+
try {
17+
$AccountOutput = & cmd /c "$AWS_CMD sts get-caller-identity 2>nul"
18+
if ($LASTEXITCODE -eq 0) {
19+
$AccountInfo = $AccountOutput | ConvertFrom-Json
20+
$AWSAccountID = $AccountInfo.Account
21+
Write-Host "✅ AWS Account: $AWSAccountID" -ForegroundColor Green
22+
} else {
23+
throw "AWS credentials test failed"
24+
}
25+
}
26+
catch {
27+
Write-Host "❌ AWS CLI not configured or credentials invalid" -ForegroundColor Red
28+
Write-Host "Please run: .\.venv\Scripts\python.exe -m awscli configure" -ForegroundColor Yellow
29+
Write-Host "Make sure to use fresh AWS Access Keys!" -ForegroundColor Yellow
30+
exit 1
31+
}
32+
33+
# Check if Docker is available
34+
Write-Host "🐳 Checking Docker..." -ForegroundColor Cyan
35+
try {
36+
docker --version | Out-Null
37+
if ($LASTEXITCODE -eq 0) {
38+
Write-Host "✅ Docker is available" -ForegroundColor Green
39+
} else {
40+
throw "Docker not found"
41+
}
42+
}
43+
catch {
44+
Write-Host "❌ Docker not installed" -ForegroundColor Red
45+
Write-Host "Please install Docker Desktop or use GitHub Actions deployment" -ForegroundColor Yellow
46+
Write-Host "GitHub Actions URL: https://github.com/hk-dev13/project-permit-api/actions" -ForegroundColor Cyan
47+
exit 1
48+
}
49+
50+
# Create ECR repository if needed
51+
Write-Host "📦 Setting up ECR repository..." -ForegroundColor Cyan
52+
$RepoCheck = & cmd /c "$AWS_CMD ecr describe-repositories --repository-names $ECRRepository --region $AWSRegion 2>nul"
53+
if ($LASTEXITCODE -ne 0) {
54+
Write-Host "Creating ECR repository: $ECRRepository" -ForegroundColor Yellow
55+
& cmd /c "$AWS_CMD ecr create-repository --repository-name $ECRRepository --region $AWSRegion"
56+
}
57+
58+
# Login to ECR
59+
Write-Host "🔐 Logging into ECR..." -ForegroundColor Cyan
60+
$LoginPassword = & cmd /c "$AWS_CMD ecr get-login-password --region $AWSRegion"
61+
if ($LASTEXITCODE -eq 0) {
62+
echo $LoginPassword | docker login --username AWS --password-stdin "$AWSAccountID.dkr.ecr.$AWSRegion.amazonaws.com"
63+
if ($LASTEXITCODE -eq 0) {
64+
Write-Host "✅ ECR login successful" -ForegroundColor Green
65+
} else {
66+
Write-Host "❌ ECR login failed" -ForegroundColor Red
67+
exit 1
68+
}
69+
} else {
70+
Write-Host "❌ Failed to get ECR login token" -ForegroundColor Red
71+
exit 1
72+
}
73+
74+
# Build Docker image
75+
Write-Host "🔨 Building Docker image..." -ForegroundColor Cyan
76+
docker build -f Dockerfile.apprunner -t "${ECRRepository}:${ImageTag}" .
77+
if ($LASTEXITCODE -ne 0) {
78+
Write-Host "❌ Docker build failed" -ForegroundColor Red
79+
exit 1
80+
}
81+
82+
# Tag and push image
83+
$ECRURI = "$AWSAccountID.dkr.ecr.$AWSRegion.amazonaws.com/${ECRRepository}:${ImageTag}"
84+
Write-Host "🏷️ Tagging image: $ECRURI" -ForegroundColor Cyan
85+
docker tag "${ECRRepository}:${ImageTag}" $ECRURI
86+
87+
Write-Host "📤 Pushing to ECR..." -ForegroundColor Cyan
88+
docker push $ECRURI
89+
90+
if ($LASTEXITCODE -eq 0) {
91+
Write-Host "" -ForegroundColor Green
92+
Write-Host "🎉 SUCCESS! Docker image pushed to ECR" -ForegroundColor Green
93+
Write-Host "" -ForegroundColor Green
94+
Write-Host "📋 Next Steps:" -ForegroundColor Yellow
95+
Write-Host "1. Go to AWS App Runner Console" -ForegroundColor White
96+
Write-Host "2. Create Service → Container Registry" -ForegroundColor White
97+
Write-Host "3. Use this ECR Image URI:" -ForegroundColor White
98+
Write-Host " $ECRURI" -ForegroundColor Cyan
99+
Write-Host "4. Set Port: 8000" -ForegroundColor White
100+
Write-Host "5. Add Environment Variables:" -ForegroundColor White
101+
Write-Host " FLASK_ENV=production" -ForegroundColor Gray
102+
Write-Host " FLASK_DEBUG=0" -ForegroundColor Gray
103+
Write-Host " PORT=8000" -ForegroundColor Gray
104+
Write-Host "" -ForegroundColor Green
105+
Write-Host "🌐 App Runner Console:" -ForegroundColor Yellow
106+
Write-Host " https://ap-southeast-2.console.aws.amazon.com/apprunner/home" -ForegroundColor Cyan
107+
} else {
108+
Write-Host "❌ Failed to push image to ECR" -ForegroundColor Red
109+
exit 1
110+
}

0 commit comments

Comments
 (0)