This is a Django boilerplate that covers best practices and a docker configuration.
- Python 2.7x
- Pip
- Virtualenv
- Docker (Install instructions)
-
Setup container .env files
cd docker/config cp db.example.env db.env cp web.example.env web.env
-
Retrive your machine ip:
docker-machine ip default
-
Include this ip on your hosts-file
<your-machine-ip> <project_domain>.dev
-
Start project
$(docker-machine env default) docker-compose up
-
Visit your site on: http://<project_domain>.dev:<project_web_port>
-
Make you have all individual components installed:
- PostgreSQL
- Python 2.7
- Pip
- Virtualenv
-
Install a virtualenv in your new project folder (
virtualenv venv
) -
Activate the virtualenv:
source venv/bin/activate
(or on windows:./venv/Scripts/activate
) -
Install the requirements from the environment you want (usually local version) with:
pip install -r src/requirements/local.txt
-
Create a database in postgres and remember the database name and user/password
-
Copy the example.env and rename to .env and change the settings to your projects specific settings (including database etc)
-
Go into src
cd src
-
Run the migrations to get auth system and the example pages app
python manage.py migrate
-
Create a superuser for your admin:
python manage.py createsuperuser
-
Start the development server:
python manage.py runserver
-
Run
python manage.py collectstatic
-
Visit your site on: http://localhost:8000
To activate the example app, uncomment it in base.py and it's included urls in urls.py in the core app.
This boilerplate uses semantic versioning and follow django's MAJOR and MINOR version numbers, PATCH has no connection to django version, but is something we use to indicate updates.
Bump version in:
- src/core/settings/base.py
(APP_VERSION=0.0.1)
- frontend/package.json
- src/Dockerfile
...or just use the bump-version git hook
We follow the django coding style, which is based on PEP8.
The project has .gitattributes
, but you need to make sure a driver is set up for this, type this is the terminal:
git config --global merge.ours.driver true
These hooks will automatically bump the application version when using git flow release ...
chmod +x $PWD/git-hooks/bump-version.sh
ln -nfs $PWD/git-hooks/bump-version.sh .git/hooks/post-flow-release-start
ln -nfs $PWD/git-hooks/bump-version.sh .git/hooks/post-flow-hotfix-start
This hook will run the test suite before every push.
chmod +x $PWD/git-hooks/pre-push.sh
ln -nfs $PWD/git-hooks/pre-push.sh .git/hooks/pre-push
chmod +x $PWD/git-hooks/pep8-pre-commit.sh
ln -nfs $PWD/git-hooks/pep8-pre-commit.sh .git/hooks/pre-commit
Note: This requires the pep8 package (pip install pep8
)
This app includes a docker-compose config that uses uwsgi and nginx. Just run this command.
docker-compose -f docker-compose.yml -f docker-compose-nginx.yml up
You can rebuild your application with the latest data dump by running the following
./docker/stage_to_local.sh
Note: This requires that have ssh-key based access to the stage or prod server
-
Install docker (use the Docker Toolbox). Please use the virtualbox version.
- Minimum requirements are docker
1.11
, docker-compose1.7
- Minimum requirements are docker
-
Setup machine (if not already present)
docker-machine create --driver virtualbox default docker-machine start default
Start the container with service-ports exposed instead of docker-compose up
. This will create a container called <project_prefix>_web_run_1
docker-compose run --rm --service-ports web
To run manage.py commands in docker is pretty straightforward, instead of targetting you local machine you just target your web container.
- Example: Create migrations
docker-compose exec run web python manage.py makemigrations
- Example: Run migrations
docker-compose exec run web python manage.py migrate
We also have a manage.sh script to make running management commands easier.
scripts/manage.sh makemigrations
First update your requirements/base.txt, then rebuild your container:
docker-compose stop
docker-compose build
docker-compose up
Want to contribute? Awesome. Just send a pull request.
Fröjd Django Boilerplate is released under the MIT License.