CD para EC2 #6
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: CD para EC2 | |
| on: | |
| workflow_run: | |
| workflows: ["CI - Testes e Qualidade"] | |
| types: | |
| - completed | |
| jobs: | |
| deploy: | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write # <-- ESSENCIAL para push no GHCR | |
| steps: | |
| - name: Checkout do código | |
| uses: actions/checkout@v4 | |
| - name: Login No GHCR | |
| run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| - name: Build Da Imagem | |
| run: | | |
| docker build -t ghcr.io/leayxz/clark:latest . | |
| - name: Push Da Imagem | |
| run: | | |
| docker push ghcr.io/leayxz/clark:latest | |
| - name: Deploy Via SSH | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_KEY }} | |
| script: | | |
| cd /home/ubuntu/clark | |
| docker pull ghcr.io/leayxz/clark:latest | |
| docker compose down | |
| docker compose up -d --force-recreate |