Skip to content

Commit

Permalink
Merge branch 'hooked-on-sources-master'
Browse files Browse the repository at this point in the history
Conflicts:
	.gitignore
	.travis.yml
	chef/openaddr/recipes/default.rb
	openaddr/VERSION
	setup.py
	test.py
  • Loading branch information
migurski committed May 12, 2015
2 parents 7b0abea + d16cfa6 commit 3ab723e
Show file tree
Hide file tree
Showing 24 changed files with 1,070 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ venv?-*
state-*.txt
state-*.json
env-*
venv-hooked-on-sources
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ python:
- "3.3"
cache:
apt: true
addons:
postgresql: "9.3"
before_install:
# Although we include chef, we need to pre-install a number of dependencies
# to adapt to Travis Ubuntu apt sources and virtualenv environment.
Expand All @@ -22,6 +24,7 @@ install:
# http://stackoverflow.com/questions/11491268/install-pycairo-in-virtualenv
# https://pythonhosted.org/cairocffi/
- pip install cairocffi
- sudo chef/run.sh batchmode
- sudo chef/run.sh testing
- pip install -U .
env: DATABASE_URL=postgres://openaddr:openaddr@localhost/openaddr
script: python setup.py test
2 changes: 2 additions & 0 deletions chef/Procfile-webhook
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: gunicorn -w 4 --bind 0.0.0.0:$PORT openaddr.ci:app
dequeue: python -m openaddr.ci.run_dequeue
1 change: 1 addition & 0 deletions chef/Procfile-worker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
worker: openaddr-ci-worker
13 changes: 13 additions & 0 deletions chef/account/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name = node[:username]

group name
user name do
gid name
home "/home/#{name}"
end

directory "/home/#{name}" do
owner name
group name
mode "0755"
end
23 changes: 23 additions & 0 deletions chef/apache/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package 'apache2'

file '/etc/apache2/sites-available/webhook.conf' do
content <<-CONF
<VirtualHost *:80>
<Location />
ProxyPass http://127.0.0.1:5000/
ProxyPassReverse http://127.0.0.1:5000/
</Location>
<Proxy http://127.0.0.1:5000/*>
Allow from all
</Proxy>
</VirtualHost>
CONF
end

execute 'a2enmod proxy'
execute 'a2enmod proxy_http'

execute 'a2ensite webhook'
execute 'a2dissite 000-default'

execute 'service apache2 reload'
33 changes: 33 additions & 0 deletions chef/database/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package 'postgresql'

user = node[:db_user]
pass = node[:db_pass]
host = node[:db_host]
name = node[:db_name]
database_url = "postgres://#{user}:#{pass}@#{host}/#{name}?sslmode=require"

if host == 'localhost' then
args = ''
else
args = "-h '#{host}'"
end

bash "create database" do
user 'postgres'
environment({'DATABASE_URL' => database_url, 'GITHUB_TOKEN' => ''})
code <<-CODE
# psql #{args} -c "DROP DATABASE IF EXISTS #{name}";
# psql #{args} -c "DROP USER IF EXISTS #{user}";
psql #{args} -c "CREATE USER #{user} WITH SUPERUSER PASSWORD '#{pass}'";
psql #{args} -c "CREATE DATABASE #{name} WITH OWNER #{user}";
openaddr-ci-recreate-db
CODE

# Stop as soon as an error is encountered.
flags '-e'

# Assume that exit=1 means the user and database were already in-place.
returns [0, 1]
end
1 change: 1 addition & 0 deletions chef/openaddr/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package 'python-gdal'
package 'python-pip'
package 'python-dev'
package 'libpq-dev'

