Skip to content

Commit fbca642

Browse files
committed
Refactor AWS App Runner deployment workflow: update environment input to be required and case-sensitive, remove deprecated deploy.yml file, and enhance deployment steps with improved service checks and output handling.
1 parent c335f61 commit fbca642

2 files changed

Lines changed: 23 additions & 129 deletions

File tree

.github/workflows/deploy-apprunner.yml

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ on:
55
inputs:
66
environment:
77
description: 'Deployment environment'
8-
required: false
9-
default: 'production'
8+
required: true
9+
# PERBAIKAN: Mengubah default agar cocok dengan nama environment Anda
10+
default: 'Production'
1011
type: choice
1112
options:
12-
- production
13+
# PERBAIKAN: Mengubah opsi agar cocok
14+
- Production
1315
- staging
1416
push:
1517
branches: [ main ]
@@ -21,13 +23,15 @@ on:
2123
env:
2224
AWS_REGION: ap-southeast-2
2325
ECR_REPOSITORY: permit-api
26+
APP_RUNNER_SERVICE_NAME: permit-api-service # Nama service dijadikan variabel
2427
IMAGE_TAG: ${{ github.sha }}
2528

2629
jobs:
2730
deploy:
2831
name: Build and Deploy to App Runner
2932
runs-on: ubuntu-latest
30-
environment: Production
33+
# PERBAIKAN: Mengubah default menjadi 'Production' (P besar) agar cocok dengan environment Anda
34+
environment: ${{ github.event.inputs.environment || 'Production' }}
3135

3236
steps:
3337
- name: Checkout code
@@ -50,46 +54,32 @@ jobs:
5054
aws ecr create-repository --repository-name $ECR_REPOSITORY --region $AWS_REGION
5155
5256
- name: Build, tag, and push image to Amazon ECR
57+
id: build-image
5358
env:
5459
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
5560
run: |
56-
# Build Docker image
5761
docker build -f Dockerfile.apprunner -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
5862
docker build -f Dockerfile.apprunner -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
5963
60-
# Push to ECR
6164
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
6265
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
6366
64-
# Output image URI
65-
echo "image-uri=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
67+
echo "image_uri=$ECR_REGISTRY/$ECR_REPOSITORY:latest" >> $GITHUB_OUTPUT
6668
67-
- name: Deploy to App Runner (if service exists)
68-
env:
69-
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
69+
- name: Deploy to App Runner and wait
7070
run: |
71-
# Check if App Runner service exists
72-
SERVICE_ARN=$(aws apprunner list-services --query "ServiceSummaryList[?ServiceName=='permit-api-service'].ServiceArn | [0]" --output text --region $AWS_REGION 2>/dev/null || echo "None")
71+
SERVICE_ARN=$(aws apprunner list-services --query "ServiceSummaryList[?ServiceName=='${{ env.APP_RUNNER_SERVICE_NAME }}'].ServiceArn | [0]" --output text)
7372
74-
if [ "$SERVICE_ARN" != "None" ] && [ "$SERVICE_ARN" != "" ] && [ "$SERVICE_ARN" != "null" ]; then
75-
echo "Updating existing App Runner service..."
76-
aws apprunner start-deployment --service-arn $SERVICE_ARN --region $AWS_REGION
77-
echo "Deployment started for service: $SERVICE_ARN"
73+
if [ -n "$SERVICE_ARN" ] && [ "$SERVICE_ARN" != "None" ]; then
74+
echo "Updating existing App Runner service: $SERVICE_ARN"
75+
aws apprunner start-deployment --service-arn $SERVICE_ARN
76+
77+
# Menambahkan loop untuk menunggu deployment selesai
78+
echo "Waiting for deployment to complete..."
79+
timeout 10m aws apprunner wait service-stable --service-arn $SERVICE_ARN
80+
echo "Deployment finished successfully!"
7881
else
79-
echo "No existing App Runner service found."
80-
echo "Create service manually using image URI: $ECR_REGISTRY/$ECR_REPOSITORY:latest"
82+
echo "Service '${{ env.APP_RUNNER_SERVICE_NAME }}' not found. Please create it manually."
83+
echo "Use Image URI: ${{ steps.build-image.outputs.image_uri }}"
84+
# exit 1 # Opsional: buat job gagal jika service tidak ditemukan
8185
fi
82-
83-
- name: Output deployment info
84-
env:
85-
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
86-
run: |
87-
echo "🚀 Deployment completed!"
88-
echo "📦 Docker Image: $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
89-
echo "🔗 Use this image URI in App Runner console:"
90-
echo " $ECR_REGISTRY/$ECR_REPOSITORY:latest"
91-
echo ""
92-
echo "📋 Next steps:"
93-
echo "1. Go to AWS App Runner console"
94-
echo "2. Create service with Container Registry source"
95-
echo "3. Use image URI: $ECR_REGISTRY/$ECR_REPOSITORY:latest"

.github/workflows/deploy.yml

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)