diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..6834686 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,51 @@ +name: Build and Deploy Backend + +on: + push: + branches: [ "main" ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: starappeal/matrix-backend + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/setup-buildx-action@v3 + - uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ghcr.io/${{ env.IMAGE_NAME }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Deploy via SSH + uses: appleboy/ssh-action@v1.2.0 + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USER }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + envs: GHCR_PAT + script: | + cd /home/matrix/ledmatrix-deployment + + docker compose -f docker-compose.yml -f docker-compose.prod.yml pull backend + + docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d + + docker image prune -f + env: + GHCR_PAT: ${{ secrets.GHCR_PAT }} \ No newline at end of file