execute "pip install -U ." do
cwd File.join(File.dirname(__FILE__), '..', '..', '..')
Expand Down
11 changes: 11 additions & 0 deletions chef/role-database.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"db_user": "openaddr",
"db_pass": "openaddr",
"db_host": "localhost",
"db_name": "openaddr",
"run_list":
[
"openaddr",
"database"
]
}
16 changes: 16 additions & 0 deletions chef/role-testing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"username": "openaddr",
"db_user": "openaddr",
"db_pass": "openaddr",
"db_host": "localhost",
"db_name": "openaddr",
"github_token": "fake-token",
"run_list":
[
"openaddr",
"database",
"account",
"webhooks",
"sources"
]
}
15 changes: 15 additions & 0 deletions chef/role-webhooks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"username": "openaddr",
"db_user": "openaddr",
"db_pass": "openaddr",
"db_host": "localhost",
"db_name": "openaddr",
"github_token": "{Github Token}",
"run_list":
[
"openaddr",
"account",
"webhooks",
"apache"
]
}
14 changes: 14 additions & 0 deletions chef/role-worker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"username": "openaddr",
"db_user": "openaddr",
"db_pass": "openaddr",
"db_host": "localhost",
"db_name": "openaddr",
"github_token": "{Github Token}",
"run_list":
[
"openaddr",
"account",
"worker"
]
}
59 changes: 59 additions & 0 deletions chef/webhooks/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
username = node[:username]
app_name = 'openaddr_webhook'

db_user = node[:db_user]
db_pass = node[:db_pass]
db_host = node[:db_host]
db_name = node[:db_name]

database_url = "postgres://#{db_user}:#{db_pass}@#{db_host}/#{db_name}?sslmode=require"
github_token = node['github_token']

env_file = "/etc/#{app_name}.conf"
procfile = File.join(File.dirname(__FILE__), '..', '..', 'Procfile-webhook')

execute 'pip install honcho[export]'

#
# Ensure upstart job exists.
#
file env_file do
content <<-CONF
DATABASE_URL=#{database_url}
GITHUB_TOKEN=#{github_token}
CONF
end

execute "honcho export upstart /etc/init" do
command "honcho -e #{env_file} -f #{procfile} export -u #{username} -a #{app_name} upstart /etc/init"
end

rotation = <<-ROTATION
{
copytruncate
rotate 4
weekly
missingok
notifempty
compress
delaycompress
endscript
}
ROTATION

file "/etc/logrotate.d/#{app_name}-web-1" do
content "/var/log/#{app_name}/web-1.log\n#{rotation}\n"
end

file "/etc/logrotate.d/#{app_name}-dequeue-1" do
content "/var/log/#{app_name}/dequeue-1.log\n#{rotation}\n"
end

#
# Make it go.
#
execute "stop #{app_name}" do
returns [0, 1]
end

execute "start #{app_name}"
55 changes: 55 additions & 0 deletions chef/worker/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
username = node[:username]
app_name = 'openaddr_worker'

db_user = node[:db_user]
db_pass = node[:db_pass]
db_host = node[:db_host]
db_name = node[:db_name]

database_url = "postgres://#{db_user}:#{db_pass}@#{db_host}/#{db_name}?sslmode=require"
github_token = node['github_token']

env_file = "/etc/#{app_name}.conf"
procfile = File.join(File.dirname(__FILE__), '..', '..', 'Procfile-worker')

execute 'pip install honcho[export]'

#
# Ensure upstart job exists.
#
file env_file do
content <<-CONF
DATABASE_URL=#{database_url}
GITHUB_TOKEN=#{github_token}
CONF
end

execute "honcho export upstart /etc/init" do
command "honcho -e #{env_file} -f #{procfile} export -u #{username} -a #{app_name} upstart /etc/init"
end

rotation = <<-ROTATION
{
copytruncate
rotate 4
weekly
missingok
notifempty
compress
delaycompress
endscript
}
ROTATION

file "/etc/logrotate.d/#{app_name}-worker-1" do
content "/var/log/#{app_name}/worker-1.log\n#{rotation}\n"
end

#
# Make it go.
#
execute "stop #{app_name}" do
returns [0, 1]
end

execute "start #{app_name}"
2 changes: 1 addition & 1 deletion openaddr/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.1
1.7.1
Loading

0 comments on commit 3ab723e

Please sign in to comment.