Skip to content

Commit fe8912d

Browse files
authored
Merge pull request #4 from Block-Guard/setting/#3/cicd
Setting/#3/cicd
2 parents 4e4c81c + cefdc20 commit fe8912d

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI/CD pipeline test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
10+
env:
11+
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
12+
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
13+
DOCKER_REPO: ${{ secrets.DOCKER_REPO }}
14+
AWS_HOST: ${{ secrets.AWS_HOST }}
15+
AWS_SSH_KEY: ${{ secrets.AWS_SSH_KEY }}
16+
AWS_USER: ${{ secrets.AWS_USER }}
17+
18+
19+
jobs:
20+
build-and-push:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Check out the repo
24+
uses: actions/checkout@v3
25+
26+
- name: Login to Docker Hub
27+
run: |
28+
docker login -u ${{ env.DOCKER_HUB_USERNAME }} -p ${{ env.DOCKER_HUB_ACCESS_TOKEN }}
29+
30+
- name: Build and push Docker image
31+
run: |
32+
docker build -t ${{ env.DOCKER_REPO }}:latest .
33+
docker push ${{ env.DOCKER_REPO }}:latest
34+
35+
deploy:
36+
needs: build-and-push
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Check out the repo
40+
uses: actions/checkout@v3
41+
42+
- name: EC2 Docker Deploy
43+
uses: appleboy/ssh-action@master
44+
with:
45+
host: ${{ env.AWS_HOST }}
46+
username: ${{ env.AWS_USER }}
47+
key: ${{ env.AWS_SSH_KEY }}
48+
script: |
49+
cd git-action-test/
50+
sed -i 's|image:.*|image: '"${{ env.DOCKER_REPO }}:latest"'|' docker-compose.yaml
51+
docker-compose down
52+
docker-compose pull
53+
docker-compose up -d

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# 1. 베이스 이미지로 Python 3.9 선택
2+
FROM python:3.9-slim
3+
4+
# 2. 작업 디렉토리 생성
5+
WORKDIR /app
6+
7+
# 3. 요구 사항 파일 복사
8+
COPY requirements.txt /app/
9+
10+
# 4. 의존성 설치
11+
RUN pip install --no-cache-dir -r requirements.txt
12+
13+
# 5. 애플리케이션 코드 복사
14+
COPY . /app/
15+
16+
# 6. FastAPI 서버 실행 (Uvicorn 사용)
17+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

0 commit comments

Comments
 (0)