|
| 1 | +# PowerShell script for Docker deployment to AWS App Runner |
| 2 | +param( |
| 3 | + [string]$AWSRegion = "ap-southeast-2", |
| 4 | + [string]$ECRRepository = "permit-api", |
| 5 | + [string]$ImageTag = "latest" |
| 6 | +) |
| 7 | + |
| 8 | +Write-Host "🚀 Building and deploying Permit API to AWS App Runner via ECR" -ForegroundColor Green |
| 9 | +Write-Host "Region: $AWSRegion" -ForegroundColor Yellow |
| 10 | +Write-Host "Repository: $ECRRepository" -ForegroundColor Yellow |
| 11 | + |
| 12 | +# Get AWS Account ID |
| 13 | +try { |
| 14 | + $AWSAccountID = aws sts get-caller-identity --query Account --output text 2>$null |
| 15 | + if ($LASTEXITCODE -ne 0) { throw } |
| 16 | + Write-Host "Account: $AWSAccountID" -ForegroundColor Yellow |
| 17 | +} |
| 18 | +catch { |
| 19 | + Write-Host "❌ AWS CLI not configured or not authenticated" -ForegroundColor Red |
| 20 | + Write-Host "Please run: aws configure" -ForegroundColor Yellow |
| 21 | + exit 1 |
| 22 | +} |
| 23 | + |
| 24 | +# Create ECR repository if it doesn't exist |
| 25 | +Write-Host "📦 Creating ECR repository..." -ForegroundColor Cyan |
| 26 | +$repoExists = aws ecr describe-repositories --repository-names $ECRRepository --region $AWSRegion 2>$null |
| 27 | +if ($LASTEXITCODE -ne 0) { |
| 28 | + aws ecr create-repository --repository-name $ECRRepository --region $AWSRegion |
| 29 | +} |
| 30 | + |
| 31 | +# Get ECR login token |
| 32 | +Write-Host "🔐 Authenticating Docker with ECR..." -ForegroundColor Cyan |
| 33 | +$loginPassword = aws ecr get-login-password --region $AWSRegion |
| 34 | +if ($LASTEXITCODE -eq 0) { |
| 35 | + echo $loginPassword | docker login --username AWS --password-stdin "$AWSAccountID.dkr.ecr.$AWSRegion.amazonaws.com" |
| 36 | +} |
| 37 | + |
| 38 | +# Build Docker image |
| 39 | +Write-Host "🔨 Building Docker image..." -ForegroundColor Cyan |
| 40 | +docker build -f Dockerfile.apprunner -t "${ECRRepository}:${ImageTag}" . |
| 41 | + |
| 42 | +if ($LASTEXITCODE -ne 0) { |
| 43 | + Write-Host "❌ Docker build failed" -ForegroundColor Red |
| 44 | + exit 1 |
| 45 | +} |
| 46 | + |
| 47 | +# Tag image for ECR |
| 48 | +$ECRURI = "$AWSAccountID.dkr.ecr.$AWSRegion.amazonaws.com/${ECRRepository}:${ImageTag}" |
| 49 | +docker tag "${ECRRepository}:${ImageTag}" $ECRURI |
| 50 | + |
| 51 | +# Push to ECR |
| 52 | +Write-Host "📤 Pushing image to ECR..." -ForegroundColor Cyan |
| 53 | +docker push $ECRURI |
| 54 | + |
| 55 | +if ($LASTEXITCODE -eq 0) { |
| 56 | + Write-Host "✅ Docker image pushed successfully!" -ForegroundColor Green |
| 57 | + Write-Host "ECR URI: $ECRURI" -ForegroundColor Yellow |
| 58 | + Write-Host "" |
| 59 | + Write-Host "Next steps:" -ForegroundColor Green |
| 60 | + Write-Host "1. Go to AWS App Runner console" -ForegroundColor White |
| 61 | + Write-Host "2. Choose 'Container registry' as source" -ForegroundColor White |
| 62 | + Write-Host "3. Use this image URI: $ECRURI" -ForegroundColor Cyan |
| 63 | + Write-Host "4. Configure service settings" -ForegroundColor White |
| 64 | +} else { |
| 65 | + Write-Host "❌ Docker push failed" -ForegroundColor Red |
| 66 | + exit 1 |
| 67 | +} |
0 commit comments