Skip to content

Commit ec3ce03

Browse files
authored
๐Ÿ‘ท ci : CI/CD ํŒŒ์ดํ”„๋ผ์ธ ๊ตฌ์ถ•
๐Ÿ‘ท ci : CI/CD ํŒŒ์ดํ”„๋ผ์ธ ๊ตฌ์ถ•
2 parents ea6e7c3 + bd85565 commit ec3ce03

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

โ€Ž.github/workflows/cicd.ymlโ€Ž

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: CI/CD with FastAPI
2+
3+
on:
4+
pull_request:
5+
branches: ["main"]
6+
push:
7+
branches: ["main"]
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ci-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
permissions:
15+
contents: read
16+
17+
env:
18+
IMAGE: ${{ secrets.DOCKER_USERNAME }}/menu-ai
19+
20+
jobs:
21+
docker-build-push:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Login to Docker Hub
29+
uses: docker/login-action@v3
30+
with:
31+
username: ${{ secrets.DOCKER_USERNAME }}
32+
password: ${{ secrets.DOCKER_PASSWORD }}
33+
34+
- name: Build & Push Docker Image
35+
uses: docker/build-push-action@v6
36+
with:
37+
context: .
38+
file: ./Dockerfile
39+
push: true
40+
tags: |
41+
${{ env.IMAGE }}:latest
42+
${{ env.IMAGE }}:${{ github.sha }}
43+
44+
deploy:
45+
name: Deploy to Server
46+
needs: docker-build-push
47+
runs-on: ubuntu-latest
48+
if: github.ref == 'refs/heads/main'
49+
50+
steps:
51+
- name: Deploy via SSH
52+
uses: appleboy/[email protected]
53+
with:
54+
host: ${{ secrets.HOST }}
55+
username: ${{ secrets.USER }}
56+
key: ${{ secrets.PRIVATE_KEY }}
57+
script: |
58+
docker pull ${{ env.IMAGE }}:latest
59+
docker stop menu-ai || true
60+
docker rm menu-ai || true
61+
docker run -d --name menu-ai \
62+
-p 8000:8000 \
63+
-e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} \
64+
-e OPENAI_MODEL=${{ secrets.OPENAI_MODEL }} \
65+
${{ env.IMAGE }}:latest

โ€ŽDockerfileโ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt .
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
8+
COPY . .
9+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

0 commit comments

Comments
ย (0)