-
Notifications
You must be signed in to change notification settings - Fork 0
46 lines (39 loc) · 1.69 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
name: Deploy FastAPI App to Docker Hub
on:
push:
branches:
- main # main 브랜치에 푸시될 때 실행
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# 1. GitHub 리포지토리에서 소스 코드 체크아웃
- name: Checkout repository
uses: actions/checkout@v4
# 2. Docker Hub 로그인
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# 3. Docker 이미지 빌드 및 태그 지정
- name: Build and tag Docker image
run: |
docker build -t my-fastapi-app .
docker tag my-fastapi-app ${{ secrets.DOCKERHUB_USERNAME }}/my-fastapi-app:latest
# 4. Docker Hub에 이미지 푸시
- name: Push Docker image to Docker Hub
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/my-fastapi-app:latest
# 5. SSH로 서버에 접속하여 Docker 이미지 배포
- name: Deploy to Server via SSH
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_IP }} # GitHub Secrets에서 서버 IP 가져옴
username: ${{ secrets.SERVER_USER }} # GitHub Secrets에서 사용자 이름 가져옴
key: ${{ secrets.SSH_PRIVATE_KEY }} # GitHub Secrets에서 SSH 비밀키 가져옴
port: 22
script: |
docker stop fastapi-container || true
docker rm fastapi-container || true
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/my-fastapi-app:latest
docker run -d -p 8000:8000 --name fastapi-container ${{ secrets.DOCKERHUB_USERNAME }}/my-fastapi-app:latest