|
1 | | -Provision a Deis Controller on Vagrant |
2 | | -====================================== |
| 1 | +Local development workflow for Deis |
| 2 | +================================================================ |
3 | 3 |
|
4 | | -This document describes how to set up a Deis controller and two nodes with |
5 | | -Vagrant for testing. |
| 4 | +This document suggests some ways that might make developing Deis easier and cheaper. You don't have to follow |
| 5 | +them all. |
6 | 6 |
|
7 | | -1. Install VirtualBox version 4.2.18. (Vagrant does not support version 4.3.) |
8 | | -Then start VirtualBox and install the VirtualBox Extension Pack for 4.2.18. |
| 7 | +1. You'll need VirtualBox >= `4.2.18`. We recommend installing Vagrant with their binary installer from http://downloads.vagrantup.com |
| 8 | +Vagrant 1.3.5 has support for VirtualBox 4.3 |
9 | 9 |
|
10 | | -2. Install Vagrant version 1.3.5 or later. Rather than fight Ruby dependencies, |
11 | | -use a binary installer from vagrantup.com. |
| 10 | +2. Firstly you need to decide whether to use your own Chef Server or the free tier of the hosted enterprise |
| 11 | +service from Opscode. The free tier has a limit of 5 nodes which is more then enough for development. Also |
| 12 | +bear in mind that a local Chef Server VM will take up at least 1GB of RAM. |
12 | 13 |
|
13 | | -3. Run the provisioning script: |
14 | | -```console |
15 | | -$ ./contrib/vagrant/provision-vagrant-controller.sh |
16 | | -``` |
| 14 | + **Local Chef Server** |
| 15 | + * `cd [DEIS_DIR] && ln -s contrib/vagrant/knife-config .chef` |
| 16 | + * `vagrant up` the chef server Vagrantfile. |
| 17 | + * copy the admin.pem and validation.pem files for your own knife client |
| 18 | + `scp -r root@chefserver.local:/etc/chef-server/admin.pem [DEIS_DIR]/contrib/vagrant/knife-config/` |
| 19 | + `scp -r root@chefserver.local:/etc/chef-server/chef-validator.pem [DEIS_DIR]/contrib/vagrant/knife-config/` |
17 | 20 |
|
18 | | -This script will: |
19 | | -- Create the data bags in your Chef account to support Deis |
20 | | -- Run `vagrant up` to create a Deis controller and 2 static nodes |
21 | | -- Register the controller with Chef and install Deis and supporting software |
| 21 | + **Hosted Chef Server** |
| 22 | + * Goto https://getchef.opscode.com/signup and fill in your details. |
| 23 | + * Goto https://preview.opscode.com/login and sign in to your Chef Server. |
| 24 | + * Click on the 'Administration' tab and choose your organisation. There should be a tab in the sidebar that says |
| 25 | + 'Starter Kit'. Click it and it will start a small download. |
| 26 | + * Inside the Starter Kit there is a '.chef' folder. Copy it to the root of your Deis codebase. |
22 | 27 |
|
23 | | -4. Register a user |
| 28 | +3. Now you can follow the standard deis setup: |
| 29 | + ```bash |
| 30 | + bundle install # Installs gem files like the knife tool |
| 31 | + berks install # Downloads the relevant cookbooks |
| 32 | + # '--ssl-verify' is only needed when using a local Chef Server |
| 33 | + berks upload [--ssl-verify=false] # Upload the cookbooks to the Chef Server |
| 34 | + ``` |
24 | 35 |
|
25 | | -5. Run the script to create a static formation: |
26 | | -```console |
27 | | -$ ./contrib/vagrant/create-static-formation.sh |
28 | | -``` |
| 36 | +4. Use the provision script to boot the deis controller. |
| 37 | + * If you don't already have the deis-node Vagrant box installed (~1GB). This step might take a long time! If for some reason |
| 38 | + you want to manually add it, use: |
| 39 | + `vagrant box add deis-node https://s3-us-west-2.amazonaws.com/opdemand/deis-node.box` |
| 40 | + * `cd contrib/vagrant && ./provision-controller.sh` |
| 41 | + * You will be asked to add the Controller's SSH key to your local SSH server. This will allow the Controller |
| 42 | + to run vagrant commands on your machine to bootstrap new nodes. |
| 43 | + * If you are using a local Chef Server you will need to tell it that your new controller has permission to create |
| 44 | + nodes. Use: |
| 45 | + `knife client edit deis-controller` |
| 46 | + and your default text editor will launch, you need to set 'admin' to 'true'. |
| 47 | + |
| 48 | +5. The Controller needs to be able to run Vagrant commands on your host machine. It does this via SSH. Therefore |
| 49 | +you will need a running SSH server open on port 22. |
| 50 | + * On Debian-flavoured Linux you just need to; |
| 51 | + `sudo apt-get install openssh-server` |
| 52 | + * On Mac OSX you just need to go to **System Preferences -> Sharing** and enable 'Remote Login'. |
| 53 | + * **NB** If your machine's IP changes the Controller won't be able to run commands any more. Currently you aren't informed |
| 54 | + of this, you just get a 500 error from the client. If you tail `/var/log/deis/celeryd.log` though you'll know. When this |
| 55 | + does happen just reupload your IP with `deis providers:discover`. |
| 56 | + |
| 57 | +6. If you want to hack on the actual codebase, you can mount your local codebase onto the VM |
| 58 | + by using the custom Vagrantfile.local. |
| 59 | + * `cp Vagrantfile.local.example Vagrantfile.local` (don't worry it's in .gitignore) |
| 60 | + * Update the VM with `vagrant reload --provision` |
| 61 | + * When mounted you can use your favourite editor to change the code _on your local machine's path_ and then run |
| 62 | + `service deis-server restart` and/or `service deis-worker restart` on the VM for your changes to instantly take effect. |
| 63 | + * It's worth having a read of `Vagrantfile.local.example` |
| 64 | + |
| 65 | +7. If you want to hack on the command line client (`/client/deis.py`), install your local dev version rather than |
| 66 | +the one from Pip. |
| 67 | + * `cd deis && make install` This will symlink the dev version to your executables path. |
| 68 | + * Your deis controller is available at http://deis-controller.local so you can register with; |
| 69 | + `deis register http://deis-controller.local` |
| 70 | + |
| 71 | +8. Right, time to boot up some nodes! |
| 72 | + * Create a foramtion with a vagrant flavour, 512MB, 1024MB and 2048MB are available. |
| 73 | + `deis formations:create dev --flavor=vagrant-512 --domain=deisapp.local` |
| 74 | + * Scale a node with `deis nodes:scale dev runtime=1` Be patient, this is the command that runs vagrant commands. Scaling a single node |
| 75 | + can take about 5 mins. |
| 76 | + * Then create and push your app as per the usual documentation. |
| 77 | + |
| 78 | +## Useful development commands |
| 79 | +* To use Django's manage.py: |
| 80 | + * SSH in to the VM with `vagrant ssh` |
| 81 | + * Switch user to deis with `sudo su deis` |
| 82 | + * `cd /opt/deis/controller` and activate Venv with `. venv/bin/activate` |
| 83 | + * Get a list of commands with; `./manage.py help`. |
| 84 | + |
| 85 | +* To reset the DB: |
| 86 | + * On the VM run `sudo su postgres -c 'dropdb deis && createdb --encoding=utf8 --template=template0 deis'` |
| 87 | + * When you restart the server with `sudo service deis-server restart` Django will reinstall the DB. |
| 88 | + * You'll need to reupdate the Django's Site Object |
| 89 | + `sudo su deis -c "psql deis -c \"UPDATE django_site SET domain = 'deis-controller.local', name = 'deis-controller.local' WHERE id = 1 \""` |
| 90 | + |
| 91 | +* This is useful for uploading your own local version of the cookbooks, rather than the Github versions: |
| 92 | + * `knife cookbook upload deis --cookbook-path [deis-cookbook path] --force` |
| 93 | + * You need to change directory structure though as knife gets the cookbook name from the folder name. So, for example I use; |
| 94 | + |
| 95 | + ```bash |
| 96 | + deis |
| 97 | + |__ code |
| 98 | + |__ api |
| 99 | + |__ bin |
| 100 | + |__ client |
| 101 | + |__ cm |
| 102 | + |__ ... and so on |
| 103 | + |__ cookbooks |
| 104 | + |__ deis |
| 105 | + |__ attributes |
| 106 | + |__ definitions |
| 107 | + |__ recipes |
| 108 | + |__ ... and so on |
| 109 | + ``` |
29 | 110 |
|
30 | 111 | Notes |
31 | 112 | ----- |
32 | 113 |
|
33 | 114 | Mac OS X: if you see an error such as |
34 | | -"failed to open /dev/vboxnetctl", try restarting VirtualBox: |
35 | | -sudo /Library/StartupItems/VirtualBox/VirtualBox restart |
| 115 | +'failed to open /dev/vboxnetctl', try restarting VirtualBox: |
| 116 | +sudo /Library/StartupItems/VirtualBox/VirtualBox restart |
0 commit comments