A tool for deploying Django Web Apps to remote servers
Project description
Last Updated: July 18th, 2018
A collection of commands for generating and modifying a Django 2.0 project bundled with production-ready Dockerfiles.
Installation & Setup
Install the following dependencies:
Docker for Mac/Windows
Python 2.7/3.x (Python 3.x preferred)
Install from PyPI
pip install yak-yurt
Alternative: Install from git
git clone git@github.com:yeti/yurt.git
cd yurt
pip install --editable .
Project Structure
A project created with Yurt has the following file structure:
<project_name> (PROJECT_ROOT)
|
|_ docker-compose.yml
|_ docker-compose.remote.yml
|
|_ django_app
| |
| |_ <project_name>
| | |_ settings.py
| | |_ wsgi.py
| | |_ urls.py
| |
| |_ manage.py
| |_ requirements.txt
| |_ Dockerfile.dev
| |_ Dockerfile.remote
|
|_ envs
| |
| |_ dev.env
| |_ remote.env
|
|_ proxy
|
|_ Dockerfile
|_ start.sh
|_ <project_name>.conf
|_ <project_name>.ssl.conf
- Running yurt env add will add:
Another docker-compose.*.yml file to the PROJECT_ROOT.
Another *.env file to PROJECT_ROOT/envs
Note: <project_name>.ssl.conf is provided as a convenience, but it will still take some work to get it set up.
Usage
Get HELP for a Yurt command
yurt [COMMAND] --help
Creating a new Django project
yurt new
This command generates all the files necessary to have a Django project, bundled with docker-compose.yml. Without any further configuration, you can run docker-compose to run Django’s dev server
cd path/to/projects/docker-compose.yml
docker-compose up
Host Provisioning
yurt provision new
Yurt uses docker-machine to support automagical Docker provisioning on AWS EC2 servers as well as on generic servers. Dry run mode (which is prompted by Yurt) simply prints out the docker-machine commands that Yurt would call given your input (and is recommended for new users).
Environment Variable Management
Yurt has some utilities for managing environment variables in the project. It only really makes sense to do this once you’ve provisioned a host with Docker (see Host Provisioning above ☝️).
About Environment Contexts
An environment context is simply the environment variables and deploy configurations that correspond to a given desired context (i.e. “staging”, “production”, “test”). Each environment context in a Yurt project consists of an environment variable file (*.env) in the envs directory and the corresponding docker-compose.*.yml file in the root-level directory. The environment variables of new environment contexts are NOT checked into version control, so it’s important to coordinate with teams a way to export/import environment variables.
Note 1: docker-compose.remote.yml is a special file that Yurt uses as the initial template for new environment contexts. It can be edited but should not be deleted.
Note 2: Adding new services to docker-compose.remote.yml will propagate those new services to new environment contexts. For example, adding a new service like redis to docker-compose.remote.yml means that subsequent calls to yurt env add will include redis.
Add a new environment context
cd path/to/yurt-project
yurt env add
Export environment variables of all environment contexts to zip file
cd path/to/yurt-project
yurt env export <arbitrary-name>
Import environment variables of all environment contexts from zip file
cd path/to/yurt-project
yurt env import path/to/env-vars.zip
Deploying Django to Remote Host
Yurt no longer directly handles app deploy. To deploy, you can use docker-compose in the right machine context. This is a guide to do so. This guide assumes you are in the root directory of a Yurt project (i.e. the same directory as docker-compose.yml).
First: Provision a new Remote Host
yurt provision new
In this example, I will create a new generic host on a VPS at IP address 11.22.33.44 called test-host-1.
Second: Change machine context
eval `docker-machine env test-host-1` # Or use a different name than "test-host-1" to access a different context.
This tells Docker that any docker or related command that is called is to be piped over directly to the remote host.
Third: Generate the Environment Context
yurt env add
In this example, I defined allowed_hosts and nginx_server_name as the IP address of the current machine context (11.22.33.44). I defined environment as production. I also set a bunch of other variables related to Django and Postgres.
Fourth: Deploy
docker-compose -f docker-compose.production.yml up -d
Simply, run docker-compose with the correct environment context’s deploy configs. The deploy configs automatically pull the correct environment variables.
Contributing
Refer to CONTRIBUTING.rst
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file yak-yurt-1.0.0.tar.gz
.
File metadata
- Download URL: yak-yurt-1.0.0.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7988c13095e25db7feddaeabe5851c9aa15859c4b0e8a2604a77712a8c547d4b |
|
MD5 | 9c7c550e6826e130e6b3fb3961c158d6 |
|
BLAKE2b-256 | a10c0a21047495678ddc69a5f2fc1096822bf9d84b7142bbd75d91e2bb5b5e97 |
File details
Details for the file yak_yurt-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: yak_yurt-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2819f23dfeb0d93e2a6d6cc2d3f7bceed671b5c9f24b3abf1644b4aee5984b5e |
|
MD5 | 4185d67a9c78be789b79d7a1d931fbfd |
|
BLAKE2b-256 | cb51374ab5ef9d4f652495940e9f3e44a382407c531a9a62c366c8eff436bb32 |