- Table of Contents
- Introduction
- Makefile
- Django App Dockerfile
- Nginx Dockerfile
- Docker Compose
- Core Django Settings
- For Development
- For Production
- Default Credentials for Django Admin
- Deploy on A Real Server
- Backup
- CI & CD with GitHub Actions
I created this repo to easily dockerize Django apps. In this repo, I have my own config set-up to seperate prod and dev environments. Also, I have my pre-built docker-compose.yml
to easily deploy my projects. You can create a Django app inside this directory to use this boilerplate. I have also published two articles about this repo. You can read them by following the links below.
- A Boilerplate to Easily Dockerize and Deploy Django Apps
- A Boilerplate to Self-Hosted Continuous Delivery Django Apps (Part-2)
In Makefile I set the commands I use often.
The app's image is created by using Dockerfile.
To set-up Nginx, we use Dockerfile which is located under the nginx folder. Also, nginx.conf file is being used for proxy.
docker-compose.yml is being used for setting up the services.
I seperate the prod and dev environments. config_prod.py file is being used for prod environments and config_prod.py for dev environments. We need to implement the lines in settings.py file to use these seperated environments.
Do not forget to remove DATABASES
variable in default settings to prevent database duplication!!!
You can use dev-postgres.sh to create a development database.
docker container exec -it baysan_web /bin/bash
>>> make loaddata
username: admin
password: Passw0rd!.
Steps:
-
Create an nginx file in
/etc/nginx/sites-available
for your web project. For example:baysanproject
-
Put the content below into the file you created
server { # `listen` can be changed for your nginx service in docker-compose.yml listen 80; listen [::]:80; server_name YOUR_URL(S); server_name_in_redirect off; access_log /var/log/nginx/reverse-access.log; error_log /var/log/nginx/reverse-error.log; location / { proxy_set_header Client-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_pass http://127.0.0.1:81; # because baysan_nginx service is listening 81 port on host } }
-
Create a symbolic link
sudo ln -s /etc/nginx/sites-available/baysanproject /etc/nginx/sites-enabled
You can use backuper-db.sh to backup your database inside Docker container.
You can use backuper-web.sh to backup your django data inside Docker container.
You can create a crontab by using the command below.
sudo crontab -e
In cd.yml file, there is a simple continuous delivery workflow is coded. To use it, you have to have your own VPS.
- To activate
self-hosted
mode, you can use theSettings
tab on your repo. Then, you should goActions > General
section. Here,Allow all actions and reusable workflows
checkbox should be checked. - Now, you are able to create your own runner on your VPS. You should go
Actions > Runners
section and create a new Runner. - You should install the runner on your VPS by following the commands GitHub showed you.
- If you get an error like this
Must not be executed as ROOT
, you should deal with it by using the command below on your terminal.export RUNNER_ALLOW_RUNASROOT=1
run.sh
will start to listen, when you close your terminal or executed job, runner will not listen the further requests../svc.sh help
command will help you to understand how to run a consistent runner. You will follow the command like below../svc.sh install ./svc.sh run