fix : flask #100
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
name: CI/CD using GitHub Actions & Docker | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
CI-CD: | |
runs-on: ubuntu-latest | |
env: | |
BUCKET_NAME: ${{ secrets.BUCKET_NAME }} | |
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} | |
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }} | |
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 login -u ${{ secrets.DOCKERHUB_NAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
docker system prune | |
docker volume prune | |
docker volume ls | |
docker system df | |
docker build -t ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest . | |
docker push ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest | |
docker images | |
# 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: | | |
docker system prune -a -f | |
sudo docker stop $(sudo docker ps -aqf "name=${{ secrets.DOCKERHUB_REPOSITORY }}") || true | |
sudo docker rm $(sudo docker ps -aqf "name=${{ secrets.DOCKERHUB_REPOSITORY }}") || true | |
sudo docker pull ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} | |
sudo docker run -d -p 5000:5000 --name ${{ secrets.DOCKERHUB_REPOSITORY }} ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} |