Skip to content

Merge pull request #10 from Myaongi/feature/#9 #1

Merge pull request #10 from Myaongi/feature/#9

Merge pull request #10 from Myaongi/feature/#9 #1

Workflow file for this run

name: Deploy To VM on GCP
on:
push:
branches:
- develop
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create config.py
run: |
echo "${{ secrets.CONFIG_PY }}" > app/domain/config.py
echo "config.py created from GitHub Secret"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker image
run: |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/gangajikimi-ai:latest .
- name: Push Docker image to Docker Hub
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/gangajikimi-ai:latest
- name: Deploy to VM
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.VM_HOST }}
username: ${{ secrets.VM_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
# 기존 컨테이너 중지 및 제거 (있을 경우)
docker stop gangajikimi-api || true
docker rm gangajikimi-api || true
# 최신 이미지 pull
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/gangajikimi-ai:latest
# 새 컨테이너 실행
docker run -d \
--name gangajikimi-api \
--restart unless-stopped \
-p 8000:8000 \
${{ secrets.DOCKERHUB_USERNAME }}/gangajikimi-ai:latest