Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updating with instructions and deploy key setup

  • Loading branch information...
commit 70fdd74c15477d989cc2a3e81750886aca784d01 1 parent 9432a86
@akoumjian authored
View
53 README.md
@@ -1,18 +1,47 @@
-salt-django-example
-===================
+# salt-django-example
-A skeleton example for deploying a django web application out of a git repository with salt.
-** Warning: This state tree is a demo and untested. **
+A salt state tree for deploying a django app to a production server.
-Instructions:
+## The Stack
-1. Follow the instructions to install and setup a salt-master and one or more salt-minions
-2. Copy the contents of this repo to /srv/ on your salt-master
-3. Update files with your own git repo and settings.
-4. Target the minions you want to deploy and call highstate.
-```sh
-# salt '*' state.highstate
-```
+* __Ubuntu 12.04 64bit __: The package names and the rest of the stack are only known to work with Ubuntu 12.04
+* __NGINX__: As a reverse proxy for the wsgi container and to serve static content
+* __gunicorn__: As our wsgi container
+* __circus__: Process watcher for gunicorn
+* __git__: For deploying our web application
+* __pip__ & __virtualenv__: For installing our requirements
+## The Setup
+
+
+There is no one click solution here, but when you are complete you will be able to deploy stateless web applications with relative easy and consistency. This tutorial does not include:
+
+1. Setting up a salt-master
+2. Configuring the salt-minion conf
+3. Creating and hosting your database
+
+When you are certain you already have those setup, you can continue.
+
+### Deploy Keys
+
+If you don't already have a deploy key for your application, you will want to create one. This guide assumes you are deploying from a private repository on github. See the guide here for details: https://help.github.com/articles/managing-deploy-keys
+
+After you have created your deploy key, you will want to place the keypair in `salt/deploy/` as `id_rsa` and `id_rsa.pub` respectively. If you name them something different, you will need to go into ``salt/webserver/init.sls`` and change the reference.
+
+### Entering your details
+
+Now you will need to edit the ``pillar/settings.sls`` file. Here you will enter the string values for your git repository, the branch or commit you wish to deploy, and your database settings.
+
+You will now need to copy over your settings from settings.py to the one located in ``salt/webserver/settings.py``. Make sure to you do not overwrite the template pillar fields and that you have included ``gunicorn`` in the installed apps.
+
+Check to make sure that the static folder specified in ``salt/webserver/nginx.conf`` correlates to the location of your static files.
+
+### Deploying
+
+Make sure you've placed your this state tree on the file_root for your salt-master (normally ``/srv/salt``). From your salt master you can now run ``salt '*' state.highstate``.
+
+### Notes
+
+The example is still missing conditional states to initiate your database with syncdb, run migrations, or running collectstatic on your files. These will be added in an upcoming release.
View
3  pillar/settings.sls
@@ -5,4 +5,5 @@ dbuser: mydbuser
dbpassword: myterribledbpassword
dbhost: localhost
dbport: 3306
-git_rev: develop
+git_rev: master
+git_repo: git@github.com:username/repo.git
View
19 salt/deploy/init.sls
@@ -0,0 +1,19 @@
+ssh_config:
+ file.managed:
+ - name: /root/.ssh/config
+ - source: salt://deploy/ssh_config
+ - makedirs: True
+
+deploykey:
+ file.managed:
+ - name: /root/.ssh/github
+ - source: salt://deploy/id_rsa
+ - makedirs: True
+ - mode: 600
+
+publickey:
+ file.managed:
+ - name: /root/.ssh/github.pub
+ - source: salt://deploy/id_rsa.pub
+ - makedirs: True
+ - mode: 600
View
5 salt/deploy/ssh_config
@@ -0,0 +1,5 @@
+Host github.com
+ User git
+ HostName github.com
+ StrictHostKeyChecking no
+ IdentityFile /root/.ssh/github
View
1  salt/webserver/gunicorn.ini
@@ -1,3 +1,4 @@
[watcher:gunicorn]
cmd = /var/www/env/bin/python /var/www/webapp/manage.py run_gunicorn
+args = --access-logfile /var/log/gunicorn.log --log-file /var/log/gunicorn.log
working_dir = /var/www/webapp
View
6 salt/webserver/init.sls
@@ -1,5 +1,6 @@
include:
- circus
+ - deploy
app-pkgs:
pkg.installed:
@@ -11,12 +12,15 @@ app-pkgs:
webapp:
git.latest:
- - name: git@github.com:username/repo.git
+ - name: {{ pillar['git_repo'] }}
- rev: {{ pillar['git_rev'] }}
- target: /var/www/myapp/
- force: true
- require:
- pkg: app-pkgs
+ - file: deploykey
+ - file: publickey
+ - file: ssh_config
settings:
file.managed:
View
5 salt/webserver/nginx.conf
@@ -3,6 +3,11 @@ server {
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
+ location /static/ {
+ autoindex on;
+ alias /var/www/myapp/static/;
+ }
+
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $http_host;
View
1  salt/webserver/settings.py
@@ -111,6 +111,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
+ 'gunicorn',
'myapp',
)
Please sign in to comment.
Something went wrong with that request. Please try again.