Skip to content

Deploy to EC2 with GHCR #52

Deploy to EC2 with GHCR

Deploy to EC2 with GHCR #52

Workflow file for this run

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