Skip to content

Commit

Permalink
chore : github action 닫기
Browse files Browse the repository at this point in the history
  • Loading branch information
sycuuui committed Mar 25, 2024
1 parent 371f5ed commit c2a213d
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 102 deletions.
202 changes: 101 additions & 101 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -1,108 +1,108 @@
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

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11.6'

- name: Create .env file
run: |
echo "AWS_ACCESS_KEY_ID=${{secrets.AWS_ACCESS_KEY}}" > .env
echo "AWS_SECRET_ACCESS_KEY=${{secrets.AWS_SECRET_KEY}}" >> .env
echo "BUCKET_NAME=${{secrets.BUCKET_NAME}}" >> .env
echo "REGION_NAME=${{secrets.REGION_NAME}}" >> .env
echo "DOCKERHUB_NAME=${{secrets.DOCKERHUB_NAME}}" >> .env
echo "DOCKERHUB_REPOSITORY=${{secrets.DOCKERHUB_REPOSITORY}}" >> .env
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# Docker 빌드 & 푸시
- name: Docker build & push
if: github.ref == 'refs/heads/main'
run: |
docker login -u ${{ secrets.DOCKERHUB_NAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
docker build -t ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest .
docker push ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest
# Docker-compose 파일 및 .env 파일 EC2로 전송
- name: SCP docker-compose file to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
source: "docker-compose.yml"
target: "/home/ubuntu/server-flask"
port: 22

- name: SCP image file to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
source: "dd.jpeg"
target: "/home/ubuntu/server-flask"
port: 22

- name: SCP .env file to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
source: ".env"
target: "/home/ubuntu/server-flask"
port: 22

# EC2에서 Docker Compose를 사용한 서비스 재시작
- name: Restart services using docker-compose on EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
script: |
cd /home/ubuntu/server-flask
sudo docker login -u ${{ secrets.DOCKERHUB_NAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
sudo docker-compose down
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-compose pull
sudo docker-compose up -d
port: 22

# # EC2로 배포
# - name: Deploy to EC2
# if: github.ref == 'refs/heads/main' # 메인 브랜치에 푸시했을 때만 실행
#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
#
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v2
#
# - name: Set up Python
# uses: actions/setup-python@v2
# with:
# python-version: '3.11.6'
#
# - name: Create .env file
# run: |
# echo "AWS_ACCESS_KEY_ID=${{secrets.AWS_ACCESS_KEY}}" > .env
# echo "AWS_SECRET_ACCESS_KEY=${{secrets.AWS_SECRET_KEY}}" >> .env
# echo "BUCKET_NAME=${{secrets.BUCKET_NAME}}" >> .env
# echo "REGION_NAME=${{secrets.REGION_NAME}}" >> .env
# echo "DOCKERHUB_NAME=${{secrets.DOCKERHUB_NAME}}" >> .env
# echo "DOCKERHUB_REPOSITORY=${{secrets.DOCKERHUB_REPOSITORY}}" >> .env
#
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# pip install -r requirements.txt
#
# # Docker 빌드 & 푸시
# - name: Docker build & push
# if: github.ref == 'refs/heads/main'
# run: |
# docker login -u ${{ secrets.DOCKERHUB_NAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
# docker build -t ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest .
# docker push ${{ secrets.DOCKERHUB_NAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest
#
# # Docker-compose 파일 및 .env 파일 EC2로 전송
# - name: SCP docker-compose file to EC2
# uses: appleboy/scp-action@master
# with:
# host: ${{ secrets.HOST_PROD }}
# username: ubuntu
# key: ${{ secrets.PRIVATE_KEY }}
# source: "docker-compose.yml"
# target: "/home/ubuntu/server-flask"
# port: 22
#
# - name: SCP image file to EC2
# uses: appleboy/scp-action@master
# with:
# host: ${{ secrets.HOST_PROD }}
# username: ubuntu
# key: ${{ secrets.PRIVATE_KEY }}
# source: "dd.jpeg"
# target: "/home/ubuntu/server-flask"
# port: 22
#
# - name: SCP .env file to EC2
# uses: appleboy/scp-action@master
# with:
# host: ${{ secrets.HOST_PROD }}
# username: ubuntu
# key: ${{ secrets.PRIVATE_KEY }}
# source: ".env"
# target: "/home/ubuntu/server-flask"
# port: 22
#
# # EC2에서 Docker Compose를 사용한 서비스 재시작
# - name: Restart services using docker-compose on EC2
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS
# host: ${{ secrets.HOST_PROD }}
# username: ubuntu
# key: ${{ secrets.PRIVATE_KEY }}
# script: |
# cd /home/ubuntu/server-flask
# sudo docker login -u ${{ secrets.DOCKERHUB_NAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
# sudo docker-compose down
# 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}}

# sudo docker-compose pull
# sudo docker-compose up -d
# port: 22
#
## # 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 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}}
#
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c2a213d

Please sign in to comment.