Skip to content

chore: version packages (#118) #10

chore: version packages (#118)

chore: version packages (#118) #10

name: Deploy Gateway
on:
push:
branches: [main]
paths:
- "gateway/**"
- "packages/agent-world-sdk/**"
workflow_dispatch:
concurrency:
group: deploy-gateway
cancel-in-progress: true
permissions:
id-token: write
contents: read
jobs:
deploy:
name: Build & Deploy Gateway
runs-on: ubuntu-latest
env:
ECR_REPOSITORY: awn-gateway
INSTANCE_ID: i-04670f4d1a72c7d5d
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
aws-region: us-east-2
- name: Login to Amazon ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@v2
- name: Build & push Docker image
env:
REGISTRY: ${{ steps.ecr-login.outputs.registry }}
run: |
IMAGE="$REGISTRY/$ECR_REPOSITORY"
docker build -f gateway/Dockerfile -t "$IMAGE:${{ github.sha }}" -t "$IMAGE:latest" .
docker push "$IMAGE:${{ github.sha }}"
docker push "$IMAGE:latest"
- name: Deploy via SSM
env:
REGISTRY: ${{ steps.ecr-login.outputs.registry }}
run: |
IMAGE="$REGISTRY/$ECR_REPOSITORY:${{ github.sha }}"
# Build SSM parameters via jq to avoid quoting issues.
# The instance role has ecr-pull permissions, so we use the ECR
# credential helper for authentication instead of the aws CLI.
PARAMS=$(jq -cn \
--arg pull "docker pull $IMAGE" \
--arg run "docker run -d --name awn-gateway --restart unless-stopped -p 8099:8099 -p 8100:8100 -v /opt/awn-gateway/data:/data -e PEER_PORT=8099 -e HTTP_PORT=8100 -e DATA_DIR=/data $IMAGE" \
'{commands: [
"command -v amazon-ecr-credential-helper >/dev/null 2>&1 || apt-get install -y amazon-ecr-credential-helper",
"mkdir -p /root/.docker && printf '"'"'{\"credsStore\":\"ecr-login\"}'"'"' > /root/.docker/config.json",
$pull,
"docker stop awn-gateway 2>/dev/null || true",
"docker rm awn-gateway 2>/dev/null || true",
"fuser -k 8099/tcp 2>/dev/null || true",
"fuser -k 8100/tcp 2>/dev/null || true",
$run
]}')
COMMAND_ID=$(aws ssm send-command \
--instance-ids "$INSTANCE_ID" \
--document-name "AWS-RunShellScript" \
--parameters "$PARAMS" \
--region us-east-2 \
--query "Command.CommandId" \
--output text)
echo "SSM Command ID: $COMMAND_ID"
sleep 5
for i in $(seq 1 30); do
if STATUS=$(aws ssm get-command-invocation \
--command-id "$COMMAND_ID" \
--instance-id "$INSTANCE_ID" \
--region us-east-2 \
--query "Status" \
--output text 2>&1); then
echo "Attempt $i: Status=$STATUS"
if [ "$STATUS" = "Success" ]; then
echo "Deploy command succeeded"
exit 0
elif [ "$STATUS" = "Failed" ] || [ "$STATUS" = "Cancelled" ] || [ "$STATUS" = "TimedOut" ]; then
echo "Deploy command failed with status: $STATUS"
aws ssm get-command-invocation \
--command-id "$COMMAND_ID" \
--instance-id "$INSTANCE_ID" \
--region us-east-2 \
--query "StandardErrorContent" \
--output text
exit 1
fi
else
echo "Attempt $i: GetCommandInvocation error (will retry): $STATUS"
fi
sleep 10
done
echo "Timed out waiting for deploy command"
exit 1
- name: Health check
run: |
COMMAND_ID=$(aws ssm send-command \
--instance-ids "$INSTANCE_ID" \
--document-name "AWS-RunShellScript" \
--parameters commands='["sleep 5","curl -sf http://localhost:8100/health"]' \
--region us-east-2 \
--query "Command.CommandId" \
--output text)
sleep 15
STATUS=$(aws ssm get-command-invocation \
--command-id "$COMMAND_ID" \
--instance-id "$INSTANCE_ID" \
--region us-east-2 \
--query "Status" \
--output text)
if [ "$STATUS" = "Success" ]; then
echo "Health check passed"
else
echo "Health check failed (status: $STATUS)"
aws ssm get-command-invocation \
--command-id "$COMMAND_ID" \
--instance-id "$INSTANCE_ID" \
--region us-east-2 \
--query "StandardErrorContent" \
--output text
exit 1
fi