Website: https://airproject.xyz
- Django 3
- Django Channels
- DRF
- Postgres
- Celery
- Redis
Docker containers:
- nginx
- db
- redis
- daphne
- server
- celery
- flower
- celery_beat
docker-compose files:
docker-compose-local.yml
- for local developmentdocker-compose-master.yml
- for production
Swarm stack files:
stack-prod.yml
- for production
To run docker containers you have to create a .env
file in the root directory.
Example of .env
file:
ENV=.env
# Python
PYTHONUNBUFFERED=
# Project
ENVIRONMENT=<local|test|prod>
DJANGO_SETTINGS_MODULE=<airbnb.settings.local|airbnb.settings.pro>
PROJECT_ALLOWED_HOSTS=<host1,host2>
PROJECT_ADMIN_EMAIL=<admin@email.com>
PROJECT_FULL_DOMAIN=<http://127.0.0.1>
SITE_DEFAULT_PROTOCOL=<http>
# Yandex Object Storage
USE_S3_BUCKET=<0|1>
YANDEX_STORAGE_BUCKET_NAME=
YANDEX_STORAGE_ACCESS_KEY_ID=
YANDEX_STORAGE_SECRET_ACCESS_KEY=
# Media & staticfiles
MEDIA_URL=
STATIC_URL=
# Emails
EMAIL_HOST_USER_ESL=<email@username>
EMAIL_HOST_PASSWORD_ESL=<email.password>
# Postgres
POSTGRES_DEFAULT_USER=
POSTGRES_DEFAULT_PASSWORD=
POSTGRES_DB=
POSTGRES_HOST=<db>
POSTGRES_PORT=
# Prod
POSTGRES_PROD_USER=
POSTGRES_PROD_PASSWORD=
POSTGRES_PROD_DB=
# Yandex.Cloud Managed PostgreSQL
USE_MANAGED_POSTGRES=<0|1>
POSTGRES_YANDEX_CLUSTER_NAME=
POSTGRES_YANDEX_USER=
POSTGRES_YANDEX_PASSWORD=
POSTGRES_YANDEX_DB=
POSTGRES_YANDEX_HOST=
POSTGRES_YANDEX_PORT=
POSTGRES_SSL_CERT_DOCKER_PATH=</docker/path/to/root.crt>
# Celery
CELERY_BROKER_URL=<redis://redis:6379/0>
CELERY_RESULT_BACKEND=<redis://redis:6379/0>
# Redis
REDIS_DECODE_RESPONSES=1
REDIS_PORT=6379
REDIS_URL=
AIRBNB_REDIS_HOST=<redis>
# Prod
REDIS_SSL_CERT_DOCKER_PATH=</docker/path/to/YandexInternalRootCA.crt>
REDIS_SENTINEL_HOSTS=<server-1,server-2>
REDIS_CLUSTER_NAME=
REDIS_CLUSTER_PASSWORD=
# Redis DBs
REDIS_CACHE_DB=
REDIS_MAIN_DB=
REDIS_SESSION_DB=
CELERY_REDIS_DB=
REDIS_CHANNELS_DB=
# Channels
REDIS_CHANNELS_URL=
# Twilio
TWILIO_ACCOUNT_SID=
TWILIO_AUTH_TOKEN=
TWILIO_PHONE_NUMBER=
# Sentry
AIRBNB_SENTRY_DSN=
# Flower
FLOWER_PORT=
# Traefik - optional
TRAEFIK_PILOT_TOKEN=
TRAEFIK_DASHBOARD_USER_CREDENTIALS=
# DOCKER HUB / CI - optional
DOCKER_HUB_USERNAME=<dockerhub-username>
DOCKER_HUB_PASSWORD=<dockerhub-password>
CI_COMMIT_SHORT_SHA=<latest>
Local:
docker-compose -f docker-compose-local.yml build
docker-compose -f docker-compose-local.yml run --rm server sh -c "cd airbnb_app && ./manage.py migrate && ./manage.py populate_db"
docker-compose -f docker-compose-local.yml up
Production docker-compose:
- Create ./config/nginx/certs/ folder (in the repository root)
- Add ssl files:
- airproject.crt: ssl certificate
- airproject.key: private key
- ca.crt: root certificate
- Run docker containers
docker-compose -f docker-compose-master.yml build
docker-compose -f docker-compose-master.yml up
Production Swarm:
- Create ./config/nginx/certs/ folder (in the repository root)
- Add ssl files:
- airproject.crt: ssl certificate
- airproject.key: private key
- ca.crt: root certificate
- Build and push your image to the Docker Hub
- Deploy Swarm stack
env $(cat .env | grep ^[A-Z] | xargs) docker stack deploy -c stack-prod.yml airbnb_app --with-registry-auth
Migrations will be applied automatically.
Before pushing a commit run all linters:
docker-compose -f docker-compose-local.yml run --rm server sh -c "make check"
You also have to add a makefile.env
file (for pre-commit):
# Your docker-compose file name
DOCKER_COMPOSE_FILENAME=<docker-compose-local.yml>
And then run linters:
make check-docker
To configure pre-commit on your local machine:
docker-compose -f docker-compose-local.yml build
docker-compose -f docker-compose-local.yml run --rm server sh -c "pre-commit install"