Merge pull request #167 from albohlabs/feature/ansible

Add ansible for provisioning
This commit is contained in:
Martin Zimmermann 2015-02-19 22:32:03 +01:00
commit e3dedef7ed
10 changed files with 190 additions and 59 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@
*.pyc *.pyc
.Python .Python
.sass-cache .sass-cache
.vagrant
/bin /bin
/include /include

View File

@ -44,5 +44,8 @@ In chronological order:
* Matías Ducasa <https://github.com/matiasducasa> * Matías Ducasa <https://github.com/matiasducasa>
* Spanish translation * Spanish translation
* Daniel Gräber <https://github.com/albohlabs>
* Added ansible for provisioning
* [Your name or handle] <[email or website]> * [Your name or handle] <[email or website]>
* [Brief summary of your changes] * [Brief summary of your changes]

60
Vagrantfile vendored
View File

@ -4,9 +4,10 @@
# This is the Vagrant config file for setting up an environment for Isso development. # This is the Vagrant config file for setting up an environment for Isso development.
# It requires: # It requires:
# #
# * Vagrant (http://vagrantup.com) # * Vagrant (https://vagrantup.com)
# * A VM engine, like VirtualBox (http://virtualbox.org) # * A VM engine, like VirtualBox (https://virtualbox.org)
# * The Vagrant-Hostmanager plugin (https://github.com/smdahlen/vagrant-hostmanager) # * The Vagrant-Hostmanager plugin (https://github.com/smdahlen/vagrant-hostmanager)
# * Ansible (https://www.ansible.com)
# #
# With them installed, cd into this directory and do 'vagrant up'. It's possible Vagrant will # With them installed, cd into this directory and do 'vagrant up'. It's possible Vagrant will
# ask for your root password so it can update your /etc/hosts file. Once it's happily churning out # ask for your root password so it can update your /etc/hosts file. Once it's happily churning out
@ -17,47 +18,20 @@
# to get into the VM. Useful info about it: # to get into the VM. Useful info about it:
# #
# * Running Ubuntu 14.04 # * Running Ubuntu 14.04
# * Isso is running on uWSGI via port 8080 # * Isso is running on uWSGI
# * Actual webserver is Apache2, using mod_proxy_uwsgi to talk to uWSGI # * Actual webserver is Nginx to talk to uWSGI over a unix socket
# * uWSGI log file is /tmp/uwsgi.log # * uWSGI log file is /var/log/uwsgi/apps/isso.log
# * Isso DB file is /tmp/isso/comments.db # * Isso DB file is /var/isso/comments.db
# * Isso log file is /tmp/isso/isso.log # * Isso log file is /var/log/isso.log
#
# When the VM is getting rebooted vagrant mounts the shared folder after uWSGI is getting startet. To fix this issue for
# the moment you need to 'vagrant ssh' into the VM and execute 'sudo service uwsgi restart'.
#
# For debugging with _pudb_ stop uWSGI service and start it manually
# 'sudo uwsgi --ini /etc/uwsgi/apps-available/isso.ini'.
# #
# Enjoy! # Enjoy!
$bootstrap = <<BOOTSTRAP
apt-get update
apt-get install -y apache2 curl build-essential python-setuptools python-dev sqlite3 git python-pip
a2enmod proxy
service apache2 restart
curl -sL https://deb.nodesource.com/setup | bash -
apt-get install -y nodejs
npm install -g bower requirejs uglify-js jade
cd /vagrant
python setup.py develop
make init
make js
ln -s /vagrant/isso/demo /var/www/isso
pip install uwsgi
mkdir -p /tmp/isso/spool
uwsgi --socket 127.0.0.1:8080 --master --processes 4 --cache2 name=hash,items=1024,blocksize=32 --spooler /tmp/isso/spool --module isso.run --env ISSO_SETTINGS=/vagrant/share/isso-dev.conf --daemonize /tmp/uwsgi.log --py-autoreload 1
chmod a+r /tmp/uwsgi.log
apt-get install libapache2-mod-proxy-uwsgi
cp /vagrant/share/isso-dev.local.apache-conf /etc/apache2/sites-available/isso-dev.local.conf
a2ensite isso-dev.local
a2dissite 000-default
service apache2 restart
BOOTSTRAP
Vagrant.configure(2) do |config| Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below. # The most common configuration options are documented and commented below.
@ -81,7 +55,11 @@ Vagrant.configure(2) do |config|
(ip = /inet addr:(\d+\.\d+\.\d+\.\d)/.match(result)) && ip[1] (ip = /inet addr:(\d+\.\d+\.\d+\.\d)/.match(result)) && ip[1]
end end
config.vm.provision "shell", inline: $bootstrap config.vm.provision "ansible" do |ansible|
ansible.playbook = "ansible/site.yml"
ansible.limit = "all"
ansible.verbose = "v"
end
config.vm.post_up_message = "Browse to http://isso-dev.local/demo/index.html to start." config.vm.post_up_message = "Browse to http://isso-dev.local/demo/index.html to start."
end end

