set: cd test #3
Workflow file for this run
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: Django CD # workflow 이름 | |
on: # Event | |
pull_request: | |
types: | |
- closed | |
branches: [ develop ] | |
jobs: # Job | |
cd: # Job 이름 | |
if: github.event.pull_request.merged == true # Job 실행 조건 | |
runs-on: ubuntu-latest # Runner | |
steps: # Step | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Set up Python 3.9 | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.9 | |
# 라이브러리 설치 | |
- name: Install Dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
# 도커 허브 사용을 위해 도커에 로그인 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} # 도커 홈페이지에서 발급받은 토큰 사용 | |
# 이미지 빌드를 위해 .env 생성 | |
- name: Setting .env | |
run: | | |
echo "${{ secrets.ENV }}" >> .env | |
cat .env | |
# docker-compose에서 사용하는 이미지들을 build, 공식 이미지들은 x | |
- name: Build docker images | |
run: | | |
docker-compose -f docker-compose.yml -f docker-compose.monitoring.yml build | |
docker images | |
# docker hub repository에 이미지들을 push | |
- name: Push docker images | |
run: docker-compose -f docker-compose.yml -f docker-compose.monitoring.yml push | |
# ssh를 통해 EC2에 접속, 접속한 후에 실행할 스크립트 작성 | |
- name: Connect to EC2 using SSH | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{secrets.AWS_HOST}} | |
username: ${{secrets.AWS_USERNAME}} | |
password: ${{ secrets.PASSWD }} | |
key: ${{ secrets.AWS_KEY_PEM }} | |
envs: GITHUB_SHA | |
script: | | |
cd github-actions-session | |
git pull | |
sudo docker-compose -f docker-compose.yml -f docker-compose.monitoring.yml down | |
sudo docker-compose -f docker-compose.yml -f docker-compose.monitoring.yml pull | |
sudo docker-compose -f docker-compose.yml -f docker-compose.monitoring.yml up -d --build |