Repository navigation
Deploy to EC2 with GHCR #52
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 EC2 with GHCR | |
| on: | |
| workflow_run: | |
| workflows: ["🏷️ Semantic Release (Versioning)"] | |
| types: | |
| - completed | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build: | |
| name: Build and Push Docker Image | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout source code | |
| uses: actions/checkout@v3 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get latest release tag | |
| id: get_tag | |
| uses: actions-ecosystem/action-get-latest-tag@v1 | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| file: ./packages/back/Dockerfile | |
| push: true | |
| tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest, ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.tag }} | |
| deploy: | |
| name: Deploy to EC2 | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Deploy with Docker Compose | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| export GEMINI_API_KEY="${{ secrets.GEMINI_API_KEY }}" | |
| sudo docker compose -f ~/docker-compose.yml pull | |
| sudo docker compose -f ~/docker-compose.yml up -d --force-recreate | |
| sudo docker image prune -f |