django-docker
django를 Docker & Github Action으로 배포해봅시다.
환경
- docker
- docker-compose
- nginx
- gunicorn
- postgres
- python3.8
- django(>=3.0)
Docker
development
docker-compose -f docker-compose.yml up --build
- 127.0.0.1:8000 접속
docker-compose -f docker-compose.prod.yml down -v
로 종료
production 테스트
docker-compose -f docker-compose.prod.yml up --build
- 127.0.0.1 접속
docker-compose -f docker-compose.prod.yml down -v
로 종료
Deploy
- Github Action 설정 확인 (.github/workflows/deploy.yml)
- Github Secrets에 필요한 값 설정
- ENV_FILE: .env file에 들어갈 key-value 값 전체
- HOST: 배포할 remote 서버 host
- USERNAME: 배포할 remote 서버의 username ex) ubuntu
- KEY: 배포할 remote 서버로 접근 가능한 ssh key 전문
sudo sh /home/ubuntu/srv/config/scripts/deploy.sh
가 실행되고 서버 실행 완료
- 소스는 ec2 ubuntu 기준 /home/{username}/srv/로 배포됩니다
Reference
https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/
https://github.com/appleboy/ssh-action
https://github.com/marketplace/actions/rsync-deployments-action
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04
https://docs.docker.com/compose/install/