-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from studio-recoding/feat/cicd
feat: ci/cd 추가
- Loading branch information
Showing
2 changed files
with
73 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: CI/CD | ||
|
||
on: | ||
push: | ||
branches: [ dev ] | ||
pull_request: | ||
branches: [ main, dev ] | ||
|
||
env: | ||
DOCKER_IMAGE: ghcr.io/${{ github.actor }}/myproject | ||
VERSION: ${{ github.sha }} | ||
NAME: ness-fastapi | ||
# Docker image 를 ghcr.io 에 올릴 때 우리의github이름/이미지이름 으로 저장한다. 이미지이름을 정해주면 된다. | ||
# Docker image 의 이름을 newproject 이라고 해놓은 것. 이름 뭐할지 정하면 된다. | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup docker buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Cache docker layers | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ env.VERSION }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Login to ghcr | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GHCR_TOKEN }} | ||
|
||
- name: Build and push | ||
id: docker_build | ||
uses: docker/build-push-action@v2 | ||
with: | ||
builder: ${{ steps.buildx.outputs.name }} | ||
push: true | ||
tags: ${{ env.DOCKER_IMAGE }}:latest | ||
|
||
deploy: | ||
needs: build | ||
name: Deploy | ||
runs-on: [ self-hosted, label-NESS ] | ||
# label-newproject 라는 이름으로 AWS EC2 가 Runner 를 작동시킬 때 사용했던 그 label | ||
steps: | ||
- name: Login to ghcr | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GHCR_TOKEN }} | ||
|
||
- name: Docker run | ||
run: | | ||
docker stop ${{ env.NAME }} && docker rm ${{ env.NAME }} && docker rmi ${{ env.DOCKER_IMAGE }}:latest | ||
docker run -d -p 3000:3000 --name newproject --restart always ${{ env.DOCKER_IMAGE }}:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,19 @@ | ||
# Python 이미지를 기반으로 설정 | ||
|
||
FROM python:3.9 | ||
|
||
# 작업 디렉토리 설정 | ||
WORKDIR /app | ||
WORKDIR /code | ||
|
||
# 환경변수 설정 | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
# ENV PYTHONDONTWRITEBYTECODE 1 | ||
# ENV PYTHONUNBUFFERED 1 | ||
|
||
# 의존성 설치 | ||
COPY requirements.txt . | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# 소스 코드 복사 | ||
COPY . . | ||
|
||
# 애플리케이션 실행 | ||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] | ||
|
||
# 나의 python 버전 | ||
FROM python:3.11.1 | ||
|
||
# /code 폴더 만들기 | ||
WORKDIR /code | ||
|
||
# ./requirements.txt 를 /code/requirements.txt 로 복사 | ||
COPY ./requirements.txt /code/requirements.txt | ||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt | ||
|
||
# requirements.txt 를 보고 모듈 전체 설치(-r) | ||
RUN pip install --no-cache-dir -r /code/requirements.txt | ||
|
||
# 이제 app 에 있는 파일들을 /code/app 에 복사 | ||
# 소스 코드 복사 | ||
COPY ./app /code/app | ||
|
||
# 실행 | ||
# 어플리케이션 실행 | ||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] |