프로젝트 로그/테스트x솔루션 JIG 개발기
[Github Action] Github Action을 이용하여 간단한 배포 자동화 구축하기 #1
Life4IoT.rnd
2022. 5. 24. 20:34
반응형
Django+Nginx+PostgreSQL 조합의 서비스를 구축하였다.
구축된 서비스를 Github Repository에 배포하고 코드가 수정 될 때마다 배포를 위한 작업을 매번 하는 것이 너무 번거로워 자동화를 위한 작업을 진행 했다.
배포 자동화를 위해서는 여러 방법이 있지만, 비용 없이 간단하게 구축하기 위해 Github Action에서 SSH로 접속하여 배포 하는 방법을 선택 하였다. ( 추후에는 AWS 서비스를 이용하여 배포 자동화로 변경할 계획 )
배포를 위한 프로젝트의 폴더 구조
| .env.prod
| 00_init-letsencrypt.sh
| 01_start_1st_install.sh
| 02_update.sh
| 03_pull_repository.sh
| docker-compose.for1stInstall.yml
| docker-compose.prod.yml
| README.md
|
+---data
| README.txt
|
+---django
| | .gitignore
| | Dockerfile.prod
| | entrypoint.prod.sh
| | LICENSE
| | manage.py
| | README.md
| | requirements.txt
| |
| +---config
| |
| +---static
| | +---css
| | +---img
| | +---js
| | \---vendor
| +---templates
| \---testxapi
| | admin.py
| | apps.py
| | constants.py
| | forms.py
| | middleware.py
| | models.py
| | tests.py
| | urls.py
| | views.py
| | __init__.py
| |
| +---api
| +---demo
| +---form
| +---utils
| \---view
|
+---nginx
| Dockerfile.prod
| Dockerfile_for1stInstall.prod
| nginx.conf
| nginx_for1stInstall.conf
|
+---postgresql
| Dockerfile.prod
| entrypoint.prod.sh
|
\---redis
Dockerfile.prod
배포를 위한 Script
Github Action에서 서비스 배포를 위한 서버에 SSH로 접속한 후, Git Pull 명령과 Docker 컨테이너를 실행하기 위한 명령을 수행한다.
본 프로젝트에서는 Git Pull을 위해 03_pull_repository.sh와 Docker 컨테이너 실행을 위해 02_update.sh 파일을 미리 만들어 두었다. Github Action에서는 03_pull_repository.sh와 02_update.sh를 순차적으로 수행한다.
03_pull_repository.sh 파일 내용
git pull
02_update.sh 파일 내용
sudo docker-compose -f docker-compose.prod.yml down
sudo docker-compose -f docker-compose.prod.yml up -d --build
Github Action으로 배포하기 위한 설정
https://kaizen8501.tistory.com/260
반응형