Permalink
Browse files

Bug 799244: add puppet scripts for Spade

  • Loading branch information...
1 parent 9a5b20c commit 2cb76f2a90995a7c428b8fe6aa4bd3eed080440e @AutomatedTester AutomatedTester committed Oct 8, 2012
View
@@ -36,3 +36,6 @@ spade/settings/local.py
# generated files from storage
media/*
+
+#Vagrant
+.vagrant
View
@@ -0,0 +1,43 @@
+require "yaml"
+
+# Load up our vagrant config files -- vagrantconfig.yaml first
+_config = YAML.load(File.open(File.join(File.dirname(__FILE__),
+ "vagrantconfig.yaml"), File::RDONLY).read)
+
+# Local-specific/not-git-managed config -- vagrantconfig_local.yaml
+begin
+ _config.merge!(YAML.load(File.open(File.join(File.dirname(__FILE__),
+ "vagrantconfig_local.yaml"), File::RDONLY).read))
+rescue Errno::ENOENT # No vagrantconfig_local.yaml found -- that's OK; just
+ # use the defaults.
+end
+
+CONF = _config
+MOUNT_POINT = '/home/vagrant/project'
+
+Vagrant::Config.run do |config|
+ config.vm.box = "lucid32"
+ config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
+
+ config.vm.forward_port 80, 8000
+
+ # Increase vagrant's patience during hang-y CentOS bootup
+ # see: https://github.com/jedi4ever/veewee/issues/14
+ config.ssh.max_tries = 50
+ config.ssh.timeout = 300
+
+ # nfs needs to be explicitly enabled to run.
+ if CONF['nfs'] == false or RUBY_PLATFORM =~ /mswin(32|64)/
+ config.vm.share_folder("v-root", MOUNT_POINT, ".")
+ else
+ config.vm.share_folder("v-root", MOUNT_POINT, ".", :nfs => true)
+ end
+
+ # Add to /etc/hosts: 33.33.33.24 dev.playdoh.org
+ config.vm.network :hostonly, "33.33.33.24"
+
+ config.vm.provision :puppet do |puppet|
+ puppet.manifests_path = "puppet/manifests"
+ puppet.manifest_file = "vagrant.pp"
+ end
+end
View
@@ -17,4 +17,15 @@ Installation
4. Run ``./manage.py syncdb`` to create the database tables.
+Vagrant Setup
+-------------
+
+1. Run ``vagrant up`` in a terminal. This will create a new VM that will have
+ Spade running on it. It will run the necessary `Puppet`_ scripts
+
+2. add ``127.0.0.1 dev.spade.org`` to /etc/hosts
+
+3. Navigate to http://dev.spade.org:8000 in your browser
+
.. _virtualenv: http://www.virtualenv.org
+.. _Puppet: http://puppetlabs.com/
@@ -0,0 +1,30 @@
+# HACK: Make the server reload after every hit to refresh django code
+MaxRequestsPerChild 1
+
+WSGISocketPrefix /var/run/wsgi
+
+<VirtualHost *:80>
+ ServerName dev.spade.org
+
+ DirectoryIndex index.php index.html
+ Options -Indexes
+
+ RewriteEngine On
+
+ DocumentRoot "/var/www/html/"
+
+ Alias /static/ "/home/vagrant/project/static/"
+ Alias /admin-media/ "/home/vagrant/project/vendor/src/django/django/contrib/admin/media/"
+
+ WSGIDaemonProcess spade python-path=/home/vagrant/project:/home/vagrant/spade-venv/lib/python2.6/site-packages processes=1 threads=1 maximum-requests=1
+ WSGIProcessGroup spade
+
+ WSGIScriptAlias / "/home/vagrant/project/spade/wsgi.py"
+
+ <Proxy *>
+ AddDefaultCharset off
+ Order deny,allow
+ Deny from all
+ Allow from all
+ </Proxy>
+</VirtualHost>
@@ -0,0 +1,70 @@
+# Red Hat, CentOS, and Fedora think Apache is the only web server
+# ever, so we have to use a different package on CentOS than Ubuntu.
+class apache {
+ case $operatingsystem {
+ centos: {
+ package { "httpd-devel":
+ ensure => present,
+ before => File['/etc/httpd/conf.d/spade.conf'];
+ }
+
+ file { "/etc/httpd/conf.d/spade.conf":
+ source => "$PROJ_DIR/puppet/files/etc/httpd/conf.d/spade.conf",
+ owner => "root", group => "root", mode => 0644,
+ require => [
+ Package['httpd-devel']
+ ];
+ }
+
+ service { "httpd":
+ ensure => running,
+ enable => true,
+ require => [
+ Package['httpd-devel'],
+ File['/etc/httpd/conf.d/spade.conf']
+ ];
+ }
+
+ }
+ ubuntu: {
+ package { "apache2-dev":
+ ensure => present,
+ before => File['/etc/apache2/sites-available/spade.conf'];
+ }
+
+ file { "/etc/apache2/sites-available/spade.conf":
+ source => "$PROJ_DIR/puppet/files/etc/httpd/conf.d/spade.conf",
+ owner => "root", group => "root", mode => 0644,
+ require => [
+ Package['apache2-dev']
+ ];
+ }
+
+
+ exec {
+ 'a2enmod rewrite':
+ onlyif => 'test ! -e /etc/apache2/mods-enabled/rewrite.load';
+ 'a2enmod proxy':
+ onlyif => 'test ! -e /etc/apache2/mods-enabled/proxy.load';
+ }
+
+ exec { "enable-vhost":
+ command => "/usr/sbin/a2ensite spade.conf",
+ require => [ File["/etc/apache2/sites-available/spade.conf"]]
+ }
+ exec { "reload-apache2":
+ command => "/etc/init.d/apache2 reload",
+ refreshonly => true,
+ }
+
+ service { "apache2":
+ ensure => running,
+ enable => true,
+ require => [
+ Package['apache2-dev'],
+ File['/etc/apache2/sites-available/spade.conf']
+ ];
+ }
+ }
+ }
+}
@@ -0,0 +1,3 @@
+# You can add custom puppet manifests for your app here.
+class custom {
+}
@@ -0,0 +1,25 @@
+# stage {"pre": before => Stage["main"]} class {'apt': stage => 'pre'}
+
+# Commands to run before all others in puppet.
+class init {
+ group { "puppet":
+ ensure => "present",
+ }
+
+ case $operatingsystem {
+ ubuntu: {
+ exec { "update_apt":
+ command => "sudo apt-get update",
+ }
+
+ # Provides "add-apt-repository" command, useful if you need
+ # to install software from other apt repositories.
+ package { "python-software-properties":
+ ensure => present,
+ require => [
+ Exec['update_apt'],
+ ];
+ }
+ }
+ }
+}
@@ -0,0 +1,26 @@
+# Get mysql up and running
+class mysql {
+ package { "mysql-server":
+ ensure => installed;
+ }
+
+ case $operatingsystem {
+ centos: {
+ package { "mysql-devel":
+ ensure => installed;
+ }
+ }
+
+ ubuntu: {
+ package { "libmysqld-dev":
+ ensure => installed;
+ }
+ }
+ }
+
+ service { "mysql":
+ ensure => running,
+ enable => true,
+ require => Package['mysql-server'];
+ }
+}
@@ -0,0 +1,81 @@
+# Install python and compiled modules for project
+class python {
+ case $operatingsystem {
+ centos: {
+ package {
+ ["python26-devel", "python26-libs", "python26-distribute", "python26-mod_wsgi"]:
+ ensure => installed;
+ }
+
+ exec { "pip-install":
+ command => "easy_install -U pip",
+ creates => "/usr/bin/pip",
+ require => Package["python26-devel", "python26-distribute"]
+ }
+
+ exec { "virtualenv-install":
+ command => "/usr/bin/pip install -U virtualenv",
+ creates => "/usr/bin/virtualenv",
+ timeout => 600,
+ require => [ Exec['pip-install'] ]
+ }
+
+ exec {
+ "virtualenv-create":
+ cwd => "/home/vagrant",
+ user => "vagrant",
+ command => "/usr/bin/virtualenv --no-site-packages /home/vagrant/spade-venv",
+ creates => "/home/vagrant/spade-venv"
+ }
+
+ exec { "pip-install-compiled":
+ command => "/home/vagrant/spade-venv/bin/pip install -r $PROJ_DIR/requirements/compiled.txt",
+ require => Exec['virtualenv-create'],
+ timeout => 600,
+ }
+ }
+
+ ubuntu: {
+ package {
+ ["python2.6-dev", "python2.6", "python-distribute","libapache2-mod-wsgi", "python-wsgi-intercept", "libxml2-dev", "libxslt1-dev"]:
+ ensure => installed;
+ }
+
+ exec { "pip-install":
+ command => "/usr/bin/easy_install -U pip",
+ creates => "/usr/local/bin/pip",
+ require => Package["python-distribute"]
+ }
+ file { "$PROJ_DIR/puppet/cache/pip":
+ ensure => directory
+ }
+
+ exec { "virtualenv-install":
+ command => "/usr/local/bin/pip install --download-cache=$PROJ_DIR/puppet/cache/pip -U virtualenv",
+ creates => "/usr/local/bin/virtualenv",
+ timeout => 600,
+ require => [ Exec['pip-install'] ]
+ }
+
+ exec {
+ "virtualenv-create":
+ cwd => "/home/vagrant",
+ user => "vagrant",
+ command => "/usr/local/bin/virtualenv --no-site-packages /home/vagrant/spade-venv",
+ creates => "/home/vagrant/spade-venv"
+ }
+
+ exec {
+ "pip-cache-ownership":
+ command => "/bin/chown -R vagrant:vagrant $PROJ_DIR/puppet/cache/pip && /bin/chmod ug+rw -R $PROJ_DIR/puppet/cache/pip",
+ unless => '/bin/su vagrant -c "/usr/bin/test -w $PROJ_DIR/puppet/cache/pip"';
+ "pip-install-compiled":
+ require => Exec['pip-cache-ownership','virtualenv-create'],
+ user => "vagrant",
+ cwd => '/tmp',
+ command => "/home/vagrant/spade-venv/bin/pip install --download-cache=$PROJ_DIR/puppet/cache/pip -r $PROJ_DIR/requirements/compiled.txt",
+ timeout => 1200;
+ }
+ }
+ }
+}
@@ -0,0 +1,36 @@
+# TODO: Make this rely on things that are not straight-up exec.
+class spade{
+ file { "$PROJ_DIR/spade/settings/local.py":
+ ensure => file,
+ source => "$PROJ_DIR/spade/settings/local.sample.py",
+ replace => false;
+ }
+
+ exec { "create_mysql_database":
+ command => "mysql -uroot -B -e'CREATE DATABASE $DB_NAME CHARACTER SET utf8;'",
+ unless => "mysql -uroot -B --skip-column-names -e 'show databases' | /bin/grep '$DB_NAME'",
+ require => File["$PROJ_DIR/spade/settings/local.py"]
+ }
+
+ exec { "grant_mysql_database":
+ command => "mysql -uroot -B -e'GRANT ALL PRIVILEGES ON $DB_NAME.* TO $DB_USER@localhost # IDENTIFIED BY \"$DB_PASS\"'",
+ unless => "mysql -uroot -B --skip-column-names mysql -e 'select user from user' | grep '$DB_USER'",
+ require => Exec["create_mysql_database"];
+ }
+
+ exec { "syncdb":
+ cwd => "$PROJ_DIR",
+ command => "/home/vagrant/spade-venv/bin/python ./manage.py syncdb --noinput",
+ require => Exec["grant_mysql_database"];
+ }
+
+ exec { "sql_migrate":
+ cwd => "$PROJ_DIR",
+ command => "python ./vendor/src/schematic/schematic migrations/",
+ require => [
+ Service["mysql"],
+ Package["python2.6-dev", "libapache2-mod-wsgi", "python-wsgi-intercept" ],
+ Exec["syncdb"]
+ ];
+ }
+}
@@ -0,0 +1,28 @@
+#
+# Playdoh puppet magic for dev boxes
+#
+import "classes/*.pp"
+
+$PROJ_DIR = "/home/vagrant/project"
+
+# You can make these less generic if you like, but these are box-specific
+# so it's not required.
+$DB_NAME = "spade"
+$DB_USER = "root"
+
+Exec {
+ path => "/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin",
+}
+
+class dev {
+ class {
+ init: before => Class[mysql];
+ mysql: before => Class[python];
+ python: before => Class[apache];
+ apache: before => Class[spade];
+ spade: ;
+
+ }
+}
+
+include dev
View
@@ -0,0 +1,5 @@
+# Default config for Vagrant
+
+# Don't change this; use vagrantconfig_local.yaml to override these
+# settings instead.
+nfs: false

1 comment on commit 2cb76f2

Contributor

Nice!

Please sign in to comment.