liip/django-ansible

Name: django-ansible

Owner: Liip

Description: Deploy Django projects generated by liip/django-template with Ansible

Created: 2016-09-24 08:28:27.0

Updated: 2017-05-04 19:20:50.0

Pushed: 2018-01-23 09:08:01.0

Homepage:

Size: 138

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

django-ansible

This project allows you to easily deploy your Django project on a Debian/Ubuntu Linux server. The following services/software will be installed on the server:

Server setup
Project setup
Deploy

Go to the deployment directory, there are two scripts:

Multiple environments/servers

To deploy to multiple different environments (e.g. test/staging/prod) you have to do the following: Make a copy of the files deployment/group_vars/production and deployment/production and adjust them for your new environment. Add the name of you new environment to the hosts: entry in deployment/site.yml.

Javascript single-page application frontend

You can deploy a SPA with django-ansible by uncommenting the frontend role in site.yml and setting some variables in group_vars/all.

The app has to be in a separate git repository. The repository will be checked out and built locally, after that the resulting files gets pushed to the server. The project needs a package.json with a npm run build command which builds the app into the dist/ subdirectory of the project.

If the build uses a different directory than dist/ for the production build, set the frontend_build_directory variable.

To make HTML5 history mode urls work, all requests not matching a file inside dist/ will be rewritten by nginx to dist/index.html.

vue-cli generates a project fulfilling these requirements without further modifications, except that HTML5 history mode is not enabled by default on vue-router.

If you have several environments (e.g. staging and production), configure frontend_build_env in each appropriate group_vars/* file. Refer to this guide on how to setup your frontend to work with this.

Continuous Deployment with GitLab

The install.sh script sets up a basic continuous deployment configuration. How to configure GitLab to use this configuration is documented here.

Email

django-template uses dj-email-url to configure the email settings.

Add the configuration url to your group_vars/<environment> file:

l_url: smtp://user:password@smtp.example.com:465/?ssl=True
l_from: webmaster@example.com

If these variables are not set, the emails will be sent to the smtp server running on port 25 on localhost without authentication.

Customization

You can add additional installation steps by adding Ansible Tasks to your project. To do this, create a directory custom in the deployment directory. This is the root directory for your custom Ansible role, you can add tasks, handlers, templates and other Ansible artifacts here. You also have to add your custom role to your deployment/site.yml under the roles entry.

To e.g. add a cronjob to your project, create a tasks directory inside custom, copy the file from examples/tasks/cronjob.yml to <your-project>/deployment/custom/tasks/cronjob.yml and adjust the configuration in this file for your needs. You also have to add a <your-project>/deployment/custom/tasks/main.yml file which includes the new task file:

- include: cronjob.yml

Example task files:

python-rq task queue

There is an additional role “taskqueue” which setups python-rq with redis as broker. To use it, add django-rq to your INSTALLED_APPS and define queues with RQ_QUEUES in your Django settings file. (see example in tests/django_app/settings/base.py)

Then activate the role by adding/uncommenting - taskqueue in your deployment/site.yml file.

License

MIT


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.