Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Latest commit

 

History

History
92 lines (64 loc) · 2.19 KB

File metadata and controls

92 lines (64 loc) · 2.19 KB

Deployment with Docker-Compose

Using the docker-compose of the production environment of Django-Cookie-Cutter

docker-compose -f docker-compose.production.yml run --rm django python manage.py migrate
docker-compose -f docker-compose.production.yml run --rm django python manage.py createsuperuser
docker-compose -f docker-compose.production.yml --env-file .envs/.production/.django up

Protect the staging enviroment with basic auth.

htpasswd -c compose/production/traefik/htpasswd user

Settings via .env files

mkdir -p .envs/.production/.django && mkdir .envs/.production/.postgres

Docker with systemd service

Here an example on how to deploy with Docker-Compose and systemd.

Some more details in the cookiecutter-django Docker documentation.

cd /etc/systemd/system
vim goliath-staging.service
[Unit]
Description=Goliath (Staging)
After=docker.service

[Service]
Restart=on-failure
RestartSec=5s

Type=oneshot
RemainAfterExit=yes
StandardOutput=file:/var/log/goli.log
StandardError=file:/var/log/goli_error.log

WorkingDirectory=/root/code/goliath/
ExecStart=/usr/bin/docker-compose -f docker-compose.production.yml --env-file .envs/.production/.django up -d
ExecStop=/usr/bin/docker-compose -f docker-compose.production.yml down

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable goliath-staging.service

Commands

Usefull commands

systemctl enable goliath-staging
systemctl status goliath-staging
systemctl start goliath-staging
systemctl stop goliath-staging

Deployment Script

Create a simple deployment script:

#!/usr/bin/env bash

rsync -avz --delete --exclude node_modules --exclude .git --exclude htpasswd . awlab2:~/code/goliath

ssh awlab2 "cd code/goliath && docker-compose -f docker-compose.production.yml up --detach --build && docker-compose -f docker-compose.production.yml run --rm django python manage.py migrate"

Volumnes

Create a volume (on the host) and assign the uid + guid of the user running django.

mkdir /var/goliath_media_files

chown -R 101:101 /var/goliath_media_files