From f337f6c1c6bfa0770beb96475fe75cab16e43237 Mon Sep 17 00:00:00 2001 From: sycuuui <102959791+sycuuui@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:08:51 +0900 Subject: [PATCH] =?UTF-8?q?chore=20:=20ci/cd=20=EA=B5=AC=EC=B6=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit docker,ec2배포까지 완료 --- .github/workflows/github-actions.yml | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/github-actions.yml diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml new file mode 100644 index 0000000..2c5e016 --- /dev/null +++ b/.github/workflows/github-actions.yml @@ -0,0 +1,54 @@ +name: CI/CD using GitHub Actions & Docker + +on: + push: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + CI-CD: + runs-on: ubuntu-latest + steps: + + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ' 3.11.6' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + # application.yml 파일 생성 + - name: make application.yml + if: | + contains(github.ref, 'main') || + contains(github.ref, 'develop') + run: | + mkdir -p ./config # config 폴더 생성 + echo "${{ secrets.YML }}" > ./config/application.yml # GitHub Secrets에서 설정한 값을 application.yml 파일에 쓰기 + + # Docker 빌드 & 푸시 + - name: Docker build & push + if: github.ref == 'refs/heads/main' # 메인 브랜치에 푸시했을 때만 실행 + run: | + docker build -t capic/capic . + docker push capic/capic + + # EC2로 배포 + - name: Deploy to EC2 + if: github.ref == 'refs/heads/main' # 메인 브랜치에 푸시했을 때만 실행 + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS + username: ubuntu + key: ${{ secrets.PRIVATE_KEY }} + script: | + sudo docker pull capic/capic + sudo docker run -d -p 5000:5000 capic/capic