freighthop 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,50 @@
1
+ require 'pathname'
2
+ require_relative 'freighthop/version'
3
+
4
+ unless defined? Vagrant
5
+ raise "i expect to be required from a Vagrantfile"
6
+ end
7
+
8
+ module Freighthop
9
+ class << self
10
+ def vmware?
11
+ !!(defined? HashiCorp)
12
+ end
13
+
14
+ def host_rails_root
15
+ @rails_root ||= begin
16
+ Pathname.pwd.tap do |pwd|
17
+ unless pwd.join('config', 'boot.rb').file?
18
+ raise 'run me with a rails app as PWD, using VAGRANT_CWD to refer to my directory'
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def guest_rails_root
25
+ "/srv/#{app_name}"
26
+ end
27
+
28
+ def app_name
29
+ @app_name ||= host_rails_root.basename.to_s
30
+ end
31
+
32
+ def hostname
33
+ "#{app_name}.vagrant.dev"
34
+ end
35
+
36
+ def ip_address
37
+ "10.20.1.#{app_name.getbyte(0)}"
38
+ end
39
+
40
+ def box_url
41
+ if vmware?
42
+ 'http://files.vagrantup.com/precise64_vmware.box'
43
+ else
44
+ 'http://files.vagrantup.com/precise64.box'
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+
@@ -0,0 +1,3 @@
1
+ module Freighthop
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ eval(File.read('Gemfile'))
2
+
3
+ gem 'puma'
@@ -0,0 +1,31 @@
1
+ # /etc/init/puma-manager.conf - manage a set of Pumas
2
+
3
+ # This example config should work with Ubuntu 12.04+. It
4
+ # allows you to manage multiple Puma instances with
5
+ # Upstart, Ubuntu's native service management tool.
6
+ #
7
+ # See puma.conf for how to manage a single Puma instance.
8
+ #
9
+ # Use "stop puma-manager" to stop all Puma instances.
10
+ # Use "start puma-manager" to start all instances.
11
+ # Use "restart puma-manager" to restart all instances.
12
+ # Crazy, right?
13
+ #
14
+
15
+ description "Manages the set of puma processes"
16
+
17
+ # This starts upon bootup and stops on shutdown
18
+ start on runlevel [2345]
19
+ stop on runlevel [06]
20
+
21
+ # Set this to the number of Puma processes you want
22
+ # to run on this machine
23
+ env PUMA_CONF="/etc/puma.conf"
24
+
25
+ pre-start script
26
+ for i in `cat $PUMA_CONF`; do
27
+ app=`echo $i | cut -d , -f 1`
28
+ logger -t "puma-manager" "Starting $app"
29
+ start puma app=$app
30
+ done
31
+ end script
@@ -0,0 +1,34 @@
1
+ class freighthop::bundler(
2
+ $ruby_version,
3
+ $app_root,
4
+ ){
5
+ file { "${app_root}/.freighthop.gemfile":
6
+ ensure => 'file',
7
+ mode => '0644',
8
+ source => 'puppet:///modules/freighthop/bundler/freighthop.gemfile',
9
+ }
10
+
11
+ file { '/etc/profile.d/custom_bundler_gemfile.sh':
12
+ ensure => present,
13
+ mode => '0755',
14
+ content => template('freighthop/profile/custom_bundler_gemfile.sh.erb'),
15
+ }
16
+
17
+ exec { 'bundle install':
18
+ environment => [
19
+ 'BUNDLE_GEMFILE=.freighthop.gemfile',
20
+ 'RBENV_ROOT=/usr/lib/rbenv',
21
+ "RBENV_VERSION=${ruby_version}",
22
+ ],
23
+ cwd => $app_root,
24
+ path => [
25
+ '/usr/lib/rbenv/shims',
26
+ '/usr/bin',
27
+ '/bin',
28
+ ],
29
+ logoutput => true,
30
+ timeout => 0,
31
+ unless => 'bundle check',
32
+ require => File["${app_root}/.freighthop.gemfile"],
33
+ }
34
+ }
@@ -0,0 +1,55 @@
1
+ class freighthop(
2
+ $databases,
3
+ $database_users,
4
+ $packages = ['git-core'],
5
+ $ruby_version = $freighthop::params::ruby_version,
6
+ $app_name = $freighthop::params::app_name,
7
+ $app_root = $freighthop::params::app_root,
8
+ $web_root = $freighthop::params::web_root,
9
+ $socket_dir = $freighthop::params::socket_dir,
10
+ $socket_path = $freighthop::params::socket_path,
11
+ $server_name = $freighthop::params::server_name,
12
+ $ssl_cert_path = $freighthop::params::ssl_cert_path,
13
+ $ssl_key_path = $freighthop::params::ssl_key_path,
14
+ ) inherits freighthop::params {
15
+ file { $socket_dir:
16
+ ensure => directory,
17
+ owner => 'vagrant',
18
+ group => 'vagrant',
19
+ mode => '0755'
20
+ }
21
+ class { 'freighthop::pkgs':
22
+ packages => $packages,
23
+ }
24
+ class { 'freighthop::rbenv':
25
+ ruby_version => $ruby_version
26
+ }
27
+ class { 'freighthop::nginx':
28
+ upstream_socket_path => $socket_path,
29
+ server_name => $server_name,
30
+ web_root => $web_root,
31
+ ssl_cert_path => $ssl_cert_path,
32
+ ssl_key_path => $ssl_key_path,
33
+ }
34
+ class { 'freighthop::postgres':
35
+ databases => $databases,
36
+ database_users => $database_users,
37
+ }
38
+ class { 'freighthop::bundler':
39
+ ruby_version => $ruby_version,
40
+ app_root => $app_root,
41
+ }
42
+ class { 'freighthop::puma':
43
+ app_root => $app_root,
44
+ socket_path => $socket_path,
45
+ }
46
+
47
+ File[$socket_dir] ->
48
+ Class['freighthop::pkgs'] ->
49
+ Class['freighthop::rbenv'] ->
50
+ Class['freighthop::nginx'] ->
51
+ Class['freighthop::postgres'] ->
52
+ Class['freighthop::bundler'] ->
53
+ Class['freighthop::puma']
54
+
55
+ }
@@ -0,0 +1,28 @@
1
+ class freighthop::nginx(
2
+ $upstream_socket_path,
3
+ $server_name,
4
+ $web_root,
5
+ $ssl_cert_path,
6
+ $ssl_key_path,
7
+ ) {
8
+ $cert_subject = "/C=US/ST=IL/L=Chicago/O=Instructure/CN=${server_name}"
9
+
10
+ class {'::nginx':
11
+ confd_purge => true
12
+ }
13
+
14
+ exec { 'generate-self-signed-ssl-cert':
15
+ command => "openssl req -x509 -nodes -days 3650 -subj '${cert_subject}' -newkey rsa:1024 -keyout ${ssl_key_path} -out ${ssl_cert_path}",
16
+ path => ['/usr/bin'],
17
+ creates => $ssl_cert_path,
18
+ }
19
+
20
+ file { '/etc/nginx/conf.d/vagrant-rails.conf':
21
+ owner => 'root',
22
+ group => 'root',
23
+ mode => '0644',
24
+ content => template('freighthop/nginx/vagrant-rails.conf.erb'),
25
+ notify => Service['nginx'],
26
+ require => Exec['generate-self-signed-ssl-cert'],
27
+ }
28
+ }
@@ -0,0 +1,11 @@
1
+ class freighthop::params {
2
+ $ruby_version = '1.9.3-p392'
3
+ $app_name = $::hostname
4
+ $app_root = "/srv/${app_name}"
5
+ $web_root = "${app_root}/public"
6
+ $socket_dir = "/var/run/${app_name}"
7
+ $socket_path = "${socket_dir}/puma.sock"
8
+ $server_name = $::fqdn
9
+ $ssl_cert_path = "/etc/ssl/certs/${app_name}.pem"
10
+ $ssl_key_path = "/etc/ssl/private/${app_name}.key"
11
+ }
@@ -0,0 +1,7 @@
1
+ class freighthop::pkgs(
2
+ $packages
3
+ ) {
4
+ package { $packages:
5
+ ensure => installed
6
+ }
7
+ }
@@ -0,0 +1,28 @@
1
+ class freighthop::postgres(
2
+ $databases,
3
+ $database_users
4
+ ) {
5
+ include postgresql::server
6
+
7
+ postgresql::pg_hba_rule { 'local-users-get-everything':
8
+ type => 'local',
9
+ database => 'all',
10
+ user => 'all',
11
+ auth_method => 'trust',
12
+ order => '0001',
13
+ }
14
+ postgresql::pg_hba_rule { 'local-host-connections-get-everything':
15
+ type => 'host',
16
+ database => 'all',
17
+ user => 'all',
18
+ address => '127.0.0.1/32',
19
+ auth_method => 'trust',
20
+ order => '0001',
21
+ }
22
+ postgresql::database { $databases: }
23
+ postgresql::database_user { $database_users:
24
+ superuser => true,
25
+ createdb => true,
26
+ createrole => true,
27
+ }
28
+ }
@@ -0,0 +1,36 @@
1
+ class freighthop::puma(
2
+ $app_root,
3
+ $socket_path,
4
+ ) {
5
+ package { 'puma':
6
+ ensure => 'installed',
7
+ provider => 'gem'
8
+ }
9
+ file { '/etc/init/puma.conf':
10
+ owner => 'root',
11
+ group => 'root',
12
+ mode => '0644',
13
+ content => template('freighthop/puma/upstart/puma.conf.erb')
14
+ }
15
+ file { '/etc/puma.conf':
16
+ owner => 'root',
17
+ group => 'root',
18
+ mode => '0644',
19
+ content => "${app_root}\n"
20
+ }
21
+ file { '/etc/init/puma-manager.conf':
22
+ owner => 'root',
23
+ group => 'root',
24
+ mode => '0644',
25
+ source => 'puppet:///modules/freighthop/puma/upstart/puma-manager.conf',
26
+ require => [
27
+ File['/etc/init/puma.conf'],
28
+ File['/etc/puma.conf'],
29
+ ],
30
+ notify => Service['puma-manager']
31
+ }
32
+ service { 'puma-manager':
33
+ ensure => 'running',
34
+ provider => 'upstart'
35
+ }
36
+ }
@@ -0,0 +1,34 @@
1
+ class freighthop::rbenv(
2
+ $ruby_version
3
+ ) {
4
+ include apt
5
+ apt::ppa { 'ppa:gds/govuk': }
6
+ apt::ppa { 'ppa:phinze/rbenv': }
7
+
8
+ class { '::rbenv':
9
+ global_version => $ruby_version,
10
+ require => Apt::Ppa['ppa:gds/govuk'],
11
+ }
12
+
13
+ rbenv::version { $ruby_version: }
14
+
15
+ # The rbenv puppet module drops $RBENV_ROOT/version but the package from
16
+ # ppa:gds/govuk is an older version of rbenv that expects $RBENV_ROOT/global;
17
+ # this is a workaround that uses the installed CLI to fix it.
18
+ exec { 'fix-rbenv-global-version':
19
+ command => "rbenv global ${ruby_version}",
20
+ unless => "rbenv global | grep '${ruby_version}'",
21
+ environment => 'RBENV_ROOT=/usr/lib/rbenv',
22
+ require => Rbenv::Version[$ruby_version]
23
+ }
24
+
25
+ Exec {
26
+ path => [
27
+ '/usr/local/bin',
28
+ '/usr/bin',
29
+ '/usr/sbin',
30
+ '/bin',
31
+ '/sbin',
32
+ ]
33
+ }
34
+ }
@@ -0,0 +1,9 @@
1
+ class freighthop::redis {
2
+ package { 'redis-server':
3
+ ensure => installed
4
+ }
5
+ service { 'redis-server':
6
+ ensure => running,
7
+ require => Package['redis-server']
8
+ }
9
+ }
@@ -0,0 +1,89 @@
1
+ upstream app_server {
2
+ # fail_timeout=0 means we always retry an upstream even if it failed
3
+ # to return a good HTTP response (in case the Unicorn master nukes a
4
+ # single worker for timing out).
5
+ server unix:<%= upstream_socket_path %> fail_timeout=0;
6
+ }
7
+
8
+ server {
9
+ listen 80 default deferred; # for Linux
10
+
11
+ client_max_body_size 4G;
12
+ server_name <%= server_name %>;
13
+
14
+ keepalive_timeout 5;
15
+
16
+ # path for static files
17
+ root <%= web_root %>;
18
+
19
+ # Prefer to serve static files directly from nginx to avoid unnecessary
20
+ # data copies from the application server.
21
+ try_files $uri/index.html $uri.html $uri @app;
22
+
23
+ location @app {
24
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
25
+
26
+ # enable this if you forward HTTPS traffic to unicorn,
27
+ # this helps Rack set the proper URL scheme for doing redirects:
28
+ proxy_set_header X-Forwarded-Proto $scheme;
29
+
30
+ # pass the Host: header from the client right along so redirects
31
+ # can be set properly within the Rack application
32
+ proxy_set_header Host $http_host;
33
+
34
+ # we don't want nginx trying to do something clever with
35
+ # redirects, we set the Host: header above already.
36
+ proxy_redirect off;
37
+
38
+ proxy_pass http://app_server;
39
+ }
40
+
41
+ # Rails error pages
42
+ error_page 500 502 503 504 /500.html;
43
+ location = /500.html {
44
+ root <%= web_root %>;
45
+ }
46
+ }
47
+
48
+ server {
49
+ listen 443;
50
+ client_max_body_size 4G;
51
+ server_name <%= server_name %>;
52
+
53
+ keepalive_timeout 5;
54
+
55
+ # path for static files
56
+ root <%= web_root %>;
57
+
58
+ ssl on;
59
+ ssl_certificate <%= ssl_cert_path %>;
60
+ ssl_certificate_key <%= ssl_key_path %>;
61
+
62
+ # Prefer to serve static files directly from nginx to avoid unnecessary
63
+ # data copies from the application server.
64
+ try_files $uri/index.html $uri.html $uri @app;
65
+
66
+ location @app {
67
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
68
+
69
+ # enable this if you forward HTTPS traffic to unicorn,
70
+ # this helps Rack set the proper URL scheme for doing redirects:
71
+ proxy_set_header X-Forwarded-Proto $scheme;
72
+
73
+ # pass the Host: header from the client right along so redirects
74
+ # can be set properly within the Rack application
75
+ proxy_set_header Host $http_host;
76
+
77
+ # we don't want nginx trying to do something clever with
78
+ # redirects, we set the Host: header above already.
79
+ proxy_redirect off;
80
+
81
+ proxy_pass http://app_server;
82
+ }
83
+
84
+ # Rails error pages
85
+ error_page 500 502 503 504 /500.html;
86
+ location = /500.html {
87
+ root <%= web_root %>;
88
+ }
89
+ }
@@ -0,0 +1 @@
1
+ export BUNDLE_GEMFILE=.freighthop.gemfile
@@ -0,0 +1,51 @@
1
+ # /etc/init/puma.conf - Puma config
2
+
3
+ # This example config should work with Ubuntu 12.04+. It
4
+ # allows you to manage multiple Puma instances with
5
+ # Upstart, Ubuntu's native service management tool.
6
+ #
7
+ # See workers.conf for how to manage all Puma instances at once.
8
+ #
9
+ # Save this config as /etc/init/puma.conf then manage puma with:
10
+ # sudo start puma app=PATH_TO_APP
11
+ # sudo stop puma app=PATH_TO_APP
12
+ # sudo status puma app=PATH_TO_APP
13
+ #
14
+ # or use the service command:
15
+ # sudo service puma {start,stop,restart,status}
16
+ #
17
+
18
+ description "Puma Background Worker"
19
+
20
+ # no "start on", we don't want to automatically start
21
+ stop on (stopping puma-manager or runlevel [06])
22
+
23
+ # change apps to match your deployment user if you want to use this as a less privileged user (recommended!)
24
+ # setuid vagrant
25
+ # setgid vagrant
26
+
27
+ respawn
28
+ respawn limit 3 30
29
+
30
+ instance ${app}
31
+
32
+ script
33
+ # this script runs in /bin/sh by default
34
+ # respawn as bash so we can source in rbenv/rvm
35
+ # quoted heredoc to tell /bin/sh not to interpret
36
+ # variables
37
+ exec /bin/bash <<'EOT'
38
+ # set HOME to the setuid user's home, there doesn't seem to be a better, portable way
39
+ export HOME="$(eval echo ~$(id -un))"
40
+
41
+ cd $app
42
+
43
+ source /etc/profile.d/rbenv.sh
44
+
45
+ source /etc/profile.d/custom_bundler_gemfile.sh
46
+
47
+ logger -t puma "Starting server: $app"
48
+
49
+ exec bundle exec puma -b unix://<%= socket_path %>
50
+ EOT
51
+ end script