Merge pull request #25 from next-engineer/dev #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to Amazon ECR & EC2 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| env: | |
| AWS_REGION: ap-northeast-2 | |
| ECR_REPOSITORY: intune-chat-repo | |
| CONTAINER_NAME: intune-chat | |
| EC2_INSTANCE_IDS: "i-08100c71ecc821618,i-07ee03b6f1f176e41" | |
| DOCKER_RUN_ARGS: >- | |
| -p 8081:8081 | |
| --restart unless-stopped | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| environment: production | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a | |
| - id: build-image | |
| run: | | |
| bash scripts/build_and_push.sh \ | |
| "${{ steps.login-ecr.outputs.registry }}" \ | |
| "${{ env.ECR_REPOSITORY }}" \ | |
| "${{ github.sha }}" | |
| - id: ssm-deploy | |
| run: | | |
| IMAGE_URI=${{ steps.build-image.outputs.image }} | |
| TARGETS_JSON=$(jq -n --arg ids "${{ env.EC2_INSTANCE_IDS }}" ' | |
| {Key:"InstanceIds", Values: ($ids | split(","))} | |
| ' | jq -s .) | |
| PARAMS_JSON=$(bash scripts/make_ssm_params.sh \ | |
| "${{ env.AWS_REGION }}" \ | |
| "${{ steps.login-ecr.outputs.registry }}" \ | |
| "$IMAGE_URI" \ | |
| "${{ env.CONTAINER_NAME }}" \ | |
| "${{ env.DOCKER_RUN_ARGS }}") | |
| aws ssm send-command \ | |
| --document-name "AWS-RunShellScript" \ | |
| --comment "Deploy new container" \ | |
| --targets "$TARGETS_JSON" \ | |
| --parameters "$PARAMS_JSON" \ | |
| --region "${{ env.AWS_REGION }}" \ | |
| --output json > send-command.json | |
| COMMAND_ID=$(jq -r '.Command.CommandId' send-command.json) | |
| echo "command-id=$COMMAND_ID" >> "$GITHUB_OUTPUT" | |
| - run: | | |
| bash scripts/wait_ssm.sh \ | |
| "${{ env.AWS_REGION }}" \ | |
| "${{ steps.ssm-deploy.outputs.command-id }}" |