39
ansible/files/nginx.conf Normal file
View File

@ -0,0 +1,39 @@
user root;
worker_processes 4;
worker_rlimit_nofile 8192;
error_log /var/log/nginx/error.log warn;
pid /run/nginx.pid;
events {
worker_connections 2014;
multi_accept on;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format timed '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'$request_time $upstream_response_time $upstream_addr '
' $upstream_status $upstream_cache_status $pipe';
access_log /var/log/nginx/access.log timed;
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

View File

@ -0,0 +1,13 @@
server {
client_max_body_size 20M;
listen 80 default_server;
server_name isso-dev.local;
root /vagrant/isso/demo;
location / {
# uwsgi_pass unix:///run/uwsgi/app/isso/socket;
uwsgi_pass 127.0.0.1:8080;
include uwsgi_params;
}
}

24
ansible/files/uwsgi.ini Normal file
View File

@ -0,0 +1,24 @@
[uwsgi]
plugins = python
chdir = /vagrant
uid = root
gid = root
socket = :8080
master = true
processes = 4
cache2 = name=hash,items=10240,blocksize=32
spooler = /var/isso/spool
module = isso.run
env = ISSO_SETTINGS=/vagrant/share/isso-dev.conf
env = PYTHON_EGG_CACHE=/tmp
# uncomment for debugging
# daemonize = /var/log/uwsgi/uwsgi.log
py-autoreload = 1
# prevent uWSGI from remapping stdin to /dev/null
honour-stdin = true

84
ansible/site.yml Normal file
View File

@ -0,0 +1,84 @@
---
- name: Provision development server
hosts: all
sudo: true
tasks:
- name: Apt | Add nodesource keys
apt_key: url=https://deb.nodesource.com/gpgkey/nodesource.gpg.key state=present
- name: Apt | Add nodesource sources list deb
apt_repository: repo='deb https://deb.nodesource.com/node {{ ansible_distribution_release }} main' state=present
- name: Apt | Add nodesource sources list deb src
apt_repository: repo='deb-src https://deb.nodesource.com/node {{ ansible_distribution_release }} main' state=present
- name: Apt | Install packages
apt: pkg={{ item }} state=latest update_cache=true
with_items:
- build-essential
- curl
- htop
- vim
- git
- python-dev
- python-software-properties
- python-setuptools
- python-pip
- nginx
- uwsgi
- uwsgi-plugin-python
- supervisor
- sqlite3
- nodejs
- name: NPM | Install packages
npm: name={{ item }} global=yes
with_items:
- bower
- requirejs
- uglify-js
- jade
- name: Python | Install egg
shell: cd /vagrant; python setup.py develop
- name: Make
shell: cd /vagrant; {{ item }}
with_items:
- make init
- make js
- name: Spool | Create directory
file: path=/var/isso/spool state=directory mode=0777
- name: uwsgi | Deploy configuration
copy: src=files/uwsgi.ini dest=/etc/uwsgi/apps-available/isso.ini
- name: uwsgi | Enable app
file: src=/etc/uwsgi/apps-available/isso.ini dest=/etc/uwsgi/apps-enabled/isso.ini state=link
- name: uwsgi | Restart service daemon
service: name=uwsgi state=restarted enabled=yes
- name: uwsgi | Chmod logfile
file: path=/var/log/uwsgi/uwsgi.log state=touch mode="a+r"
- name: nginx | Deploy nginx.conf
copy: src=files/nginx.conf dest=/etc/nginx/nginx.conf
- name: nginx | Delete default vhost
action: file path=/etc/nginx/sites-enabled/default state=absent
- name: nginx | Deploy vhost config
copy: src=files/nginx.vhost.conf dest=/etc/nginx/sites-available/isso.conf
- name: nginx | Enable vhost
file: src=/etc/nginx/sites-available/isso.conf dest=/etc/nginx/sites-enabled/000-isso state=link
- name: nginx | Chmod logfile
file: path=/var/log/nginx mode="a+rx" state=directory recurse=true
- name: nginx | Restart service daemon
service: name=nginx state=restarted enabled=yes

View File

@ -39,7 +39,10 @@ class curl(object):
except (httplib.HTTPException, socket.error): except (httplib.HTTPException, socket.error):
return None return None
try:
return self.con.getresponse() return self.con.getresponse()
except (socket.timeout, socket.error):
return None
def __exit__(self, exc_type, exc_value, traceback): def __exit__(self, exc_type, exc_value, traceback):
self.con.close() self.con.close()

View File

@ -5,11 +5,11 @@
[general] [general]
dbpath = /tmp/isso/comments.db dbpath = /var/isso/comments.db
host = http://isso-dev.local/ host = http://isso-dev.local/
max-age = 15m max-age = 15m
notify = stdout notify = stdout
log-file = /tmp/isso/isso.log log-file = /var/log/isso.log
[moderation] [moderation]
enabled = false enabled = false

View File

@ -1,14 +0,0 @@
<VirtualHost *:80>
ServerName isso-dev.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/isso/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass / uwsgi://127.0.0.1:8080/
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet