Skip to content

Commit 2001057

Browse files
committedJan 18, 2012
Adds a basic Vagrant image for Zamboni (bug 689755)
1 parent bf66c8e commit 2001057

14 files changed

+453
-1
lines changed
 

‎.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
settings_local.py
1+
settings_local.py*
22
*.py[co]
33
*.sw[po]
44
.coverage
@@ -22,3 +22,6 @@ vendor
2222
.nose*
2323
tmp/*
2424
tags
25+
vagrantconfig_local.yaml
26+
vagrant/manifests/classes/custom.pp
27+
vagrant/manifests/build

‎Vagrantfile

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require "yaml"
2+
3+
# Load up our vagrant config files -- vagrantconfig.yaml first
4+
_config = YAML.load(File.open(File.join(File.dirname(__FILE__),
5+
"vagrantconfig.yaml"), File::RDONLY).read)
6+
7+
# Local-specific/not-git-managed config -- vagrantconfig_local.yaml
8+
begin
9+
_config.merge!(YAML.load(File.open(File.join(File.dirname(__FILE__),
10+
"vagrantconfig_local.yaml"), File::RDONLY).read))
11+
rescue Errno::ENOENT # No vagrantconfig_local.yaml found -- that's OK; just
12+
# use the defaults.
13+
end
14+
15+
CONF = _config
16+
MOUNT_POINT = '/home/vagrant/project'
17+
18+
Vagrant::Config.run do |config|
19+
config.vm.box = "zamboni"
20+
config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
21+
22+
# TODO(Kumar) figure out a way to forward port 80, as requested from the
23+
# guest, to 8000 on the host. This apparently doesn't do that :/
24+
config.vm.forward_port("web", 80, 8000)
25+
26+
# Increase vagrant's patience during hang-y CentOS bootup
27+
# see: https://github.com/jedi4ever/veewee/issues/14
28+
config.ssh.max_tries = 50
29+
config.ssh.timeout = 300
30+
31+
# nfs needs to be explicitly enabled to run.
32+
if CONF['nfs'] == false or RUBY_PLATFORM =~ /mswin(32|64)/
33+
config.vm.share_folder("v-root", MOUNT_POINT, ".")
34+
else
35+
config.vm.share_folder("v-root", MOUNT_POINT, ".", :nfs => true)
36+
end
37+
38+
# For convenience add something like this to /etc/hosts: 33.33.33.24 z.local
39+
config.vm.network "33.33.33.24"
40+
41+
config.vm.provision :puppet do |puppet|
42+
puppet.manifests_path = "vagrant/manifests"
43+
puppet.manifest_file = "vagrant.pp"
44+
end
45+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# HACK: Make the server reload after every hit to refresh django code
2+
# MaxRequestsPerChild 1
3+
4+
WSGISocketPrefix /var/run/wsgi
5+
6+
<VirtualHost 33.33.33.24:443 33.33.33.24:80>
7+
ServerName 33.33.33.24
8+
9+
DirectoryIndex index.php index.html
10+
Options -Indexes
11+
12+
DocumentRoot "/home/vagrant/project"
13+
14+
Alias /media/ "/home/vagrant/project/media/"
15+
Alias /admin-media/ "/home/vagrant/project/vendor/src/django/django/contrib/admin/media/"
16+
17+
WSGIDaemonProcess playdoh processes=2 threads=2 maximum-requests=4
18+
WSGIProcessGroup playdoh
19+
20+
WSGIScriptAlias / "/home/vagrant/project/wsgi/zamboni.wsgi"
21+
</VirtualHost>

‎vagrant/manifests/classes/apache.pp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Red Hat, CentOS, and Fedora think Apache is the only web server
2+
# ever, so we have to use a different package on CentOS than Ubuntu.
3+
class apache {
4+
case $operatingsystem {
5+
centos: {
6+
package { "httpd-devel":
7+
ensure => present,
8+
before => File['/etc/httpd/conf.d/zamboni.conf'];
9+
}
10+
11+
file { "/etc/httpd/conf.d/zamboni.conf":
12+
source => "$PROJ_DIR/vagrant/files/etc/httpd/conf.d/zamboni.conf",
13+
owner => "root", group => "root", mode => 0644,
14+
require => [
15+
Package['httpd-devel']
16+
];
17+
}
18+
19+
service { "httpd":
20+
ensure => running,
21+
enable => true,
22+
require => [
23+
Package['httpd-devel'],
24+
File['/etc/httpd/conf.d/zamboni.conf']
25+
];
26+
}
27+
28+
}
29+
ubuntu: {
30+
package { "apache2-threaded-dev":
31+
ensure => present,
32+
before => File['/etc/apache2/sites-enabled/zamboni.conf'];
33+
}
34+
35+
file { "/etc/apache2/sites-enabled/zamboni.conf":
36+
source => "$PROJ_DIR/vagrant/files/etc/httpd/conf.d/zamboni.conf",
37+
owner => "root", group => "root", mode => 0644,
38+
require => [
39+
Package['apache2-threaded-dev']
40+
];
41+
}
42+
43+
# DISABLED, using dev server instead.
44+
service { "apache2":
45+
ensure => stopped,
46+
enable => false,
47+
require => [
48+
Package['apache2-threaded-dev'],
49+
File['/etc/apache2/sites-enabled/zamboni.conf']
50+
];
51+
}
52+
}
53+
}
54+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copy this file to custom.pp and declare any commands you want to run on your
2+
# local machine only. Anything you add to custom.pp will *not* be committed to
3+
# version control.
4+
class custom {
5+
# exec { "install-nosenicedots":
6+
# command => "sudo pip install nosenicedots",
7+
# require => Package['python-pip']
8+
# }
9+
}
+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
# Based loosely on https://gist.github.com/1190526
3+
# This can probably be simplified when there is a deb package for ES.
4+
5+
class elasticsearch {
6+
7+
## NOTE: moved to init.pp so that we don't get a huge pile of updates to
8+
## previously installed packages
9+
10+
# exec { "add_java_repo":
11+
# # For sun java:
12+
# command => 'sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"',
13+
# require => Package["python-software-properties"]
14+
# }
15+
#
16+
# exec { "init_java_repo":
17+
# command => "sudo apt-get update",
18+
# require => Exec['add_java_repo']
19+
# }
20+
21+
exec { "accept_jre_license":
22+
command => "echo 'sun-java6-jre shared/accepted-sun-dlj-v1-1 boolean true' | sudo debconf-set-selections",
23+
require => Exec["init_java_repo"]
24+
}
25+
26+
exec { "accept_java_license":
27+
command => "echo 'sun-java6-bin shared/accepted-sun-dlj-v1-1 boolean true' | sudo debconf-set-selections",
28+
require => Exec["init_java_repo"]
29+
}
30+
31+
exec { "accept_java_plugin_license":
32+
command => "echo 'sun-java6-plugin shared/accepted-sun-dlj-v1-1 boolean true' | sudo debconf-set-selections",
33+
require => Exec["init_java_repo"]
34+
}
35+
36+
package {
37+
["sun-java6-jre", "sun-java6-bin", "sun-java6-plugin", "curl"]:
38+
ensure => installed,
39+
require => [
40+
Exec["accept_jre_license"],
41+
Exec["accept_java_plugin_license"],
42+
Exec["accept_java_license"]
43+
];
44+
}
45+
46+
exec { "get_source":
47+
cwd => "/tmp",
48+
command => 'wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.17.6.tar.gz -O elasticsearch.tar.gz',
49+
unless => 'test -d /usr/local/share/elasticsearch'
50+
}
51+
52+
exec { "untar":
53+
cwd => "/tmp",
54+
command => 'tar -xzf elasticsearch.tar.gz',
55+
require => Exec["get_source"],
56+
unless => 'test -d /usr/local/share/elasticsearch'
57+
}
58+
59+
exec { "move_source":
60+
cwd => "/tmp",
61+
command => 'sudo mv elasticsearch-* /usr/local/share/elasticsearch',
62+
require => Exec["untar"],
63+
unless => 'test -d /usr/local/share/elasticsearch'
64+
}
65+
66+
exec { "get_service":
67+
cwd => "/tmp",
68+
command => 'curl -L http://github.com/elasticsearch/elasticsearch-servicewrapper/tarball/master | tar -xz',
69+
require => [Package["curl"], Exec["move_source"]],
70+
unless => 'test -d /usr/local/share/elasticsearch/bin/service'
71+
}
72+
73+
exec { "move_service":
74+
cwd => "/tmp",
75+
command => 'sudo mv *servicewrapper*/service /usr/local/share/elasticsearch/bin/',
76+
require => [Exec["get_service"], Exec["move_source"]],
77+
unless => 'test -d /usr/local/share/elasticsearch/bin/service'
78+
}
79+
80+
exec { "install_service":
81+
# Makes /etc/init.d/elasticsearch
82+
command => 'sudo /usr/local/share/elasticsearch/bin/service/elasticsearch install',
83+
# Install if service is not already running.
84+
unless => 'test `cat /usr/local/share/elasticsearch/bin/service/elasticsearch.java.status` = STARTED',
85+
require => [
86+
Exec["move_service"],
87+
Package["sun-java6-jre", "sun-java6-bin", "sun-java6-plugin", "curl"]
88+
]
89+
}
90+
91+
service { "elasticsearch":
92+
enable => true,
93+
ensure => "running",
94+
require => Exec["install_service"]
95+
}
96+
}

