|
| 1 | +# GeoNode DevOps (geonode-devops) |
| 2 | + |
| 3 | +DevOps tools for developing & deploying [GeoNode](http://geonode.org/), including [Ansible](https://www.ansible.com/), [Packer](https://www.packer.io/), [Vagrant](https://www.vagrantup.com/), and [Fabric](http://www.fabfile.org/) configuration files for building and managing Ubuntu and CentOS GeoNode boxes. |
| 4 | + |
| 5 | +# Installation |
| 6 | + |
| 7 | +On the control/host machine, you'll need to install [Ansible](https://www.ansible.com/), [Packer](https://www.packer.io/), [Vagrant](https://www.vagrantup.com/), and [Fabric](http://www.fabfile.org). |
| 8 | + |
| 9 | +**Quick Install** |
| 10 | + |
| 11 | +If you wish to use a python virtual environment on your host/control machine, be sure to install `virutalenv` and `virtualenvwrapper`. Your `~/.bash_aliases` file should look something like the following: |
| 12 | + |
| 13 | +``` |
| 14 | +export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python |
| 15 | +export WORKON_HOME=~/.venvs |
| 16 | +source /usr/local/bin/virtualenvwrapper.sh |
| 17 | +export PIP_DOWNLOAD_CACHE=$HOME/.pip-downloads |
| 18 | +``` |
| 19 | + |
| 20 | +To quickly install [Ansible](https://www.ansible.com/) and [Fabric](http://www.fabfile.org), run the following: |
| 21 | + |
| 22 | +``` |
| 23 | +sudo apt-get install python-dev # if not already installed |
| 24 | +sudo easy_install pip # if pip is not already installed |
| 25 | +sudo pip install virtualenv virtualenvwrapper |
| 26 | +# cd into project directory |
| 27 | +sudo pip install -r requirements.txt |
| 28 | +``` |
| 29 | + |
| 30 | +## Ansible |
| 31 | + |
| 32 | +Ansible is an agent-less provisioning tool for managing the state of machines. It is used by both [Packer](https://www.packer.io/) and [Vagrant](https://www.vagrantup.com/). By sharing a common Ansible `playbook` for configuring production machines, building test boxes via Packer, and development boxes for Vagrant, we're able to have dev-prod parity. |
| 33 | + |
| 34 | +To get [Ansible](https://www.ansible.com/) follow the relevant section below. Also see http://docs.ansible.com/ansible/intro_installation.html#getting-ansible for more information. |
| 35 | + |
| 36 | +#### Mac OS X & Ubuntu |
| 37 | + |
| 38 | +``` |
| 39 | +sudo easy_install pip # if pip is not already installed |
| 40 | +sudo pip install ansible |
| 41 | +``` |
| 42 | + |
| 43 | +## Packer |
| 44 | + |
| 45 | +[Packer](https://www.packer.io/) can be used to build virtual machine images. |
| 46 | + |
| 47 | +#### Mac OS X |
| 48 | + |
| 49 | +``` |
| 50 | +sudo mkdir -p /opt/packer/bin |
| 51 | +cd /opt/packer/ |
| 52 | +sudo wget https://releases.hashicorp.com/packer/0.10.0/packer_0.10.0_darwin_amd64.zip |
| 53 | +sudo unzip packer_0.10.0_darwin_amd64.zip |
| 54 | +sudo mv packer /opt/packer/bin |
| 55 | +cd /usr/local/bin/ |
| 56 | +sudo ln -s /opt/packer/bin/packer packer |
| 57 | +``` |
| 58 | + |
| 59 | +#### Ubuntu |
| 60 | + |
| 61 | +``` |
| 62 | +sudo mkdir -p /opt/packer/bin |
| 63 | +cd /opt/packer/ |
| 64 | +sudo wget 'https://releases.hashicorp.com/packer/0.10.0/packer_0.10.0_linux_amd64.zip' |
| 65 | +sudo unzip packer_0.10.0_linux_amd64.zip |
| 66 | +sudo mv packer /opt/packer/bin |
| 67 | +cd /usr/bin/ |
| 68 | +sudo ln -s /opt/packer/bin/packer packer |
| 69 | +``` |
| 70 | + |
| 71 | +## Fabric |
| 72 | + |
| 73 | +[Fabric](http://www.fabfile.org/) provides an easy command line interface for executing remote shell commands and for transferring files between machines. Fabric is extremely useful for transferring files and managing remote servers. |
| 74 | + |
| 75 | +Follow directions at http://www.fabfile.org/installing.html to install fabric or follow shortcuts below. |
| 76 | + |
| 77 | +#### Mac OS X & Ubuntu |
| 78 | + |
| 79 | +``` |
| 80 | +sudo pip install fabric |
| 81 | +``` |
| 82 | + |
| 83 | +Once fabric is installed, create a `geonodes.py` file in the same directory as the `fabfile.py`. `geonodes.py` is in `.gitignore` so will not be committed. This file includes connection and other information, so that fab commands are streamlined. |
| 84 | + |
| 85 | +```javascript |
| 86 | +GEONODE_INSTANCES = { |
| 87 | + "devgeonode": { |
| 88 | + "ident": "~/auth/keys/devgeonode.pem", |
| 89 | + "host": "dev.geonode.example.com", |
| 90 | + "user": "ubuntu", |
| 91 | + "type": "geoshape" |
| 92 | + }, |
| 93 | + "prodgeonode": { |
| 94 | + "ident": "~/auth/keys/prodgeonode.pem", |
| 95 | + "host": "prod.geonode.example.com", |
| 96 | + "user": "ubuntu", |
| 97 | + "type": "geoshape" |
| 98 | + } |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +# Usage |
| 103 | + |
| 104 | +Create a `secret.yml` file in the project root. |
| 105 | + |
| 106 | +## Vagrant |
| 107 | + |
| 108 | +To add the Centos 6.4 vagrant box to your control machine, run: |
| 109 | + |
| 110 | +``` |
| 111 | +vagrant box add --name "centos/6.4" http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20131103.box |
| 112 | +
|
| 113 | +``` |
| 114 | + |
| 115 | +To add an Ubuntu 14.04 ("Trusty") vagrant box to your control machine, run: |
| 116 | + |
| 117 | +``` |
| 118 | +vagrant box add ubuntu/trusty64 |
| 119 | +
|
| 120 | +``` |
| 121 | + |
| 122 | +To launch the GeoNode virtual machine run: |
| 123 | + |
| 124 | +``` |
| 125 | +vagrant up |
| 126 | +``` |
| 127 | + |
| 128 | +To re-provision the machine run: |
| 129 | + |
| 130 | +``` |
| 131 | +vagrant provision |
| 132 | +``` |
| 133 | + |
| 134 | +## Packer |
| 135 | + |
| 136 | +You can also use [Packer](https://www.packer.io/) to build a virtual machine. |
| 137 | + |
| 138 | +To build a base box for CentOS 6.4, run: |
| 139 | + |
| 140 | +``` |
| 141 | +packer build -var 'ansible_playbook=ansible/centos_base.yml' -var 'ansible_secret=secret.yml' -var 'ansible_os=centos' packer/centos64.json |
| 142 | +``` |
| 143 | + |
| 144 | +To build a base box for Ubuntu 14.04, run: |
| 145 | + |
| 146 | +``` |
| 147 | +packer build -var 'ansible_playbook=ansible/ubuntu_base.yml' -var 'ansible_secret=secret.yml' -var 'ansible_os=ubuntu' packer/ubuntu1404.json |
| 148 | +``` |
| 149 | + |
| 150 | +#### Adding Your New Box |
| 151 | + |
| 152 | +After you created your box, you can add with: |
| 153 | + |
| 154 | +``` |
| 155 | +vagrant box add --name "geonode_base" packer_virtualbox-ovf_virtualbox.box |
| 156 | +``` |
| 157 | + |
| 158 | +Add the box to the [Vagrantfile](https://github.com/pjdufour/geonode-devops/blob/master/Vagrantfile) to provision with it. |
| 159 | + |
| 160 | +## Launch |
| 161 | + |
| 162 | +Once the image is provisioned, ssh into the machine via: |
| 163 | + |
| 164 | +``` |
| 165 | +# cd into geonode-devops.git directory |
| 166 | +vagrant ssh |
| 167 | +``` |
| 168 | + |
| 169 | +Once in the virtual machine, run: |
| 170 | + |
| 171 | +``` |
| 172 | +workon geonode |
| 173 | +cd geonode |
| 174 | +paver stop |
| 175 | +paver reset_hard |
| 176 | +paver setup |
| 177 | +paver start -b 0.0.0.0:8000 # Launches Django and GeoServer. Listens to all addresses on port 8000. |
| 178 | +``` |
| 179 | + |
| 180 | +## Fabric |
| 181 | + |
| 182 | +[Fabric](http://www.fabfile.org/) provides an easy command line interface for executing remote shell commands and for transferring files between machines. For GeoNode, Fabric can be used to import large files, `updatelayers`, manage GeoServer restart cron jobs, and backup a remote GeoNode locally. |
| 183 | + |
| 184 | +To get started, change directory (`cd`) into the main fabric directory (`./fabric`) with the `fabfile.py`. When you call fab, start with `gn:geonodehost` so that the host and identity key are loaded automatically from `geonodes.py`. |
| 185 | + |
| 186 | +To see a list of tasks run: |
| 187 | + |
| 188 | +``` |
| 189 | +fab -l |
| 190 | +``` |
| 191 | + |
| 192 | +To see the long description of a task run: |
| 193 | + |
| 194 | +``` |
| 195 | +fab -d taskname |
| 196 | +``` |
| 197 | + |
| 198 | +A few examples: |
| 199 | + |
| 200 | +``` |
| 201 | +fab gn:devgeonode,prodgeonode lsb_release |
| 202 | +fab gn:devgeonode inspect_geoshape |
| 203 | +fab gn:devgeonode restart_geoshape |
| 204 | +fab gn:prodgeonode updatelayers:t=geoshape |
| 205 | +fab gn:prodgeonode importlayers:t=geoshape,local=~/data/*.zip,drop=/opt/drop,user=admin,overwrite=1,private=1 |
| 206 | +fab gn:prodgeonode addgmail_geoshape:email,password |
| 207 | +fab gn:prodgeonode cron_restart_geoserver:'00 04 * * *' |
| 208 | +fab gn:prodgeonode backup_geonode:t=geoshape,remote=/opt/backups/20150707,local=~/backups |
| 209 | +``` |
0 commit comments