pyPaaS has a few dependencies we need to install first:
root@host$ apt-get install build-essential python3.4-dev python3-pip virtualenv libyaml-dev daemontools daemontools-run git rsync
pyPaaS needs a normal user to work. This will be the user you use to git push
to. Let's create one:
root@host:~$ adduser --disabled-password deploy
Adding user `deploy' ...
Adding new group `deploy' (1002) ...
Adding new user `deploy' (1002) with group `deploy' ...
The home directory `/home/deploy' already exists. Not copying from `/etc/skel'.
Changing the user information for deploy
Enter the new value, or press ENTER for the default
Full Name []: pyPaaS
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
We can now grab the code and configure a virtualenv!
root@host:~$ su deploy
deploy@host:/root$ cd ~
deploy@host:~$ # For production usage:
deploy@host:~$ git clone https://github.com/fintura/pyPaaS.git
deploy@host:~$ # For development:
deploy@host:~$ ln -s <WHEREEVER YOUR CHECKOUT IS> pyPaaS
deploy@host:~$ virtualenv --python=python3.4 venv
Running virtualenv with interpreter /usr/bin/python3.4
Using base prefix '/usr'
New python executable in venv/bin/python3.4
Also creating executable in venv/bin/python
Installing setuptools, pip...done.
deploy@host:~$ venv/bin/pip install -e pyPaaS/
Create configuration and .ssh directories
deploy@host:~$ mkdir -p ~/config/domains ~/config/repos ~/.ssh/authorized_keys.d
deploy@host:~$ chmod 700 ~/.ssh
To run stuff we need to configure daemontools
root@host:~$ mkdir /etc/service/pyPaaS
root@host:~$ cp ~deploy/pyPaaS/daemontools-run /etc/service/pyPaaS/run.new
root@host:~$ chmod 755 /etc/service/pyPaaS/run.new
root@host:~$ mv /etc/service/pyPaaS/run.new /etc/service/pyPaaS/run
Now add your configuration in ~deploy/config
, your SSH public keys in ~deploy/.ssh/authorized_keys.d
and run /home/deploy/venv/bin/pypaas rebuild_authorized_keys
as deploy
to assemble the actual authorized_keys
file.
That's it :).
See example-configuration
for a heavily commented configuration example. You can put your configuration either in ~deploy/config
or /etc/pypaas
. pyPaas uses the first directory of the ones listed above with a pypaas.yml
file as it's configuration directory. Like all pyPaaS configuration it uses YAML syntax.
We'll use the example configuration in example-configuration
to deploy the heroku node.js sample application. Just copy the contents of example-configuration
into either ~deploy/config
or /etc/pypaas
and make it (at least) readable to the deploy user.
The configuration has a simple structure:
- all global configuration goes into
pypaas.yml
- configuration for a repo goes into
repos/<repo_name>.yml
- configuration for a domain goes into
domains/<domain_name>.yml
You can have one repository serve any number of domains and vice versa.
Now all that's left to do before your first deploy is adding ssh public keys. pyPaaS expects them in ~deploy/.ssh/authorized_keys.d/
. The ~deploy/.ssh/authorized_keys
is generated by running ~deploy/venv/bin/pypaas rebuild_authorized_keys
as deploy
.
Let's deploy the node.js sample app:
you@your-machine:~$ git clone https://github.com/heroku/node-js-sample
you@your-machine:~$ cd node-js-sample
you@your-machine:~$ cat > .build.sh <<EOF
#!/bin/bash
npm install
EOF
you@your-machine:~$ chmod +x .build.sh
you@your-machine:~$ git add .build.sh && git commit -m "add build script"
you@your-machine:~$ git push deploy@your-server:node-js-sample
Now watch it build and start this application and that's it :).