‎vagrant/manifests/classes/init.pp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# stage {"pre": before => Stage["main"]} class {'apt': stage => 'pre'}
2+
3+
# Commands to run before all others in puppet.
4+
class init {
5+
group { "puppet":
6+
ensure => "present",
7+
}
8+
9+
case $operatingsystem {
10+
ubuntu: {
11+
exec { "update_apt":
12+
command => "sudo apt-get update"
13+
}
14+
15+
# Provides "add-apt-repository" command, useful if you need
16+
# to install software from other apt repositories.
17+
package { "python-software-properties":
18+
ensure => present,
19+
require => [
20+
Exec['update_apt'],
21+
];
22+
}
23+
24+
exec { "add_java_repo":
25+
# For sun java:
26+
command => 'sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"',
27+
require => Package["python-software-properties"]
28+
}
29+
30+
exec { "init_java_repo":
31+
# Bah, this is lame.
32+
command => "sudo apt-get update",
33+
require => Exec['add_java_repo']
34+
}
35+
}
36+
}
37+
38+
# If you haven't created a custom pp file, create one from dist.
39+
file { "$PROJ_DIR/vagrant/manifests/classes/custom.pp":
40+
ensure => file,
41+
source => "$PROJ_DIR/vagrant/manifests/classes/custom-dist.pp",
42+
replace => false;
43+
}
44+
}

