Skip to content

iraycd/django-react-starter

Repository files navigation

docker-django-webpack-starter

This is a starter project for a django app with webpack built frontend that uses docker for dev enironment.
Docker and docker-compose is all you need to develop, build & deploy, run development or production mode with a single command.

stack

python 3.5
node 5.10
Postgres 9.5
Django 1.10.5 Webpack
Stylus
Nginx
Gunicorn

get started

Get latest docker & docker-compose:
https://www.docker.com/
https://docs.docker.com/compose/

Pull seed to your project:

git init
git remote add starter https://github.com/domasx2/docker-django-webpack-starter.git
git pull starter master

Start dev server:

./bin/develop.sh

Wait for docker to set up container, then open http://localhost:8000

production mode

# build production images, create db backup & start
./bin/deploy.sh

# stop server
./bin/stop_production.sh

# start srever
./bin/start_production.sh

In prod mode sources are added to docker image rather than mounted from host. Nginx serves static files, proxy pass to gunicorn for django app. Logs in logs dir.

enable ssl

Copy your .key and .crt files to nginx/ssl and run ./bin/deploy.sh.

install dependencies

# frontend
./bin/npm.sh install [package] --save-dev

# backend
./bin/pipinstall.sh [pacakge] #will also add entry to backend/requirements.txt

backup & restore database

# create a backup in backups dir
./bin/backup.sh

# restore from a backup in backups dir (server must be stopped)
./bin/restore.sh backups/somebackup.bak

run django management commands

#dev mode
./bin/django.sh [command]

#create migration
./bin/django.sh makemigrations myapp

#prod mode
./bin/django_prod.sh [command]

#start django shell in prod mode
./bin/django_prod.sh shell

layout

bin/                          - various utility scripts

docker-compose.yml            - base docker compose config
docker-compose.overrides.yml  - development docker compose config
docker-compose.production.yml - production docker compose config

frontend/                     - frontend stuff
frontend/package.json         - npm package file with frotnend dependencies
frontend/src/js/              - javascript code
frontend/src/js/index.js      - js entry point. include other js deps here
frontend/src/style/           - stylesheets       
frontend/src/style/index.styl - stylesheet entry point. include other styl files here

backend/                      - backend stuff
backend/apps/                 - django apps
backend/conf/                 - django settings files
backend/conf/settings.py      - default config
backend/conf/settings_prod.py - production config
backend/templates/            - django global templates
backend/requirements/         - python dependencies
backend/gunicorn.conf.py      - gunicorn conf for production
backend/media/                - user uploads

logs/                         - in prod mode app, gunicorn, nginx, postgres logs go here
nginx/                        - nginx stuff for prod mode
nginx/ssl/                    - put key & cert here if you use ssl
nginx/nginx_nossl.conf        - nginx conf if no ssl is used
nginx/nginx_ssl.conf          - nginx conf for deploy with ssl

tests

For e2e tests, use app.testutils.SeleniumTestCase class it comes with chrome driver configure at self.driver. See apps.home.tests for an example.
See http://selenium-python.readthedocs.io/ for selenium driver api

#run tests
./bin/test.sh

# skip frontend build (eg, running tests repeatedly)
./bin/test.sh --skipbuild


To debug tests it's possible to vnc into selenium container while its running at localhost:5900 and view the browser. Password is `secret`.

```sh
sudo apt-get install vinagre # vnc client

vinagre localhost:5900

About

Django React Starter Pack. Development and Deployment with docker one line commands.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published