add workflow_dispatch #1
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 Backend | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [ main ] | |
| paths: | |
| - "backend/**" | |
| permissions: | |
| id-token: write | |
| contents: read | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: arn:aws:iam::413576439231:role/GitHubActionsCodeChallengeGeneratorRole | |
| aws-region: us-east-1 | |
| - name: Login to ECR | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Build image | |
| run: | | |
| docker build -t ccg-backend ./backend | |
| - name: Tag image | |
| run: | | |
| docker tag ccg-backend:latest \ | |
| 413576439231.dkr.ecr.us-east-1.amazonaws.com/ccg-backend:latest | |
| - name: Push image | |
| run: | | |
| docker push \ | |
| 413576439231.dkr.ecr.us-east-1.amazonaws.com/ccg-backend:latest | |
| - name: Deploy on EC2 | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| docker pull 413576439231.dkr.ecr.us-east-1.amazonaws.com/ccg-backend:latest | |
| docker rm -f ccg-backend || true | |
| /usr/local/bin/ccg-backend-run.sh |