‎vagrant/manifests/classes/mysql.pp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Get mysql up and running
2+
class mysql {
3+
package { "mysql-server":
4+
ensure => installed;
5+
}
6+
7+
case $operatingsystem {
8+
centos: {
9+
package { "mysql-devel":
10+
ensure => installed;
11+
}
12+
}
13+
14+
ubuntu: {
15+
package { "libmysqld-dev":
16+
ensure => installed;
17+
}
18+
}
19+
}
20+
21+
service { "mysql":
22+
ensure => running,
23+
enable => true,
24+
require => Package['mysql-server'];
25+
}
26+
}

‎vagrant/manifests/classes/python.pp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Install python and compiled modules for project
2+
class python {
3+
package {
4+
["python2.6-dev", "python2.6", "libapache2-mod-wsgi", "python-pip",
5+
"libxml2-dev", "libxslt1-dev", "libssl-dev", "swig", "git-core"]:
6+
ensure => installed;
7+
}
8+
9+
# Bah. Ubuntu moves at the speed of molasses.
10+
# Need the fix for exit statuses: https://github.com/pypa/pip/issues/106
11+
exec { "upgrade_pip":
12+
command => "sudo easy_install -U pip",
13+
require => Package['python-pip']
14+
}
15+
16+
exec { "pip-install-compiled":
17+
command => "sudo pip install -r $PROJ_DIR/requirements/compiled.txt",
18+
require => [
19+
Exec["upgrade_pip"],
20+
Package["python2.6", "libxml2-dev", "libxslt1-dev", "libssl-dev", "swig"]
21+
]
22+
}
23+
}

‎vagrant/manifests/classes/redis.pp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class redis {
2+
package { "redis-server":
3+
ensure => installed;
4+
}
5+
6+
service { "redis-server":
7+
ensure => running,
8+
enable => true,
9+
hasrestart => true,
10+
require => [
11+
Package['redis-server']
12+
]
13+
}
14+
}

