WAS : Python(Django)
WS : Nginx
WSGI : Gunicorn
DB : MongoDB
Container : Docker
Authentication : AWS Cognito
CI/CD : Github Action
Docker
curl -fsSL https://get.docker.com/ | sudo sh
docker-compose
sudo get-apt install docker-compose
django
# 개발 초기 단계의 docker-compose를 활용
# Dockerfile, docker-compose.yml 작성 선 진행
# 위 파일의 코드는 파일 참조
# Service name은 docker-compose 내 service name
# App name은 django에서 사용할 app name
docker-compose run <Service name> django-admin.py startproject <Project name> .
docker-compose run <Service name> django-admin.py startapp <App name> .
nginx 설정 후 Project folder의 settings.py에서 다음 설정 추가
# settings.py
...
ALLOWED_HOSTS = ['web'] # nginx에서 설정한 service name
...
static file을 한 곳에 몰아주는 설정 추가
python
# settings.py
...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
...
bash
python3 manage.py collectstatic
nginx
# project folder 하위의 특정 위치(여기선 config/nginx)에 nginx.conf 작성
# docker-compose.yml에 volume에서 nginx.conf 파일이 작성된 위치 mount
# wwwroot는 Dockerfile 작성 시 root 폴더
services:
...
nginx:
...
volumes:
- .:/wwwroot
- ./config/nginx:/etc/nginx/conf.d
# static file 관리를 위해 django의 static file이 모인 폴더 위치 설정
# static_root는 django collectstatic 시 설정한 폴더 이름
server {
...
location /static/ {
alias /wwwroot/static_root/;
}
}
gunicorn
# requirements.txt에 gunicorn 추가 필수
# 구동은 docker-compose.yml에 작성
services:
...
web: # Service name
...
command: gunicorn was.wsgi:application --bind 0.0.0.0:8000 # was는 django의 project name