Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 40 additions & 23 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,28 @@ jobs:
echo "Green count: $GREEN_COUNT"

if [ "$BLUE_COUNT" -eq 0 ] && [ "$GREEN_COUNT" -eq 0 ]; then
ASG_COLOR="$BLUE_NAME"
ACTIVE_ASG_COLOR="$BLUE_NAME"
DELETE_ASG_COLOR="$GREEN_NAME"
elif [ "$BLUE_COUNT" -gt 0 ] && [ "$GREEN_COUNT" -eq 0 ]; then
ASG_COLOR="$GREEN_NAME"
ACTIVE_ASG_COLOR="$GREEN_NAME"
DELETE_ASG_COLOR="$BLUE_NAME"
elif [ "$GREEN_COUNT" -gt 0 ] && [ "$BLUE_COUNT" -eq 0 ]; then
ASG_COLOR="$BLUE_NAME"
ACTIVE_ASG_COLOR="$BLUE_NAME"
DELETE_ASG_COLOR="$GREEN_NAME"
else
ASG_COLOR="$BLUE_NAME"
DELETE_COLOR="$GREEN_NAME"
ACTIVE_ASG_COLOR="$BLUE_NAME"
DELETE_ASG_COLOR="$GREEN_NAME"
fi

TARGET_ASG="weplate-$ASG_COLOR-asg"
DELETE_ASG="${DELETE_COLOR:+weplate-$DELETE_COLOR-asg}"
ACTIVE_ASG="weplate-$ACTIVE_ASG_COLOR-asg"
DELETE_ASG="${DELETE_ASG_COLOR:+weplate-$DELETE_ASG_COLOR-asg}"

# Apply scaling
aws autoscaling update-auto-scaling-group \
--auto-scaling-group-name "$TARGET_ASG" \
--auto-scaling-group-name "$ACTIVE_ASG" \
--min-size 1 --max-size 1 --desired-capacity 1
aws autoscaling start-instance-refresh \
--auto-scaling-group-name "$TARGET_ASG" \
--auto-scaling-group-name "$ACTIVE_ASG" \
--strategy Rolling

# If both alive, shutdown DELETE
Expand All @@ -162,29 +165,34 @@ jobs:
--min-size 0 --max-size 0 --desired-capacity 0
fi

echo "ASG_COLOR=$ASG_COLOR" >> $GITHUB_ENV

echo "ACTIVE_ASG_COLOR=$ACTIVE_ASG_COLOR" >> $GITHUB_ENV
echo "DELETE_ASG_COLOR=$DELETE_ASG_COLOR" >> $GITHUB_ENV
- name: Wait for ALB Health Check → Switch Listener → Shutdown old ASG
run: |
TG_NAME="weplate-tg-${ASG_COLOR}"
echo "✅ [$ASG_COLOR] start"
TG_ARN=$(aws elbv2 describe-target-groups \
--names "$TG_NAME" \
DEPLOY_TG_NAME="weplate-tg-${ACTIVE_ASG_COLOR}"
CURRENT_TG_NAME="weplate-tg-${DELETE_ASG_COLOR}"

DEPLOY_TG_ARN=$(aws elbv2 describe-target-groups \
--names "$DEPLOY_TG_NAME" \
--query "TargetGroups[0].TargetGroupArn" --output text)

CURRENT_TG_ARN=$(aws elbv2 describe-target-groups \
--names "$CURRENT_TG_NAME" \
--query "TargetGroups[0].TargetGroupArn" --output text)

echo "🩺 Waiting for healthy target group: $TG_NAME"
echo "🩺 Waiting for healthy targets in: $DEPLOY_TG_NAME"

START_TIME=$(date +%s)
while true; do
STATUS=$(aws elbv2 describe-target-health \
--target-group-arn "$TG_ARN" \
--target-group-arn "$DEPLOY_TG_ARN" \
--query "TargetHealthDescriptions[].TargetHealth.State" \
--output text)

echo "Current target status: $STATUS"

if [[ "$STATUS" == "healthy" ]]; then
echo "✅ All targets healthy"
echo "✅ All targets in $DEPLOY_TG_NAME are healthy"
break
fi

Expand All @@ -198,22 +206,31 @@ jobs:
sleep 10
done

echo "🔁 Switching ALB listener to target group $TG_NAME"
echo "🔁 Switching ALB listeners"

for PORT in 80 443; do
LISTENER_ARN=$(aws elbv2 describe-listeners \
--load-balancer-arn ${{ secrets.WEPLATE_ALB_ARN }} \
--query "Listeners[?Port==\`${PORT}\`].ListenerArn" \
--output text)

echo "🔄 Modifying listener on port $PORT: $LISTENER_ARN"

echo "🔄 Port $PORT → $DEPLOY_TG_NAME"
aws elbv2 modify-listener \
--listener-arn "$LISTENER_ARN" \
--default-actions Type=forward,TargetGroupArn="$TG_ARN"
--default-actions Type=forward,TargetGroupArn="$DEPLOY_TG_ARN"
done

echo "✅ ALB listener now forwards to $TG_NAME"
LISTENER_ARN_8080=$(aws elbv2 describe-listeners \
--load-balancer-arn ${{ secrets.WEPLATE_ALB_ARN }} \
--query "Listeners[?Port==\`8080\`].ListenerArn" \
--output text)

echo "🔄 Port 8080 → $CURRENT_TG_NAME"
aws elbv2 modify-listener \
--listener-arn "$LISTENER_ARN_8080" \
--default-actions Type=forward,TargetGroupArn="$CURRENT_TG_ARN"

echo "✅ ALB listener forwarding complete"

if [ "$DELETE_ASG" != "" ]; then
echo "📦 Shutting down previous ASG: $DELETE_ASG"
Expand Down
10 changes: 0 additions & 10 deletions apps/nginx/nginx.op.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ http {
sendfile on;
keepalive_timeout 65;

server {
listen 8080;
server_name app.weplate.link;

location /ping {
default_type text/plain;
return 200 'pong';
}
}

server {
listen 80;
server_name app.weplate.link;
Expand Down
11 changes: 11 additions & 0 deletions docker-compose.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,14 @@ services:
- client-weplate
- server-api
- server-auth

nginx-health-check:
container_name: nginx-health-check
build: apps/nginx
image: $ECR_REGISTRY/weplate/nginx:$VERSION
ports:
- "8080:80"
depends_on:
- client-weplate
- server-api
- server-auth