‎vagrant/manifests/classes/zamboni.pp

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# playdoh-specific commands that get zamboni all going so you don't
2+
# have to.
3+
4+
# TODO: Make this rely on things that are not straight-up exec.
5+
class zamboni {
6+
package { "wget":
7+
ensure => installed;
8+
}
9+
10+
file { "$PROJ_DIR/settings_local.py":
11+
ensure => file,
12+
source => "$PROJ_DIR/settings_local.py",
13+
replace => false;
14+
}
15+
16+
exec { "create_mysql_database":
17+
command => "mysqladmin -uroot create $DB_NAME",
18+
unless => "mysql -uroot -B --skip-column-names -e 'show databases' | /bin/grep '$DB_NAME'",
19+
require => File["$PROJ_DIR/settings_local.py"]
20+
}
21+
22+
exec { "grant_mysql_database":
23+
command => "mysql -uroot -B -e'GRANT ALL PRIVILEGES ON $DB_NAME.* TO $DB_USER@localhost # IDENTIFIED BY \"$DB_PASS\"'",
24+
unless => "mysql -uroot -B --skip-column-names mysql -e 'select user from user' | grep '$DB_USER'",
25+
require => Exec["create_mysql_database"];
26+
}
27+
28+
exec { "fetch_landfill_sql":
29+
cwd => "$PROJ_DIR",
30+
command => "wget --no-check-certificate -P /tmp https://landfill.addons.allizom.org/db/landfill-`date +%Y-%m-%d`.sql.gz",
31+
require => [
32+
Package["wget"],
33+
Exec["grant_mysql_database"]
34+
];
35+
}
36+
37+
exec { "load_data":
38+
cwd => "$PROJ_DIR",
39+
command => "zcat /tmp/landfill-`date +%Y-%m-%d`.sql.gz | mysql -u$DB_USER $DB_NAME",
40+
require => [
41+
Exec["fetch_landfill_sql"]
42+
];
43+
}
44+
45+
# TODO(Kumar) add landfile files as well.
46+
47+
# Skip this migration because it won't succeed without indexes but you
48+
# can't build indexes without running migrations :(
49+
file { "$PROJ_DIR/migrations/264-locale-indexes.py":
50+
content => "#",
51+
replace => true
52+
}
53+
54+
exec { "sql_migrate":
55+
cwd => "$PROJ_DIR",
56+
command => "python ./vendor/src/schematic/schematic migrations/",
57+
require => [
58+
Service["mysql"],
59+
Package["python2.6"],
60+
File["$PROJ_DIR/migrations/264-locale-indexes.py"],
61+
Exec["fetch_landfill_sql"],
62+
Exec["load_data"]
63+
];
64+
}
65+
66+
exec { "restore_migration_264":
67+
cwd => "$PROJ_DIR",
68+
command => "git checkout migrations/264-locale-indexes.py",
69+
require => [Exec["sql_migrate"], Package["git-core"]]
70+
}
71+
72+
exec { "remove_site_notice":
73+
command => "mysql -uroot -e\"delete from config where \\`key\\`='site_notice'\" $DB_NAME",
74+
require => Exec["sql_migrate"]
75+
}
76+
}

‎vagrant/manifests/vagrant.pp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Playdoh puppet magic for dev boxes
3+
#
4+
import "classes/*.pp"
5+
6+
$PROJ_DIR = "/home/vagrant/project"
7+
8+
# You can make these less generic if you like, but these are box-specific
9+
# so it's not required.
10+
# The db user does not require a password.
11+
$DB_NAME = "zamboni"
12+
$DB_USER = "root"
13+
14+
Exec {
15+
path => "/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin",
16+
}
17+
18+
class dev {
19+
class {
20+
init: before => Class[mysql];
21+
mysql: before => Class[python];
22+
python: before => Class[redis];
23+
# apache: before => Class[zamboni];
24+
redis: before => Class[zamboni];
25+
elasticsearch: ;
26+
zamboni: ;
27+
custom: ;
28+
}
29+
}
30+
31+
include dev

‎vagrantconfig.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Default config for Vagrant
2+
3+
# Don't change this; use vagrantconfig_local.yaml to override these
4+
# settings instead.
5+
nfs: false

‎vagrantconfig_local.yaml-dist

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Configuration for Vagrant
2+
3+
# Change to true if you can use nfs; using nfs significantly
4+
# improves performance.
5+
nfs: false

0 commit comments

Comments
 (0)
Please sign in to comment.