Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env/#13 #40

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Django CD # workflow 이름
on: # Event
pull_request:
types:
- closed
branches: [ main ]

jobs: # Job
cd: # Job 이름
if: github.event.pull_request.merged == true # Job 실행 조건

runs-on: ubuntu-latest # Runner

steps: # Step

# ssh를 통해 EC2에 접속, 접속한 후에 실행할 스크립트 작성
- name: Connect to EC2 using SSH
uses: appleboy/ssh-action@master
with:
host: ${{secrets.AWS_HOST}}
username: ${{secrets.AWS_USERNAME}}
key: ${{ secrets.AWS_KEY_PEM }}
envs: GITHUB_SHA
script: |
cd docker
git pull
sudo docker-compose down
sudo docker-compose pull
sudo docker-compose up -d --build
85 changes: 85 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Django CI # workflow 이름

on: # Event
push:
branches:
- main
pull_request:
branches:
- main

jobs: # Job
ci: # Job 이름
runs-on: ubuntu-latest # Runner

services: # 컨테이너, docker-compose 설정과 거의 유사
db:
image: mysql:latest
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }} # github에 등록한 환경변수
MYSQL_DATABASE: ${{ secrets.MYSQL_DATABASE }}
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps: # Step
# 레포지토리의 소스 코드를 체크아웃하여 작업 디렉토리로 가져오는 action
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true # 서브모듈 체크아웃 추가


# mysql 컨테이너 연결 확인
- name: Verify MySQL connection
run: |
mysql --version
mysql --host 127.0.0.1 --port 3306 -u root -p${{ secrets.MYSQL_ROOT_PASSWORD }}

# 파이썬 3.11.0 버전 설치
- name: Set up Python 3.11.0
uses: actions/setup-python@v2
with:
python-version: 3.11.0

# .env 생성
- name: Setting .env
run: |
echo "${{ secrets.ENV }}" >> .env
cat .env

# 의존성 설치
- name: Install Dependencies
run: |
cd backend
python -m pip install --upgrade pip
pip install -r requirements.txt

# mysql 컨테이너에 migration, 테이블 생성
- name: Run migrations
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: root
DB_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
DB_HOST: 127.0.0.1
DB_PORT: ${{ secrets.DB_PORT }}

run: |
cd backend
python manage.py makemigrations
python manage.py migrate

# 테스트 진행
- name: Run Tests
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: root
DB_PASSWORD: '${{ secrets.MYSQL_ROOT_PASSWORD }}'
DB_HOST: 127.0.0.1
DB_PORT: ${{ secrets.DB_PORT }}
run: |
cd backend
mysql --host 127.0.0.1 --port 3306 -u ${{ secrets.DB_USER }} -p ${{ secrets.DB_PASSWORD }}
python manage.py test
6 changes: 2 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ services:
- 3000:3000
volumes:
- grafana-data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_USER=admin # grafana 사용자 이름
- GF_SECURITY_ADMIN_PASSWORD=admin # grafana 사용자 비밀번호
- GF_USERS_ALLOW_SIGN_UP=false
env_file:
- .env
networks:
- app-tier

Expand Down
Loading