Skip to content

fix(*): remove the github shagst #2

fix(*): remove the github shagst

fix(*): remove the github shagst #2

name: Deploy Kaapi staging to EC2
on:
push:
branches: [feat/staging-deployment-ec2]
workflow_dispatch:
concurrency:
group: staging-ec2-deploy
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
environment: AWS_STAGING_ENV_VARS
permissions:
id-token: write
contents: read
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ vars.STAGING_EC2_DEPLOY_ROLE_ARN }}
aws-region: ap-south-1
- name: Trigger deploy on EC2 via SSM
id: ssm
env:
INSTANCE_ID: ${{ vars.STAGING_EC2_INSTANCE_ID }}
run: |
CMD_ID=$(aws ssm send-command \
--instance-ids "$INSTANCE_ID" \
--document-name "AWS-RunShellScript" \
--comment "Deploy kaapi-backend kaapi-staging" \
--parameters commands='["set -eux","sudo -iu ubuntu bash -lc \"cd /data/kaapi-backend && git fetch --all && git pull origin main && docker compose build && docker compose run --rm backend uv run alembic upgrade head && docker compose up -d --remove-orphans && docker image prune -f\""]' \
--cloud-watch-output-config CloudWatchOutputEnabled=true \
--query "Command.CommandId" --output text)
echo "cmd_id=$CMD_ID" >> "$GITHUB_OUTPUT"
echo "Sent SSM command: $CMD_ID"
- name: Wait for SSM command to finish
env:
INSTANCE_ID: ${{ vars.STAGING_EC2_INSTANCE_ID }}
CMD_ID: ${{ steps.ssm.outputs.cmd_id }}
run: |
aws ssm wait command-executed \
--command-id "$CMD_ID" \
--instance-id "$INSTANCE_ID"
aws ssm get-command-invocation \
--command-id "$CMD_ID" \
--instance-id "$INSTANCE_ID" \
--query '{Status:Status,Stdout:StandardOutputContent,Stderr:StandardErrorContent}' \
--output json