diff options
| author | mo khan <mokhan@users.noreply.github.com> | 2015-11-11 22:02:30 -0700 |
|---|---|---|
| committer | mo khan <mokhan@users.noreply.github.com> | 2015-11-11 22:02:30 -0700 |
| commit | faefcb8b9213fc270a7f99f9df38e5ca8b89f3bf (patch) | |
| tree | e41b82ed89c42da3a1dc58b6e38b4156483ae106 | |
| parent | 152b802b203108b766381e7cfaad7cf76c53c12e (diff) | |
| parent | 9e4c5b5717318e731ba0a378a42e31ad908486d8 (diff) | |
Merge pull request #1 from mokhan/upgrade
Sidekiq with runit
79 files changed, 605 insertions, 1708 deletions
diff --git a/.kitchen.yml b/.kitchen.yml index 73b91b2..9f06509 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,3 +1,4 @@ +#<% require "kitchen-sync" %> --- driver: name: vagrant @@ -11,51 +12,59 @@ platforms: suites: - name: default run_list: - - recipe[mokhan-myface::default] - - recipe[mokhan-myface::capistrano] - - recipe[mokhan-myface::delayed_job] - - recipe[mokhan-myface::nginx] - - recipe[mokhan-myface::unicorn] - - recipe[mokhan-myface::nodejs] - - recipe[mokhan-myface::rbenv] - - recipe[mokhan-myface::postgres] + - recipe[stronglifters::default] + - recipe[stronglifters::web] + - recipe[stronglifters::worker] + - recipe[stronglifters::postgres] attributes: + stronglifters: + application_name: "stronglifters" + ruby_version: "2.2.3" + username: "vagrant" + postgresql: + password: + postgres: "iloverandompasswordsbutthiswilldo" postgres: database: "mydb" - host: "localhost" username: "rails" - postgresql: - password: - postgres: 'password' - rbenv: - ruby_version: '2.2.2' + password: "password" + host: "localhost" - name: web run_list: - - recipe[mokhan-myface::default] - - recipe[mokhan-myface::rails] + - recipe[stronglifters::default] + - recipe[stronglifters::web] attributes: - rbenv: - ruby_version: '2.2.2' - user: - username: 'rails' - aws: - username: 'rails' - monit: - application: 'mokhan-myface' - capistrano: - root_path: '/var/www/app' - username: 'rails' - env: - app_api_key: 'api-key' - app_secret_key: 'secret-key' - nginx: - domain: 'www.mokhan.ca' - puma: - username: 'rails' - current_path: '/var/www/app/current' + env: + app_api_key: "api-key" + app_secret_key: "secret-key" + postgres: + database: "mydb" + username: "rails" + password: "password" + host: "localhost" + - name: worker + run_list: + - recipe[stronglifters::default] + - recipe[stronglifters::worker] + attributes: + postgres: + database: "mydb" + username: "rails" + password: "password" + host: "localhost" + - name: db + run_list: + - recipe[stronglifters::default] + - recipe[stronglifters::postgres] + attributes: + postgresql: + password: + postgres: "iloverandompasswordsbutthiswilldo" postgres: database: "mydb" username: "rails" password: "password" host: "localhost" +transport: + name: sftp @@ -1,5 +1,3 @@ -source "https://api.berkshelf.com" +source "https://supermarket.chef.io" metadata - -cookbook "rbenv", git: 'git://github.com/fnichol/chef-rbenv.git' diff --git a/Berksfile.lock b/Berksfile.lock index 6e10850..fb5ab56 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -1,32 +1,24 @@ DEPENDENCIES - rbenv - git: git://github.com/fnichol/chef-rbenv.git - revision: 0a3018634bafe58ad21c6ee271af015220e444b9 - stronglifters-rails + stronglifters path: . metadata: true GRAPH - apt (2.7.0) - build-essential (2.2.3) - chef-sugar (3.1.0) - database (4.0.6) + apt (2.9.2) + build-essential (2.2.4) + chef-sugar (3.1.1) + database (4.0.9) postgresql (>= 1.0.0) - java (1.31.0) - openssl (4.0.0) - chef-sugar (>= 0.0.0) - postgresql (3.4.20) + openssl (4.4.0) + chef-sugar (>= 3.1.1) + packagecloud (0.1.0) + postgresql (3.4.21) apt (>= 1.9.0) build-essential (>= 0.0.0) - openssl (~> 4.0.0) - rbenv (0.7.3) - java (> 1.4.0) - ruby_build (>= 0.0.0) - ruby_build (0.8.0) - stronglifters-rails (0.1.0) - apt (>= 0.0.0) - build-essential (>= 0.0.0) + openssl (~> 4.0) + runit (1.7.4) + packagecloud (>= 0.0.0) + stronglifters (0.2.0) database (>= 0.0.0) postgresql (>= 0.0.0) - rbenv (>= 0.0.0) - ruby_build (>= 0.0.0) + runit (>= 0.0.0) diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 68e3d7b..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,13 +0,0 @@ -stronglifters-rails CHANGELOG -======================= - -This file is used to list changes made in each version of the stronglifters-rails cookbook. - -0.1.0 ------ -- [your_name] - Initial release of stronglifters-rails - -- - - -Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. - -The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. @@ -9,14 +9,6 @@ group :test do gem 'strainer' gem 'test-kitchen' gem 'kitchen-vagrant' - gem 'kitchen-docker' - gem 'kitchen-lxc' - gem 'knife-spork' - gem 'hipchat' - - gem 'guard' - gem 'guard-rspec' - gem 'guard-shell' - + gem 'kitchen-sync' gem 'ffaker' end diff --git a/Gemfile.lock b/Gemfile.lock index 4089b4f..fe84131 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,33 +2,31 @@ GEM remote: https://rubygems.org/ specs: addressable (2.3.8) - annoy (0.5.6) - highline (>= 1.5.0) - app_conf (0.4.2) - berkshelf (3.2.4) + berkshelf (4.0.1) addressable (~> 2.3.4) - berkshelf-api-client (~> 1.2) + berkshelf-api-client (~> 2.0) buff-config (~> 1.0) buff-extensions (~> 1.0) buff-shell_out (~> 0.1) - celluloid (~> 0.16.0) + celluloid (= 0.16.0) celluloid-io (~> 0.16.1) cleanroom (~> 1.0) faraday (~> 0.9.0) + httpclient (~> 2.6.0) minitar (~> 0.5.4) octokit (~> 3.0) retryable (~> 2.0) - ridley (~> 4.0) + ridley (~> 4.3) solve (~> 1.1) thor (~> 0.19) - berkshelf-api-client (1.2.1) - faraday (~> 0.9.0) + berkshelf-api-client (2.0.0) + faraday (~> 0.9.1) + httpclient (~> 2.6.0) buff-config (1.0.1) buff-extensions (~> 1.0) varia_model (~> 0.4) buff-extensions (1.0.0) buff-ignore (1.1.1) - buff-platform (0.1.0) buff-ruby_engine (0.1.0) buff-shell_out (0.2.0) buff-ruby_engine (~> 0.1.0) @@ -38,20 +36,20 @@ GEM celluloid-io (0.16.2) celluloid (>= 0.16.0) nio4r (>= 1.1.0) - chef (12.3.0) - chef-zero (~> 4.1) + chef (12.5.1) + chef-config (= 12.5.1) + chef-zero (~> 4.2, >= 4.2.2) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) - ffi-yajl (>= 1.2, < 3.0) + ffi-yajl (~> 2.2) highline (~> 1.6, >= 1.6.9) mixlib-authentication (~> 1.3) mixlib-cli (~> 1.4) - mixlib-config (~> 2.0) mixlib-log (~> 1.3) - mixlib-shellout (>= 2.0.0.rc.0, < 3.0) + mixlib-shellout (~> 2.0) net-ssh (~> 2.6) net-ssh-multi (~> 1.1) - ohai (~> 8.0) + ohai (>= 8.6.0.alpha.1, < 9) plist (~> 3.1.0) pry (~> 0.9) rspec-core (~> 3.2) @@ -60,18 +58,20 @@ GEM rspec_junit_formatter (~> 0.2.0) serverspec (~> 2.7) specinfra (~> 2.10) - chef-zero (4.2.1) - ffi-yajl (>= 1.1, < 3.0) - hashie (~> 2.0) + syslog-logger (~> 1.6) + chef-config (12.5.1) + mixlib-config (~> 2.0) + mixlib-shellout (~> 2.0) + chef-zero (4.3.2) + ffi-yajl (~> 2.2) + hashie (>= 2.0, < 4.0) mixlib-log (~> 1.3) rack uuidtools (~> 2.1) - chefspec (4.2.0) + chefspec (4.4.0) chef (>= 11.14) - fauxhai (~> 2.0) + fauxhai (~> 2.3) rspec (~> 3.0) - childprocess (0.5.6) - ffi (~> 1.0, >= 1.0.11) cleanroom (1.0.0) coderay (1.1.0) dep-selector-libgecode (1.0.2) @@ -79,115 +79,70 @@ GEM dep-selector-libgecode (~> 1.0) ffi (~> 1.9) diff-lcs (1.2.5) - diffy (3.0.7) - docile (1.1.5) - drydock (0.6.9) - elecksee (1.1.6) - childprocess - rye erubis (2.7.0) - faraday (0.9.1) + faraday (0.9.2) multipart-post (>= 1.2, < 3) fauxhai (2.3.0) net-ssh ohai - ffaker (2.0.0) - ffi (1.9.8) - ffi-yajl (2.2.0) + ffaker (2.1.0) + ffi (1.9.10) + ffi-yajl (2.2.2) libyajl2 (~> 1.2) - foodcritic (4.0.0) + foodcritic (5.0.0) erubis gherkin (~> 2.11) - nokogiri (~> 1.5) + nokogiri (>= 1.5, < 2.0) rake rufus-lru (~> 1.0) treetop (~> 1.4) yajl-ruby (~> 1.1) - formatador (0.2.5) gherkin (2.12.2) multi_json (~> 1.3) - git (1.2.9.1) - guard (2.12.5) - formatador (>= 0.2.4) - listen (~> 2.7) - lumberjack (~> 1.0) - nenv (~> 0.1) - notiffany (~> 0.0) - pry (>= 0.9.12) - shellany (~> 0.0) - thor (>= 0.18.1) - guard-compat (1.2.1) - guard-rspec (4.5.0) - guard (~> 2.1) - guard-compat (~> 1.1) - rspec (>= 2.99.0, < 4.0) - guard-shell (0.7.1) - guard (>= 2.0.0) - guard-compat (~> 1.0) - hashie (2.1.2) - highline (1.7.2) - hipchat (1.5.1) - httparty - mimemagic - hitimes (1.2.2) - httparty (0.13.3) - json (~> 1.8) - multi_xml (>= 0.5.2) + hashie (3.4.3) + highline (1.7.8) + hitimes (1.2.3) + httpclient (2.6.0.1) ipaddress (0.8.0) - json (1.8.2) - kitchen-docker (2.1.0) + json (1.8.3) + kitchen-sync (1.1.1) + net-sftp test-kitchen (>= 1.0.0) - kitchen-lxc (0.1.4) - elecksee (~> 1.0, >= 1.0.22) - test-kitchen (~> 1.2, >= 1.2.1) - kitchen-vagrant (0.17.0) + kitchen-vagrant (0.19.0) test-kitchen (~> 1.4) - knife-spork (1.5.1) - app_conf (>= 0.4.0) - chef (>= 11.0.0) - diffy (>= 3.0.1) - git (>= 1.2.5) libyajl2 (1.2.0) - listen (2.10.0) - celluloid (~> 0.16.0) - rb-fsevent (>= 0.9.3) - rb-inotify (>= 0.9) - lumberjack (1.0.9) method_source (0.8.2) - mime-types (2.5) - mimemagic (0.3.0) + mime-types (2.6.2) mini_portile (0.6.2) minitar (0.5.4) mixlib-authentication (1.3.0) mixlib-log mixlib-cli (1.5.0) - mixlib-config (2.1.0) + mixlib-config (2.2.1) mixlib-log (1.6.0) - mixlib-shellout (2.0.1) - multi_json (1.11.0) - multi_xml (0.5.5) + mixlib-shellout (2.2.3) + multi_json (1.11.2) multipart-post (2.0.0) - nenv (0.2.0) - net-http-persistent (2.9.4) net-scp (1.2.1) net-ssh (>= 2.6.5) + net-sftp (2.1.2) + net-ssh (>= 2.6.5) net-ssh (2.9.2) net-ssh-gateway (1.2.0) net-ssh (>= 2.6.5) net-ssh-multi (1.2.1) net-ssh (>= 2.6.5) net-ssh-gateway (>= 1.2.0) - nio4r (1.1.0) + net-telnet (0.1.1) + nio4r (1.1.1) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) - notiffany (0.0.6) - nenv (~> 0.1) - shellany (~> 0.0) octokit (3.8.0) sawyer (~> 0.6.0, >= 0.5.3) - ohai (8.3.0) + ohai (8.7.0) + chef-config (>= 12.5.0.alpha.1, < 13) ffi (~> 1.9) - ffi-yajl (>= 1.1, < 3.0) + ffi-yajl (~> 2.2) ipaddress mime-types (~> 2.0) mixlib-cli @@ -199,17 +154,14 @@ GEM wmi-lite (~> 1.0) plist (3.1.0) polyglot (0.3.5) - pry (0.10.1) + pry (0.10.3) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) - rack (1.6.0) + rack (1.6.4) rake (10.4.2) - rb-fsevent (0.9.4) - rb-inotify (0.9.5) - ffi (>= 0.5.0) - retryable (2.0.1) - ridley (4.1.2) + retryable (2.0.3) + ridley (4.3.2) addressable buff-config (~> 1.0) buff-extensions (~> 1.0) @@ -219,81 +171,74 @@ GEM celluloid-io (~> 0.16.1) erubis faraday (~> 0.9.0) - hashie (>= 2.0.2, < 3.0.0) + hashie (>= 2.0.2, < 4.0.0) + httpclient (~> 2.6) json (>= 1.7.7) mixlib-authentication (>= 1.3.0) - net-http-persistent (>= 2.8) - retryable (>= 2.0.0) + retryable (~> 2.0) semverse (~> 1.1) - varia_model (~> 0.4) - rspec (3.2.0) - rspec-core (~> 3.2.0) - rspec-expectations (~> 3.2.0) - rspec-mocks (~> 3.2.0) - rspec-core (3.2.3) - rspec-support (~> 3.2.0) - rspec-expectations (3.2.1) + varia_model (~> 0.4.0) + rspec (3.3.0) + rspec-core (~> 3.3.0) + rspec-expectations (~> 3.3.0) + rspec-mocks (~> 3.3.0) + rspec-core (3.3.2) + rspec-support (~> 3.3.0) + rspec-expectations (3.3.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.2.0) + rspec-support (~> 3.3.0) rspec-its (1.2.0) rspec-core (>= 3.0.0) rspec-expectations (>= 3.0.0) - rspec-mocks (3.2.1) + rspec-mocks (3.3.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.2.0) - rspec-support (3.2.2) - rspec_junit_formatter (0.2.1) + rspec-support (~> 3.3.0) + rspec-support (3.3.0) + rspec_junit_formatter (0.2.3) builder (< 4) rspec-core (>= 2, < 4, != 2.12.0) rufus-lru (1.0.5) - rye (0.9.13) - annoy - docile (>= 1.0.1) - highline (>= 1.5.1) - net-scp (>= 1.0.2) - net-ssh (>= 2.0.13) - sysinfo (>= 0.8.1) safe_yaml (1.0.4) sawyer (0.6.0) addressable (~> 2.3.5) faraday (~> 0.8, < 0.10) semverse (1.2.1) - serverspec (2.14.1) + serverspec (2.24.2) multi_json rspec (~> 3.0) rspec-its - specinfra (~> 2.25) - shellany (0.0.1) + specinfra (~> 2.43) + sfl (2.2) slop (3.6.0) solve (1.2.1) dep_selector (~> 1.0) semverse (~> 1.1) - specinfra (2.30.2) + specinfra (2.44.1) net-scp - net-ssh - storable (0.8.9) - strainer (3.4.0) - berkshelf (>= 2.0, < 4.0) - buff-platform (~> 0.1) - sysinfo (0.8.1) - drydock - storable + net-ssh (~> 2.7) + net-telnet + sfl + strainer (0.2.1) + chef (>= 10.10) + term-ansicolor (~> 1.0.7) + syslog-logger (1.6.8) systemu (2.6.5) - test-kitchen (1.4.0) + term-ansicolor (1.0.7) + test-kitchen (1.4.2) mixlib-shellout (>= 1.2, < 3.0) net-scp (~> 1.1) - net-ssh (~> 2.7) + net-ssh (~> 2.7, < 2.10) safe_yaml (~> 1.0) thor (~> 0.18) thor (0.19.1) - timers (4.0.1) + timers (4.0.4) hitimes - treetop (1.6.2) + treetop (1.6.3) polyglot (~> 0.3) uuidtools (2.1.5) - varia_model (0.4.0) + varia_model (0.4.1) buff-extensions (~> 1.0) - hashie (>= 2.0.2, < 3.0.0) + hashie (>= 2.0.2, < 4.0.0) wmi-lite (1.0.0) yajl-ruby (1.2.1) @@ -305,17 +250,11 @@ DEPENDENCIES chefspec ffaker foodcritic - guard - guard-rspec - guard-shell - hipchat - kitchen-docker - kitchen-lxc + kitchen-sync kitchen-vagrant - knife-spork rake strainer test-kitchen BUNDLED WITH - 1.10.3 + 1.10.6 diff --git a/Guardfile b/Guardfile deleted file mode 100644 index 5cc7938..0000000 --- a/Guardfile +++ /dev/null @@ -1,11 +0,0 @@ -guard :rspec, cmd: "bin/rspec" do - watch(%r{^spec/.+_spec\.rb$}) - watch(%r{recipes/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } - watch('spec/spec_helper.rb') { 'spec' } -end - -guard :shell do - watch(%r{recipes/(.+)\.rb$}) do |m| - system("bin/foodcritic .") - end -end @@ -2,62 +2,10 @@ stronglifters-rails Cookbook ====================== -TODO: Enter the cookbook description here. - -e.g. -This cookbook makes your favorite breakfast sandwich. - -Requirements ------------- -TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc. - -e.g. -#### packages -- `toaster` - stronglifters-rails needs toaster to brown your bagel. - -Attributes ----------- -TODO: List your cookbook attributes here. - -e.g. -#### stronglifters-rails::default -<table> - <tr> - <th>Key</th> - <th>Type</th> - <th>Description</th> - <th>Default</th> - </tr> - <tr> - <td><tt>['stronglifters-rails']['bacon']</tt></td> - <td>Boolean</td> - <td>whether to include bacon</td> - <td><tt>true</tt></td> - </tr> -</table> - -Usage ------ -#### stronglifters-rails::default -TODO: Write usage instructions for each cookbook. - -e.g. -Just include `stronglifters-rails` in your node's `run_list`: - -```json -{ - "name":"my_node", - "run_list": [ - "recipe[stronglifters-rails]" - ] -} -``` Contributing ------------ -TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section. -e.g. 1. Fork the repository on Github 2. Create a named feature branch (like `add_component_x`) 3. Write your change @@ -67,4 +15,4 @@ e.g. License and Authors ------------------- -Authors: TODO: List authors +Authors: mo @@ -4,4 +4,4 @@ require 'foodcritic' RSpec::Core::RakeTask.new(:spec) FoodCritic::Rake::LintTask.new -task default: [:foodcritic, :spec] +task default: [:spec] diff --git a/attributes/default.rb b/attributes/default.rb index 2c1b522..0738b14 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,18 +1,70 @@ -default['user']['username'] = 'rails' -default['capistrano']['root_path'] = '/var/www/app' -default['capistrano']['username'] = node['user']['username'] -default['capistrano']['env'] = { - asset_host: '', - secret_token: '' +if node.platform_family == "rhel" + default['stronglifters']['packages'] = %w{ + autoconf + automake + bison + bzip2 + ca-certificates + gcc-c++ + git + libffi-devel + libtool + libxml2 + libxml2-devel + libxslt + libxslt-devel + make + openssl-devel + patch + readline + readline-devel + zlib + zlib-devel + } +else + default['stronglifters']['packages'] = %w{ + build-essential + curl + git-core + libcurl4-openssl-dev + libffi-dev + libreadline-dev + libsqlite3-dev + libssl-dev + libxml2-dev + libxslt1-dev + libyaml-dev + memcached + python-software-properties + sqlite3 + zlib1g-dev + } +end + +default['stronglifters']['application_name'] = "app" +default['stronglifters']['aws']['profiles']['default']['region'] = 'us-east-1' +default['stronglifters']['aws']['profiles']['default']['aws_access_key_id'] = 'secret' +default['stronglifters']['aws']['profiles']['default']['aws_secret_access_key'] = 'secret' +default['stronglifters']['root_path'] = "/var/www/#{node['stronglifters']['application_name']}" +default['stronglifters']['nginx']['blacklisted_ips'] = [] +default['stronglifters']['nginx']['domain'] = 'www.example.com' +default['stronglifters']['ruby_version'] = '2.2.3' +default['stronglifters']['username'] = 'rails' + +pg_connection_string = + if node['postgres'].nil? == false + "postgres://#{node['postgres']['username']}:#{node['postgres']['password']}@#{node['postgres']['host']}/#{node['postgres']['database']}" + else + nil + end +default['stronglifters']['env'] = { + ASSET_HOST: '', + DATABASE_URL: pg_connection_string, + RAILS_ENV: 'production', + SECRET_TOKEN: '', } -default['delayed_job']['username'] = node['user']['username'] -default['delayed_job']['current_path'] = "#{node['capistrano']['root_path']}/current" -default['delayed_job']['rails_env'] = node.chef_environment -default['nginx']['domain'] = 'www.example.com' -default['nginx']['current_path'] = "#{node['capistrano']['root_path']}/current" -default['nginx']['shared_path'] = "#{node['capistrano']['root_path']}/shared" -default['nginx']['socket_file'] = "#{node['capistrano']['root_path']}/shared/tmp/sockets/puma.sock" -default['nginx']['ssl']['key'] = <<-DATA + +default['stronglifters']['nginx']['ssl']['key'] = <<-SELFSIGNED -----BEGIN RSA PRIVATE KEY----- MIICWwIBAAKBgQCbfQuXVpccfpOmBHGfkZVfgfOZpMLGX3XmxFrer20aGM6vG9JR 75QmD28bnDnQPaLGMzCmsg6nhi0Lz+c+u9DdCKRVgZbCK5MJo7FsVRLR9vEdhGkT @@ -28,8 +80,8 @@ AZ0Y1dz0bSiO0BIjjAwSKe8Nz+xPiSn/xjf/g0ufmCazi9SDZwQ5TyJjjfxDJ/7p KhQWzwbGnN2FUW9r2QJADT7SMkMHb9bOgUJnLehLQY0sONrfAMJ7NieJk24PyX83 bBV1YGbhWentkyZBkgcvYqVlxGTPvIao1x69xSJhOw== -----END RSA PRIVATE KEY----- -DATA -default['nginx']['ssl']['crt'] = <<-DATA +SELFSIGNED +default['stronglifters']['nginx']['ssl']['crt'] = <<-SELFSIGNED -----BEGIN CERTIFICATE----- MIIDYzCCAsygAwIBAgIJAKQbJHHxbt63MA0GCSqGSIb3DQEBBQUAMH8xCzAJBgNV BAYTAkNBMRAwDgYDVQQIEwdBbGJlcnRhMRAwDgYDVQQHEwdDYWxnYXJ5MRYwFAYD @@ -51,17 +103,4 @@ wF+ITsPDm1nWbGZ8h8tVc6VYdHPyAX95X9/F9h1u2z8E36A5CQ9aTaS6aU1KnNTh Mthn8jGpgIJeFo2Jphx/QjEVUrLQdPg3pN00uJOTa8Sk4OEWSiqw5P9w0tj0Wicz 60evIdcHAQ== -----END CERTIFICATE----- -DATA -default['unicorn']['username'] = node['user']['username'] -default['unicorn']['current_path'] = "#{node['capistrano']['root_path']}/current" -default['unicorn']['rails_env'] = node.chef_environment -default['puma']['username'] = node['user']['username'] -default['puma']['current_path'] = "#{node['capistrano']['root_path']}/current" -default['puma']['rails_env'] = node.chef_environment -default['monit']['application'] = 'app' -#default['rbenv']['ruby_version'] = '2.2.2' -default['rbenv']['rubies'] = [ "2.2.2" ] -default['aws']['username'] = node['user']['username'] -default['aws']['profiles']['default']['region'] = 'us-east-1' -default['aws']['profiles']['default']['aws_access_key_id'] = 'secret' -default['aws']['profiles']['default']['aws_secret_access_key'] = 'secret' +SELFSIGNED diff --git a/definitions/.gitkeep b/definitions/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/definitions/.gitkeep +++ /dev/null diff --git a/files/default/blacklist.conf b/files/default/blacklist.conf deleted file mode 100644 index 900f151..0000000 --- a/files/default/blacklist.conf +++ /dev/null @@ -1,2 +0,0 @@ -deny 46.118.159.178; -deny 134.249.77.209; diff --git a/files/gemrc b/files/gemrc new file mode 100644 index 0000000..154cd47 --- /dev/null +++ b/files/gemrc @@ -0,0 +1 @@ +gem: --no-document diff --git a/files/rbenv.sh b/files/rbenv.sh new file mode 100644 index 0000000..b6f9ad8 --- /dev/null +++ b/files/rbenv.sh @@ -0,0 +1,4 @@ +export RBENV_ROOT="/usr/local/rbenv" +export PATH="$RBENV_ROOT/bin:$PATH" +export RUBY_CONFIGURE_OPTS=--disable-install-doc +eval "$(rbenv init -)" diff --git a/libraries/.gitkeep b/libraries/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/libraries/.gitkeep +++ /dev/null diff --git a/libraries/platform.rb b/libraries/platform.rb new file mode 100644 index 0000000..9add1a9 --- /dev/null +++ b/libraries/platform.rb @@ -0,0 +1,7 @@ +class Chef + class Recipe + def redhat? + node.platform_family == 'rhel' + end + end +end diff --git a/libraries/rbenv.rb b/libraries/rbenv.rb new file mode 100644 index 0000000..eac1958 --- /dev/null +++ b/libraries/rbenv.rb @@ -0,0 +1,11 @@ +class Chef + class Recipe + def rbenv(command) + stronglifters_rbenv(command) + end + + def gem(command) + stronglifters_gem(command) + end + end +end diff --git a/metadata.rb b/metadata.rb index b741610..dd4360b 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,14 +1,11 @@ -name 'stronglifters-rails' -maintainer 'mo khan' -maintainer_email 'mo@mokhan.ca' -license 'All rights reserved' -description 'Installs/Configures stronglifters-rails' -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '0.1.0' +name "stronglifters" +maintainer "mo khan" +maintainer_email "mo@mokhan.ca" +license "All rights reserved" +description "Installs/Configures stronglifters" +long_description IO.read(File.join(File.dirname(__FILE__), "README.md")) +version "0.2.0" -depends "apt" -depends "build-essential" depends "database" depends "postgresql" -depends "ruby_build" -depends "rbenv" +depends "runit" diff --git a/providers/.gitkeep b/providers/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/providers/.gitkeep +++ /dev/null diff --git a/providers/gem.rb b/providers/gem.rb new file mode 100644 index 0000000..9c05f60 --- /dev/null +++ b/providers/gem.rb @@ -0,0 +1,10 @@ +use_inline_resources + +action :install do + bash "gem_#{new_resource.name}" do + code <<-BASH +source /etc/profile.d/rbenv.sh +gem install #{new_resource.name} --no-ri --no-rdoc +BASH + end +end diff --git a/providers/rbenv.rb b/providers/rbenv.rb new file mode 100644 index 0000000..f94a949 --- /dev/null +++ b/providers/rbenv.rb @@ -0,0 +1,10 @@ +use_inline_resources + +action :run do + bash "rbenv_#{new_resource.command}" do + code <<-BASH +source /etc/profile.d/rbenv.sh +rbenv #{new_resource.command} +BASH + end +end diff --git a/recipes/aws.rb b/recipes/aws.rb index 3d00357..54045d5 100644 --- a/recipes/aws.rb +++ b/recipes/aws.rb @@ -1,29 +1,20 @@ -include_recipe "apt" -configuration = node['aws'] +package "python-pip" +execute "pip install awscli" -package 'python-pip' do - action :install -end - -execute 'install awscli' do - command 'pip install awscli' - action :run -end - -directory "/home/#{configuration["username"]}/.aws/" do - owner configuration['username'] - group configuration['username'] +username = node["stronglifters"]["username"] +directory "/home/#{username}/.aws/" do + owner username + group username mode "0755" recursive true action :create end -template "/home/#{configuration["username"]}/.aws/config" do - source "aws/config.erb" +configuration = node["stronglifters"]["aws"] +template "/home/#{username}/.aws/config" do variables(configuration) end -template "/home/#{configuration["username"]}/.aws/credentials" do - source "aws/credentials.erb" +template "/home/#{username}/.aws/credentials" do variables(configuration) end diff --git a/recipes/capistrano.rb b/recipes/capistrano.rb deleted file mode 100644 index e5b50a1..0000000 --- a/recipes/capistrano.rb +++ /dev/null @@ -1,55 +0,0 @@ -include_recipe "stronglifters-rails::user" - -configuration = node['capistrano'] -root_path = configuration['root_path'] -shared_path = File.join(root_path, "shared") - -directories = [ - root_path, - shared_path, - "#{shared_path}/backups", - "#{shared_path}/bundle", - "#{shared_path}/config", - "#{shared_path}/log", - "#{shared_path}/tmp/sockets", - "#{shared_path}/tmp/pids", - "#{shared_path}/tmp/cache", - "#{root_path}/releases", -] - -directories.each do |dir_name| - directory dir_name do - owner configuration['username'] - group configuration['username'] - mode "0755" - recursive true - action :create - end -end - -template "#{shared_path}/.env.#{node.chef_environment}" do - source "env.erb" - owner configuration['username'] - group configuration['username'] - mode "0600" - variables(configuration) -end - -execute "chown-rails" do - command "chown -R rails:rails #{root_path}" - user "root" - action :run - not_if "stat -c %U #{root_path} | grep root" -end - -template "#{shared_path}/config/database.yml" do - source "database.yml.erb" - mode "0664" - variables({ - rails_env: node.chef_environment, - database: node['postgres']["database"], - username: node['postgres']['username'], - password: node['postgres']["password"], - host: node['postgres']['host'], - }) -end diff --git a/recipes/default.rb b/recipes/default.rb index cb47ad4..70ce001 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -1,39 +1,10 @@ -include_recipe "apt" -include_recipe "build-essential" -include_recipe "stronglifters-rails::user" -include_recipe "stronglifters-rails::aws" -include_recipe "stronglifters-rails::monit" +if redhat? + execute "yum update -y" +else + execute "apt-get update -y" +end -packages = [ - "curl", - "libcurl3", "libcurl3-gnutls", "libcurl4-openssl-dev", - "git-core", - "python-software-properties", - "build-essential", - "tklib", - "zlib1g-dev", - "libssl-dev", - "libxml2", - "libxml2-dev", - "libxslt1-dev", - "gawk", - "libreadline6-dev", - "libyaml-dev", - "libsqlite3-dev", - "autoconf", - "libgdbm-dev", - "libncurses5-dev", - "automake", - "libtool", - "bison", - "pkg-config", - "libffi-dev", - "vim", - "unzip", -] +package node['stronglifters']['packages'] -packages.each do |item| - package item do - action :install - end -end +include_recipe "runit" +include_recipe "stronglifters::ruby" diff --git a/recipes/delayed_job.rb b/recipes/delayed_job.rb deleted file mode 100644 index 842b502..0000000 --- a/recipes/delayed_job.rb +++ /dev/null @@ -1,15 +0,0 @@ -include_recipe "stronglifters-rails::user" - -configuration = node['delayed_job'] - -template "/etc/init.d/delayed_job" do - source "delayed_job.erb" - owner configuration[:username] - group configuration[:username] - mode "0744" - variables(configuration) -end - -service 'delayed_job' do - action [:enable, :start] -end if File.exists?("#{configuration[:current_path]}/Gemfile") diff --git a/recipes/monit.rb b/recipes/monit.rb deleted file mode 100644 index bc82a5f..0000000 --- a/recipes/monit.rb +++ /dev/null @@ -1,18 +0,0 @@ -configuration = node["monit"] - -package "monit" do - action :install -end - -template "/etc/monit/monitrc" do - source "monit/monitrc.erb" - user "root" - group "root" - mode "0600" - variables(configuration) - notifies :restart, "service[monit]" -end - -service "monit" do - action [:enable, :start] -end diff --git a/recipes/nginx.rb b/recipes/nginx.rb index a249e16..e218945 100644 --- a/recipes/nginx.rb +++ b/recipes/nginx.rb @@ -1,23 +1,21 @@ -include_recipe "apt" -apt_repository "nginx-stable" do - uri "http://ppa.launchpad.net/nginx/stable/ubuntu" - distribution node['lsb']['codename'] - components ["main"] - keyserver "keyserver.ubuntu.com" - key "C300EE8C" +if redhat? + execute "yum upgrade -y ca-certificates" + package "epel-release" end -package 'nginx' do - action :install +package "nginx" +package "logrotate" +user "nginx" + +configuration = node['stronglifters']['nginx'] + +template "/etc/nginx/nginx.conf" do + variables(configuration) + notifies :restart, 'service[nginx]' end -package 'logrotate' -configuration = node['nginx'] directory "/etc/nginx/ssl" do - owner "root" - group "root" mode "0644" - action :create end template "/etc/nginx/ssl/#{configuration['domain']}.crt" do @@ -34,36 +32,15 @@ template "/etc/nginx/ssl/#{configuration['domain']}.key" do notifies :restart, "service[nginx]" end -cookbook_file "/etc/nginx/conf.d/blacklist.conf" do - source "blacklist.conf" - mode "0644" -end - -template "/etc/nginx/sites-available/#{configuration['domain']}" do - source "nginx_unix.erb" - mode "0644" - variables(configuration) - notifies :restart, "service[nginx]" -end - -link "/etc/nginx/sites-enabled/#{configuration['domain']}" do - to "/etc/nginx/sites-available/#{configuration['domain']}" -end - -file "/etc/nginx/sites-enabled/default" do - action :delete -end - directory '/var/log/nginx' do mode '0755' - action :create +end + +service "nginx" do + action [:enable, :start] end template "/etc/logrotate.d/nginx" do source "nginx_logrotate.erb" mode "0644" end - -service "nginx" do - action [:enable, :start] -end diff --git a/recipes/nodejs.rb b/recipes/nodejs.rb deleted file mode 100644 index e802799..0000000 --- a/recipes/nodejs.rb +++ /dev/null @@ -1,13 +0,0 @@ -include_recipe "apt" - -apt_repository "node" do - uri "http://ppa.launchpad.net/chris-lea/node.js/ubuntu" - distribution node['lsb']['codename'] - components ["main"] - keyserver "keyserver.ubuntu.com" - key "C7917B12" -end - -package "nodejs" do - action :upgrade -end diff --git a/recipes/postgres.rb b/recipes/postgres.rb index 403f626..9d9c831 100644 --- a/recipes/postgres.rb +++ b/recipes/postgres.rb @@ -1,18 +1,17 @@ -include_recipe "stronglifters-rails::rbenv" include_recipe "postgresql::server" include_recipe "postgresql::contrib" include_recipe "database::postgresql" -database = node['postgres']["database"] -username = node['postgres']['username'] -password = node['postgres']["password"] -host = node['postgres']['host'] +database = node["postgres"]["database"] +username = node["postgres"]["username"] +password = node["postgres"]["password"] +host = node["postgres"]["host"] postgresql_connection_info = { host: host, port: 5432, - username: 'postgres', - password: node['postgresql']['password']['postgres'], + username: "postgres", + password: node["postgresql"]["password"]["postgres"], } postgresql_database_user username do diff --git a/recipes/puma.rb b/recipes/puma.rb deleted file mode 100644 index 077ccf2..0000000 --- a/recipes/puma.rb +++ /dev/null @@ -1,29 +0,0 @@ -configuration = node['puma'] - -template "/etc/init.d/puma" do - source "puma.erb" - owner configuration['username'] - group configuration['username'] - mode "0744" - variables(configuration) -end - -template "/usr/local/bin/run-puma" do - source "run-puma.erb" - owner configuration['username'] - group configuration['username'] - mode "0744" - variables(configuration) -end - -template "/etc/puma.conf" do - source "puma.conf.erb" - owner configuration['username'] - group configuration['username'] - mode "0744" - variables(configuration) -end - -service "puma" do - action [:enable, :start] -end if File.exists?("#{configuration['current_path']}/Gemfile") diff --git a/recipes/rails.rb b/recipes/rails.rb index 30d2d27..dddbcdf 100644 --- a/recipes/rails.rb +++ b/recipes/rails.rb @@ -1,25 +1,31 @@ -include_recipe "stronglifters-rails::rbenv" -include_recipe "stronglifters-rails::capistrano" -include_recipe "stronglifters-rails::nginx" -include_recipe "stronglifters-rails::puma" -include_recipe "stronglifters-rails::nodejs" +include_recipe "stronglifters::user" +include_recipe "stronglifters::aws" -[ - 'imagemagick', - 'libmagickwand-dev', - 'memcached', - 'logrotate', - 'sqlite3', -].each do |item| - package item do - action :install - end -end - -shared_path = "#{node['capistrano']['root_path']}/shared" +root_path = node["stronglifters"]["root_path"] template "/etc/logrotate.d/rails" do source "rails_logrotate.erb" mode "0644" - variables({ shared_path: shared_path }) + variables({ shared_path: File.join(root_path, "shared") }) +end + +directory root_path do + mode "0755" + owner node["stronglifters"]["username"] + group node["stronglifters"]["username"] + recursive true end + +template "/home/#{node["stronglifters"]["username"]}/.profile" do + variables(env: node["stronglifters"]["env"]) +end + +gem "foreman" + +runit_service "foreman" do + action [:enable, :start] + default_logger true + env node["stronglifters"]["env"] + log true + retries 3 +end if File.exists?("#{File.join(root_path, "current")}/Procfile") diff --git a/recipes/rbenv.rb b/recipes/rbenv.rb deleted file mode 100644 index f545077..0000000 --- a/recipes/rbenv.rb +++ /dev/null @@ -1,45 +0,0 @@ -include_recipe "ruby_build::default" -include_recipe "rbenv::system" - -configuration = node['rbenv'] -rbenv_global configuration['rubies'].first - -#include_recipe "apt" - -#items = [ "build-essential", "tklib", "zlib1g-dev", "libssl-dev", "libreadline-gplv2-dev", "libxml2", "libxml2-dev", "libxslt1-dev" ] -#items.each do |item| - #package item do - #action :upgrade - #end -#end - -#git "/usr/local/rbenv" do - #repository "git://github.com/sstephenson/rbenv.git" - #reference "master" - #action :sync -#end - -#directory "/usr/local/rbenv/plugins" do - #action :create -#end - -#git "/usr/local/rbenv/plugins/ruby-build" do - #repository "git://github.com/sstephenson/ruby-build.git" - #reference "master" - #action :sync -#end - -#template "/etc/skel/.bashrc" do - #source "bashrc.erb" -#end - -#bash "install ruby #{configuration['ruby_version']}" do - #code <<-SCRIPT - #export PATH="/usr/local/rbenv/bin:$PATH" - #eval "$(rbenv init -)" - #rbenv install #{configuration['ruby_version']} - #rbenv global #{configuration['ruby_version']} - #gem install bundler --no-ri --no-rdoc - #rbenv rehash - #SCRIPT -#end diff --git a/recipes/redis.rb b/recipes/redis.rb new file mode 100644 index 0000000..422c87a --- /dev/null +++ b/recipes/redis.rb @@ -0,0 +1 @@ +package "redis-server" diff --git a/recipes/ruby.rb b/recipes/ruby.rb new file mode 100644 index 0000000..6ebd5b6 --- /dev/null +++ b/recipes/ruby.rb @@ -0,0 +1,19 @@ +git "/usr/local/rbenv" do + repository "https://github.com/sstephenson/rbenv.git" +end + +cookbook_file "/etc/profile.d/rbenv.sh" +cookbook_file "/etc/gemrc" +directory "/usr/local/rbenv/plugins" + +git "/usr/local/rbenv/plugins/ruby-build" do + repository "https://github.com/sstephenson/ruby-build.git" +end + +ruby_version = node["stronglifters"]["ruby_version"] +stronglifters_rbenv "install #{ruby_version}" do + not_if { ::File.exist?("/usr/local/rbenv/versions/#{ruby_version}") } +end +rbenv "global #{ruby_version}" + +gem "bundler" diff --git a/recipes/unicorn.rb b/recipes/unicorn.rb deleted file mode 100644 index 404c3a3..0000000 --- a/recipes/unicorn.rb +++ /dev/null @@ -1,13 +0,0 @@ -configuration = node['unicorn'] - -template "/etc/init.d/unicorn" do - source "unicorn.erb" - owner configuration[:username] - group configuration[:username] - mode "0744" - variables(configuration) -end - -service "unicorn" do - action [:enable, :start] -end if File.exists?("#{configuration[:current_path]}/Gemfile") diff --git a/recipes/user.rb b/recipes/user.rb index 2833748..46bfa72 100644 --- a/recipes/user.rb +++ b/recipes/user.rb @@ -1,8 +1,6 @@ -configuration = node['user'] - -user configuration['username'] do +user node["stronglifters"]["username"] do supports manage_home: true comment "rails user" - home "/home/#{configuration['username']}" + home "/home/#{node["stronglifters"]["username"]}" shell "/bin/bash" end diff --git a/recipes/web.rb b/recipes/web.rb new file mode 100644 index 0000000..194276f --- /dev/null +++ b/recipes/web.rb @@ -0,0 +1,11 @@ +include_recipe "stronglifters::nginx" +include_recipe "stronglifters::rails" + +current_path = "#{node["stronglifters"]["root_path"]}/current" +runit_service "puma" do + action [:enable, :start] + default_logger true + env node["stronglifters"]["env"] + log true + retries 3 +end if File.exists?("#{current_path}/Gemfile") diff --git a/recipes/worker.rb b/recipes/worker.rb new file mode 100644 index 0000000..c0ecf43 --- /dev/null +++ b/recipes/worker.rb @@ -0,0 +1,11 @@ +include_recipe "stronglifters::redis" +include_recipe "stronglifters::rails" + +current_path = "#{node["stronglifters"]["root_path"]}/current" +runit_service "sidekiq" do + action [:enable, :start] + default_logger true + env node["stronglifters"]["env"] + log true + retries 3 +end if File.exists?("#{current_path}/Gemfile") diff --git a/resources/.gitkeep b/resources/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/resources/.gitkeep +++ /dev/null diff --git a/resources/gem.rb b/resources/gem.rb new file mode 100644 index 0000000..440ebc9 --- /dev/null +++ b/resources/gem.rb @@ -0,0 +1,4 @@ +actions :install +default_action :install + +attribute :name, name_attribute: true diff --git a/resources/rbenv.rb b/resources/rbenv.rb new file mode 100644 index 0000000..6d957a1 --- /dev/null +++ b/resources/rbenv.rb @@ -0,0 +1,4 @@ +actions :run +default_action :run + +attribute :command, name_attribute: true diff --git a/spec/aws_spec.rb b/spec/aws_spec.rb index e8a887a..49c7a67 100644 --- a/spec/aws_spec.rb +++ b/spec/aws_spec.rb @@ -1,25 +1,25 @@ -describe "stronglifters-rails::aws" do +describe "stronglifters::aws" do subject do ChefSpec::SoloRunner.new do |node| - node.set['aws']['username'] = username + node.set["stronglifters"]["username"] = username end.converge(described_recipe) end let(:username) { FFaker::Internet.user_name } - it 'installs python-ip' do - expect(subject).to install_package('python-pip') + it "installs python-ip" do + expect(subject).to install_package("python-pip") end - it 'installs awscli' do - expect(subject).to run_execute('pip install awscli') + it "installs awscli" do + expect(subject).to run_execute("pip install awscli") end - it 'installs the config file' do + it "installs the config file" do expect(subject).to create_template("/home/#{username}/.aws/config") end - it 'installs the credentials file' do + it "installs the credentials file" do expect(subject).to create_template("/home/#{username}/.aws/credentials") end end diff --git a/spec/capistrano_spec.rb b/spec/capistrano_spec.rb deleted file mode 100644 index 342812b..0000000 --- a/spec/capistrano_spec.rb +++ /dev/null @@ -1,59 +0,0 @@ -describe "stronglifters-rails::capistrano" do - subject do - ChefSpec::SoloRunner.new do |node| - node.set["capistrano"]["root_path"] = root_path - node.set["capistrano"]["username"] = username - node.set["postgres"]["database"] = "app" - node.set["postgres"]["username"] = username - node.set["postgres"]["password"] = "password" - node.set["postgres"]["host"] = "localhost" - end.converge(described_recipe) - end - let(:root_path) { "/var/www/#{FFaker::Internet.domain_name}" } - let(:shared_path) { "#{root_path}/shared" } - let(:username) { "deployer" } - - before :each do - stub_command("stat -c %U #{root_path} | grep root").and_return(nil) - end - - it "creates the root directory for the application" do - expect(subject).to create_directory(root_path) - .with_owner(username) - .with_group(username) - .with_mode("0755") - end - - it "creates the shared directory for the application" do - expect(subject).to create_directory("#{root_path}/shared") - .with_owner(username) - .with_group(username) - .with_mode("0755") - end - - it "creates all the shared folders" do - directories = [ - "#{shared_path}/backups", - "#{shared_path}/bundle", - "#{shared_path}/config", - "#{shared_path}/log", - "#{shared_path}/tmp/sockets", - "#{shared_path}/tmp/pids", - "#{shared_path}/tmp/cache", - "#{root_path}/releases" - ] - directories.each do |directory| - expect(subject).to create_directory(directory) - .with_owner(username) - .with_group(username) - .with_mode("0755") - end - end - - it "lays down the .env template" do - expect(subject).to create_template("#{shared_path}/.env._default") - .with_owner(username) - .with_group(username) - .with_mode("0600") - end -end diff --git a/spec/default_spec.rb b/spec/default_spec.rb index c8411f9..de3e098 100644 --- a/spec/default_spec.rb +++ b/spec/default_spec.rb @@ -1,42 +1,13 @@ -describe 'stronglifters-rails::default' do +describe "stronglifters::default" do subject do ChefSpec::SoloRunner.new do |node| + node.set["stronglifters"]["packages"] = packages end.converge(described_recipe) end - let(:packages) do - [ - "curl", - "libcurl3", - "libcurl3-gnutls", - "libcurl4-openssl-dev", - "git-core", - "python-software-properties", - "build-essential", - "tklib", - "zlib1g-dev", - "libssl-dev", - "libxml2", - "libxml2-dev", - "libxslt1-dev", - "gawk", - "libreadline6-dev", - "libyaml-dev", - "autoconf", - "libgdbm-dev", - "libncurses5-dev", - "automake", - "libtool", - "bison", - "pkg-config", - "libffi-dev", - "vim", - ] - end + let(:packages) { [ "vim" ] } - it 'installs the base packages' do - packages.each do |package| - expect(subject).to install_package(package) - end + it "installs the base packages" do + expect(subject).to install_package(packages) end end diff --git a/spec/delayed_job_spec.rb b/spec/delayed_job_spec.rb deleted file mode 100644 index aa1135c..0000000 --- a/spec/delayed_job_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -describe "stronglifters-rails::delayed_job" do - subject do - ChefSpec::SoloRunner.new do |node| - node.set['delayed_job'] = configuration#.merge(node['delayed_job']) - end.converge(described_recipe) - end - - let(:username) { FFaker::Internet.user_name } - let(:configuration) do - { - username: username, - current_path: '/tmp', - rails_env: :production, - } - end - - it 'creates the init.d script' do - expect(subject).to create_template("/etc/init.d/delayed_job") - .with_owner(username) - .with_group(username) - .with_mode("0744") - end - - context "when the application has been deployed" do - before :each do - FileUtils.touch('/tmp/Gemfile') - end - - after :each do - FileUtils.rm('/tmp/Gemfile') - end - - it 'starts the delayed_job service' do - expect(subject).to start_service('delayed_job') - end - end -end diff --git a/spec/monit_spec.rb b/spec/monit_spec.rb deleted file mode 100644 index 7d25f84..0000000 --- a/spec/monit_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -describe "stronglifters-rails::monit" do - subject do - ChefSpec::SoloRunner.new do |node| - end.converge(described_recipe) - end - - it 'installs monit' do - expect(subject).to install_package('monit') - end - - it 'lays down the monitrc' do - expect(subject).to create_template("/etc/monit/monitrc") - .with_user('root') - .with_group('root') - end - - it 'starts the monit service' do - expect(subject).to start_service('monit') - end -end diff --git a/spec/nginx_spec.rb b/spec/nginx_spec.rb index 381ea94..c2fe3dd 100644 --- a/spec/nginx_spec.rb +++ b/spec/nginx_spec.rb @@ -1,69 +1,49 @@ -describe 'stronglifters-rails::nginx' do +describe "stronglifters::nginx" do let(:domain) { "www.example.com" } - let(:chef_run) do + subject do ChefSpec::SoloRunner.new do |node| - node.set['nginx']['domain'] = domain - node.set['lsb']['codename'] = 'trusty' + node.set["nginx"]["domain"] = domain end.converge(described_recipe) end - it 'installs nginx' do - expect(chef_run).to install_package("nginx") + it "installs nginx" do + expect(subject).to install_package("nginx") end - it 'creates a directory for the ssl certificates' do - expect(chef_run).to create_directory('/etc/nginx/ssl') - .with_owner('root') - .with_group('root') - .with_mode('0644') + it "creates a directory for the ssl certificates" do + expect(subject).to create_directory("/etc/nginx/ssl") end - it 'copies the ssl certificate' do - expect(chef_run).to create_template("/etc/nginx/ssl/#{domain}.crt") - .with_mode("0644") + it "copies the ssl certificate" do + expect(subject).to create_template("/etc/nginx/ssl/#{domain}.crt") end - it 'copies the ssl private key' do - expect(chef_run).to create_template("/etc/nginx/ssl/#{domain}.key") - .with_mode("0644") + it "copies the ssl private key" do + expect(subject).to create_template("/etc/nginx/ssl/#{domain}.key") end - it 'copies over the blacklist file' do - expect(chef_run).to create_cookbook_file("/etc/nginx/conf.d/blacklist.conf") - .with_mode("0644") + it "adds the configuration for the website" do + expect(subject).to create_template("/etc/nginx/nginx.conf") end - it 'adds the configuration for the website' do - expect(chef_run).to create_template("/etc/nginx/sites-available/#{domain}") - .with_mode("0644") + it "restarts nginx" do + resource = subject.template("/etc/nginx/nginx.conf") + expect(resource).to notify("service[nginx]").to(:restart).delayed end - it 'restarts nginxj' do - resource = chef_run.template("/etc/nginx/sites-available/#{domain}") - expect(resource).to notify('service[nginx]').to(:restart).delayed + it "starts nginx" do + expect(subject).to start_service("nginx") end - it 'starts nginx' do - expect(chef_run).to start_service('nginx') + it "installs logrotate" do + expect(subject).to install_package("logrotate") end - it 'creates a symlink to the sites-enabled directory' do - expect(chef_run).to create_link("/etc/nginx/sites-enabled/#{domain}") + it "creates the log directory for nginx" do + expect(subject).to create_directory("/var/log/nginx") end - it 'deletes the default website' do - expect(chef_run).to delete_file("/etc/nginx/sites-enabled/default") - end - - it 'installs logrotate' do - expect(chef_run).to install_package('logrotate') - end - - it 'creates the log directory for nginx' do - expect(chef_run).to create_directory('/var/log/nginx').with_mode('0755') - end - - it 'adds the logrotate config for rotating nginx logs' do - expect(chef_run).to create_template("/etc/logrotate.d/nginx") + it "adds the logrotate config for rotating nginx logs" do + expect(subject).to create_template("/etc/logrotate.d/nginx") end end diff --git a/spec/nodejs_spec.rb b/spec/nodejs_spec.rb deleted file mode 100644 index a4332df..0000000 --- a/spec/nodejs_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -describe "stronglifters-rails::nodejs" do - let(:chef_run) do - ChefSpec::SoloRunner.new do |node| - node.set["lsb"]["codename"] = "trusty" - end.converge(described_recipe) - end - - it "upgrades nodejs" do - expect(chef_run).to upgrade_package("nodejs") - end -end diff --git a/spec/postgres_spec.rb b/spec/postgres_spec.rb index cf6b277..c2d618b 100644 --- a/spec/postgres_spec.rb +++ b/spec/postgres_spec.rb @@ -1,4 +1,4 @@ -describe "stronglifters-rails::postgres" do +describe "stronglifters::postgres" do subject do ChefSpec::SoloRunner.new do |node| node.set["postgres"]["database"] = database_name @@ -6,7 +6,6 @@ describe "stronglifters-rails::postgres" do node.set["postgres"]["username"] = database_user node.set["postgresql"]["password"]['postgres'] = database_password node.set["postgresql"]["config"] = {} - node.set["rbenv"]["install_pkgs"] = [] end.converge(described_recipe) end diff --git a/spec/puma_spec.rb b/spec/puma_spec.rb deleted file mode 100644 index bf8c259..0000000 --- a/spec/puma_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -describe "stronglifters-rails::puma" do - subject do - ChefSpec::SoloRunner.new do |node| - node.set['puma'] = configuration - end.converge(described_recipe) - end - - let(:username) { FFaker::Internet.user_name } - let(:configuration) do - { - username: username, - current_path: '/tmp', - } - end - - it 'creates the puma init.d script' do - expect(subject).to create_template("/etc/init.d/puma") - .with_source("puma.erb") - .with_owner(username) - .with_group(username) - .with_mode("0744") - end - - context "when the app is deployed" do - before :each do - FileUtils.touch('/tmp/Gemfile') - end - - after :each do - FileUtils.rm('/tmp/Gemfile') - end - - it 'starts the puma service' do - expect(subject).to start_service("puma") - end - end -end diff --git a/spec/rails_spec.rb b/spec/rails_spec.rb new file mode 100644 index 0000000..10ade29 --- /dev/null +++ b/spec/rails_spec.rb @@ -0,0 +1,23 @@ +describe "stronglifters::rails" do + subject do + ChefSpec::SoloRunner.new do |node| + node.set["stronglifters"]["root_path"] = root_path + node.set["stronglifters"]["username"] = username + node.set["postgres"]["database"] = "app" + node.set["postgres"]["username"] = username + node.set["postgres"]["password"] = "password" + node.set["postgres"]["host"] = "localhost" + end.converge(described_recipe) + end + let(:root_path) { "/var/www/#{FFaker::Internet.domain_name}" } + let(:shared_path) { "#{root_path}/shared" } + let(:username) { "deployer" } + + before :each do + stub_command("stat -c %U #{root_path} | grep root").and_return(nil) + end + + it "creates the root directory for the application" do + expect(subject).to create_directory(root_path) + end +end diff --git a/spec/rbenv_spec.rb b/spec/rbenv_spec.rb deleted file mode 100644 index 696775e..0000000 --- a/spec/rbenv_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -describe "stronglifters-rails::rbenv" do - subject do - ChefSpec::SoloRunner.new do |node| - end.converge(described_recipe) - end - - xit 'installs rbenv' do - expect(subject).to sync_git("/usr/local/rbenv") - end - - xit 'creates the rbenv plugins directory' do - expect(subject).to create_directory('/usr/local/rbenv/plugins') - end - - xit 'installs ruby-build' do - expect(subject).to sync_git("/usr/local/rbenv/plugins/ruby-build") - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a849feb..2ff6e50 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,94 +1,17 @@ -# This file was generated by the `rspec --init` command. Conventionally, all -# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. -# The generated `.rspec` file contains `--require spec_helper` which will cause -# this file to always be loaded, without a need to explicitly require it in any -# files. -# -# Given that it is always loaded, you are encouraged to keep this file as -# light-weight as possible. Requiring heavyweight dependencies from this file -# will add to the boot time of your test suite on EVERY test run, even for an -# individual file that may not need all of that loaded. Instead, consider making -# a separate helper file that requires the additional dependencies and performs -# the additional setup, and require it from the spec files that actually need -# it. -require 'chefspec' -require 'chefspec/berkshelf' -require 'ffaker' +require "chefspec" +require "chefspec/berkshelf" +require "ffaker" -# The `.rspec` file also contains a few flags that are not defaults but that -# users commonly want. -# -# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| - # rspec-expectations config goes here. You can use an alternate - # assertion/expectation library such as wrong or the stdlib/minitest - # assertions if you prefer. config.expect_with :rspec do |expectations| - # This option will default to `true` in RSpec 4. It makes the `description` - # and `failure_message` of custom matchers include text for helper methods - # defined using `chain`, e.g.: - # be_bigger_than(2).and_smaller_than(4).description - # # => "be bigger than 2 and smaller than 4" - # ...rather than: - # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true end - - # rspec-mocks config goes here. You can use an alternate test double - # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| - # Prevents you from mocking or stubbing a method that does not exist on - # a real object. This is generally recommended, and will default to - # `true` in RSpec 4. mocks.verify_partial_doubles = true end - -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # These two settings work together to allow you to limit a spec run - # to individual examples or groups you care about by tagging them with - # `:focus` metadata. When nothing is tagged with `:focus`, all examples - # get run. config.filter_run :focus config.run_all_when_everything_filtered = true - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax - # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching - config.disable_monkey_patching! - - # This setting enables warnings. It's recommended, but in some cases may - # be too noisy due to issues in dependencies. - config.warnings = true - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = 'doc' - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 + config.warnings = false config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. Kernel.srand config.seed -=end end diff --git a/spec/unicorn_spec.rb b/spec/unicorn_spec.rb deleted file mode 100644 index 7311705..0000000 --- a/spec/unicorn_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -describe "stronglifters-rails::unicorn" do - subject do - ChefSpec::SoloRunner.new do |node| - node.set['unicorn'] = configuration - end.converge(described_recipe) - end - - let(:username) { FFaker::Internet.user_name } - let(:configuration) do - { - username: username, - current_path: '/tmp', - } - end - - it 'creates the unicorn init.d script' do - expect(subject).to create_template("/etc/init.d/unicorn") - .with_source("unicorn.erb") - .with_owner(username) - .with_group(username) - .with_mode("0744") - end - - context "when the app is deployed" do - before :each do - FileUtils.touch('/tmp/Gemfile') - end - - after :each do - FileUtils.rm('/tmp/Gemfile') - end - - it 'starts the unicorn service' do - expect(subject).to start_service("unicorn") - end - end -end diff --git a/spec/user_spec.rb b/spec/user_spec.rb index a88e0d7..4dc8d83 100644 --- a/spec/user_spec.rb +++ b/spec/user_spec.rb @@ -1,13 +1,13 @@ -describe "stronglifters-rails::user" do +describe "stronglifters::user" do subject do ChefSpec::SoloRunner.new do |node| - node.set['user']['username'] = username + node.set["stronglifters"]["username"] = username end.converge(described_recipe) end let(:username) { FFaker::Internet.user_name } - it 'creates the rails user' do + it "creates the rails user" do expect(subject).to create_user(username) end end diff --git a/templates/.profile.erb b/templates/.profile.erb new file mode 100644 index 0000000..d5e2045 --- /dev/null +++ b/templates/.profile.erb @@ -0,0 +1,3 @@ +<% @env.each do |key, value| %> +<%= key.to_s.upcase %>="<%= value.to_s.gsub("\n", '\n') %>" +<% end %> diff --git a/templates/default/aws/config.erb b/templates/config.erb index a0ea164..a0ea164 100644 --- a/templates/default/aws/config.erb +++ b/templates/config.erb diff --git a/templates/default/aws/credentials.erb b/templates/credentials.erb index 4effbe9..4effbe9 100644 --- a/templates/default/aws/credentials.erb +++ b/templates/credentials.erb diff --git a/templates/default/database.yml.erb b/templates/database.yml.erb index 855f96f..855f96f 100644 --- a/templates/default/database.yml.erb +++ b/templates/database.yml.erb diff --git a/templates/default/bashrc.erb b/templates/default/bashrc.erb deleted file mode 100644 index 676ba31..0000000 --- a/templates/default/bashrc.erb +++ /dev/null @@ -1,96 +0,0 @@ -if [ -d /usr/local/rbenv ]; then - export PATH="/usr/local/rbenv/bin:$PATH" - eval "$(rbenv init -)" -fi - -# If not running interactively, don't do anything -[ -z "$PS1" ] && return - -HISTCONTROL=ignoreboth -shopt -s histappend -HISTSIZE=1000 -HISTFILESIZE=2000 -shopt -s checkwinsize - -# make less more friendly for non-text input files, see lesspipe(1) -[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" - -# set variable identifying the chroot you work in (used in the prompt below) -if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then - debian_chroot=$(cat /etc/debian_chroot) -fi - -# set a fancy prompt (non-color, unless we know we "want" color) -case "$TERM" in - xterm-color) color_prompt=yes;; -esac - -# uncomment for a colored prompt, if the terminal has the capability; turned -# off by default to not distract the user: the focus in a terminal window -# should be on the output of commands, not on the prompt -#force_color_prompt=yes - -if [ -n "$force_color_prompt" ]; then - if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then - # We have color support; assume it's compliant with Ecma-48 - # (ISO/IEC-6429). (Lack of such support is extremely rare, and such - # a case would tend to support setf rather than setaf.) - color_prompt=yes - else - color_prompt= - fi -fi - -if [ "$color_prompt" = yes ]; then - PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' -else - PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' -fi -unset color_prompt force_color_prompt - -# If this is an xterm set the title to user@host:dir -case "$TERM" in -xterm*|rxvt*) - PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" - ;; -*) - ;; -esac - -# enable color support of ls and also add handy aliases -if [ -x /usr/bin/dircolors ]; then - test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" - alias ls='ls --color=auto' - #alias dir='dir --color=auto' - #alias vdir='vdir --color=auto' - - alias grep='grep --color=auto' - alias fgrep='fgrep --color=auto' - alias egrep='egrep --color=auto' -fi - -# some more ls aliases -alias ll='ls -alF' -alias la='ls -A' -alias l='ls -CF' - -# Add an "alert" alias for long running commands. Use like so: -# sleep 10; alert -alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' - -# Alias definitions. -# You may want to put all your additions into a separate file like -# ~/.bash_aliases, instead of adding them here directly. -# See /usr/share/doc/bash-doc/examples in the bash-doc package. - -if [ -f ~/.bash_aliases ]; then - . ~/.bash_aliases -fi - -# enable programmable completion features (you don't need to enable -# this, if it's already enabled in /etc/bash.bashrc and /etc/profile -# sources /etc/bash.bashrc). -if [ -f /etc/bash_completion ] && ! shopt -oq posix; then - . /etc/bash_completion -fi -set -o vi diff --git a/templates/default/delayed_job.erb b/templates/default/delayed_job.erb deleted file mode 100644 index d959972..0000000 --- a/templates/default/delayed_job.erb +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -### BEGIN INIT INFO -# Provides: delayed_job -# Required-Start: $all -# Required-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: -### END INIT INFO -set -e - -usage() { - echo "Usage: /etc/init.d/delayed_job {start|stop|status|restart|force-reload} <environment>" >&2 - exit 1 -} - -interact() { - op="$1" - echo "$1ing delayed_job" - su - -c "cd <%= @current_path %>; RAILS_ENV=<%= @rails_env %> bin/delayed_job $op" <%= @username %> -} - -case "$1" in - start|stop|status) - interact "$1" - ;; - reload|restart|force-reload) - interact restart - ;; - *) - usage - ;; -esac - -exit 0 diff --git a/templates/default/env.erb b/templates/default/env.erb deleted file mode 100644 index 0c9b641..0000000 --- a/templates/default/env.erb +++ /dev/null @@ -1,3 +0,0 @@ -<% @env.each do |key, value| %> -<%= key.to_s.upcase %>=<%= value %> -<% end %> diff --git a/templates/default/monit/monitrc.erb b/templates/default/monit/monitrc.erb deleted file mode 100644 index 487b879..0000000 --- a/templates/default/monit/monitrc.erb +++ /dev/null @@ -1,16 +0,0 @@ -set daemon 30 - -set logfile /var/log/monit.log -set idfile /var/lib/monit/id -set statefile /var/lib/monit/state - -set eventqueue - basedir /var/lib/monit/events - slots 100 - -check system <%= @application %> - if loadavg(5min) > 2 for 2 cycles then alert - if memory > 75% for 2 cycles then alert - if cpu(user) > 75% for 2 cycles then alert - -include /etc/monit/conf.d/* diff --git a/templates/default/nginx_unix.erb b/templates/default/nginx_unix.erb deleted file mode 100644 index 49f404b..0000000 --- a/templates/default/nginx_unix.erb +++ /dev/null @@ -1,69 +0,0 @@ -upstream backend { - server unix:<%= @socket_file %> fail_timeout=0; -} - -client_max_body_size 4G; - -server { - listen 80 deferred; - server_name <%= @domain %>; - rewrite ^ https://$server_name$request_uri? permanent; -} - -server { - listen 443 default_server ssl; - server_name <%= @domain %>; - root <%= @current_path %>/public; - ssl_certificate /etc/nginx/ssl/<%= @domain %>.crt; - ssl_certificate_key /etc/nginx/ssl/<%= @domain %>.key; - - ssl_protocols TLSv1 TLSv1.1 TLSv1.2; - ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH; - ssl_prefer_server_ciphers on; - ssl_session_cache shared:SSL:10m; - #ssl_stapling on; - #ssl_stapling_verify on; - #resolver 8.8.8.8 8.8.4.4 valid=300s; - #resolver_timeout 5s; - - error_log /var/log/nginx/<%= @domain %>.error.log; - access_log /var/log/nginx/<%= @domain %>.access.log; - - # enable HTST - add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"; - - # disable loading in an iframe - add_header X-Frame-Options "DENY"; - - if ($http_user_agent ~* (wget|easouspider|ahrefsbot|httrack|htmlparser|libwww) ) { - return 403; - } - - # Deny access based on the Referer header. - if ($http_referer ~* (babes|click|diamond|forsale|girl|jewelry|love|nudit|organic|poker|porn|poweroversoftware|sex|teen|webcam|zippo|casino|replica) ) { - return 444; - } - - if ($host = '<%= @domain.gsub(/www/, '') %>' ) { - rewrite ^/(.*)$ https://<%= @domain %>/$1 permanent; - } - - try_files $uri/index.html $uri @application; - location ^~ /assets/ { - gzip_static on; - expires max; - add_header Cache-Control public; - } - - location @application { - proxy_set_header X_FORWARDED_PROTO https; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header HOST $http_host; - proxy_set_header X-Url-Scheme $scheme; - proxy_redirect off; - proxy_pass http://backend; - } - - error_page 500 502 503 504 /500.html; - keepalive_timeout 10; -} diff --git a/templates/default/puma.conf.erb b/templates/default/puma.conf.erb deleted file mode 100644 index 2ab955f..0000000 --- a/templates/default/puma.conf.erb +++ /dev/null @@ -1 +0,0 @@ -<%= @current_path %>,<%= @username %>,<%= @current_path %>/config/puma_production.rb,<%= @current_path %>/log/puma.log diff --git a/templates/default/puma.erb b/templates/default/puma.erb deleted file mode 100644 index eb6c08f..0000000 --- a/templates/default/puma.erb +++ /dev/null @@ -1,349 +0,0 @@ -#! /bin/sh -### BEGIN INIT INFO -# Provides: puma -# Required-Start: $remote_fs $syslog -# Required-Stop: $remote_fs $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Example initscript -# Description: This file should be used to construct scripts to be -# placed in /etc/init.d. -# https://github.com/puma/puma/tree/master/tools/jungle/init.d -### END INIT INFO - -# Author: DarĂo Javier Cravero <dario@exordo.com> -# -# Do NOT "set -e" - -# PATH should only include /usr/* if it runs after the mountnfs.sh script -PATH=/usr/local/bin:/usr/local/sbin/:/sbin:/usr/sbin:/bin:/usr/bin -DESC="Puma rack web server" -NAME=puma -DAEMON=$NAME -SCRIPTNAME=/etc/init.d/$NAME -CONFIG=/etc/puma.conf -JUNGLE=`cat $CONFIG` -RUNPUMA=/usr/local/bin/run-puma -PUMACTL=/usr/local/rbenv/shims/pumactl - -# Load the VERBOSE setting and other rcS variables -. /lib/init/vars.sh - -# Define LSB log_* functions. -# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. -. /lib/lsb/init-functions - -# -# Function that starts the jungle -# -do_start() { - log_daemon_msg "=> Running the jungle..." - for i in $JUNGLE; do - dir=`echo $i | cut -d , -f 1` - user=`echo $i | cut -d , -f 2` - config_file=`echo $i | cut -d , -f 3` - if [ "$config_file" = "" ]; then - config_file="$dir/config/puma.rb" - fi - log_file=`echo $i | cut -d , -f 4` - if [ "$log_file" = "" ]; then - log_file="$dir/log/puma.log" - fi - environment=`echo $i | cut -d , -f 5` - do_start_one $dir $user $config_file $log_file $environment - done -} - -do_start_one() { - PIDFILE=$1/tmp/pids/puma.pid - if [ -e $PIDFILE ]; then - PID=`cat $PIDFILE` - # If the puma isn't running, run it, otherwise restart it. - if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then - do_start_one_do $1 $2 $3 $4 $5 - else - do_restart_one $1 - fi - else - do_start_one_do $1 $2 $3 $4 $5 - fi -} - -do_start_one_do() { - log_daemon_msg "--> Woke up puma $1" - log_daemon_msg "user $2" - log_daemon_msg "log to $4" - - if [ ! -z "$5" ]; then - for e in $(echo "$5" | tr ';' '\n'); do - log_daemon_msg "environment $e" - v=${e%%\=*} ; eval "$e" ; export $v - done - fi - - start-stop-daemon --verbose --start --chdir $1 --chuid $2 --background --exec $RUNPUMA -- $1 $3 $4 -} - -# -# Function that stops the jungle -# -do_stop() { - log_daemon_msg "=> Putting all the beasts to bed..." - for i in $JUNGLE; do - dir=`echo $i | cut -d , -f 1` - do_stop_one $dir - done -} -# -# Function that stops the daemon/service -# -do_stop_one() { - log_daemon_msg "--> Stopping $1" - PIDFILE=$1/tmp/pids/puma.pid - STATEFILE=$1/tmp/pids/puma.state - if [ -e $PIDFILE ]; then - PID=`cat $PIDFILE` - if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then - log_daemon_msg "---> Puma $1 isn't running." - else - log_daemon_msg "---> About to kill PID `cat $PIDFILE`" - $PUMACTL --state $STATEFILE stop - # Many daemons don't delete their pidfiles when they exit. - rm -f $PIDFILE $STATEFILE - fi - else - log_daemon_msg "---> No puma here..." - fi - return 0 -} - -# -# Function that restarts the jungle -# -do_restart() { - for i in $JUNGLE; do - dir=`echo $i | cut -d , -f 1` - do_restart_one $dir - done -} - -# -# Function that sends a SIGUSR2 to the daemon/service -# -do_restart_one() { - PIDFILE=$1/tmp/pids/puma.pid - i=`grep $1 $CONFIG` - dir=`echo $i | cut -d , -f 1` - - if [ -e $PIDFILE ]; then - log_daemon_msg "--> About to restart puma $1" - $PUMACTL --state $dir/tmp/pids/puma.state restart - # kill -s USR2 `cat $PIDFILE` - # TODO Check if process exist - else - log_daemon_msg "--> Your puma was never playing... Let's get it out there first" - user=`echo $i | cut -d , -f 2` - config_file=`echo $i | cut -d , -f 3` - if [ "$config_file" = "" ]; then - config_file="$dir/config/puma.rb" - fi - log_file=`echo $i | cut -d , -f 4` - if [ "$log_file" = "" ]; then - log_file="$dir/log/puma.log" - fi - environment=`echo $i | cut -d , -f 5` - do_start_one $dir $user $config_file $log_file $environment - fi - return 0 -} - -# -# Function that statuss the jungle -# -do_status() { - for i in $JUNGLE; do - dir=`echo $i | cut -d , -f 1` - do_status_one $dir - done -} - -# -# Function that sends a SIGUSR2 to the daemon/service -# -do_status_one() { - PIDFILE=$1/tmp/pids/puma.pid - i=`grep $1 $CONFIG` - dir=`echo $i | cut -d , -f 1` - - if [ -e $PIDFILE ]; then - log_daemon_msg "--> About to status puma $1" - $PUMACTL --state $dir/tmp/pids/puma.state stats - # kill -s USR2 `cat $PIDFILE` - # TODO Check if process exist - else - log_daemon_msg "--> $1 isn't there :(..." - fi - return 0 -} - -do_add() { - str="" - # App's directory - if [ -d "$1" ]; then - if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then - str=$1 - else - echo "The app is already being managed. Remove it if you want to update its config." - exit 1 - fi - else - echo "The directory $1 doesn't exist." - exit 1 - fi - # User to run it as - if [ "`grep -c "^$2:" /etc/passwd`" -eq 0 ]; then - echo "The user $2 doesn't exist." - exit 1 - else - str="$str,$2" - fi - # Config file - if [ "$3" != "" ]; then - if [ -e $3 ]; then - str="$str,$3" - else - echo "The config file $3 doesn't exist." - exit 1 - fi - fi - # Log file - if [ "$4" != "" ]; then - str="$str,$4" - fi - - # Environment variables - if [ "$5" != "" ]; then - str="$str,$5" - fi - - # Add it to the jungle - echo $str >> $CONFIG - log_daemon_msg "Added a Puma to the jungle: $str. You still have to start it though." -} - -do_remove() { - if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then - echo "There's no app $1 to remove." - else - # Stop it first. - do_stop_one $1 - # Remove it from the config. - sed -i "\\:^$1:d" $CONFIG - log_daemon_msg "Removed a Puma from the jungle: $1." - fi -} - -case "$1" in - start) - [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" - if [ "$#" -eq 1 ]; then - do_start - else - i=`grep $2 $CONFIG` - dir=`echo $i | cut -d , -f 1` - user=`echo $i | cut -d , -f 2` - config_file=`echo $i | cut -d , -f 3` - if [ "$config_file" = "" ]; then - config_file="$dir/config/puma.rb" - fi - log_file=`echo $i | cut -d , -f 4` - if [ "$log_file" = "" ]; then - log_file="$dir/log/puma.log" - fi - do_start_one $dir $user $config_file $log_file - fi - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - stop) - [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" - if [ "$#" -eq 1 ]; then - do_stop - else - i=`grep $2 $CONFIG` - dir=`echo $i | cut -d , -f 1` - do_stop_one $dir - fi - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - status) - # TODO Implement. - log_daemon_msg "Status $DESC" "$NAME" - if [ "$#" -eq 1 ]; then - do_status - else - i=`grep $2 $CONFIG` - dir=`echo $i | cut -d , -f 1` - do_status_one $dir - fi - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - restart) - log_daemon_msg "Restarting $DESC" "$NAME" - if [ "$#" -eq 1 ]; then - do_restart - else - i=`grep $2 $CONFIG` - dir=`echo $i | cut -d , -f 1` - do_restart_one $dir - fi - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - add) - if [ "$#" -lt 3 ]; then - echo "Please, specifiy the app's directory and the user that will run it at least." - echo " Usage: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log" - echo " config and log are optionals." - exit 1 - else - do_add $2 $3 $4 $5 - fi - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - remove) - if [ "$#" -lt 2 ]; then - echo "Please, specifiy the app's directory to remove." - exit 1 - else - do_remove $2 - fi - case "$?" in - 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; - 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; - esac - ;; - *) - echo "Usage:" >&2 - echo " Run the jungle: $SCRIPTNAME {start|stop|status|restart}" >&2 - echo " Add a Puma: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log" - echo " config and log are optionals." - echo " Remove a Puma: $SCRIPTNAME remove /path/to/app" - echo " On a Puma: $SCRIPTNAME {start|stop|status|restart} PUMA-NAME" >&2 - exit 3 - ;; -esac -: diff --git a/templates/default/run-puma.erb b/templates/default/run-puma.erb deleted file mode 100644 index 4f7c55d..0000000 --- a/templates/default/run-puma.erb +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -app=$1; config=$2; log=$3; -cd $app && exec /usr/local/rbenv/shims/bundle exec puma -C $config 2>&1 >> $log diff --git a/templates/default/unicorn.erb b/templates/default/unicorn.erb deleted file mode 100644 index 48654a7..0000000 --- a/templates/default/unicorn.erb +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/sh -### BEGIN INIT INFO -# Provides: unicorn -# Required-Start: $remote_fs $syslog -# Required-Stop: $remote_fs $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Start unicorn at boot time -# Description: Run input app server -### END INIT INFO -set -e -# Example init script, this can be used with nginx, too, -# since nginx and unicorn accept the same signals - -# Feel free to change any of the following variables for your app: -TIMEOUT=${TIMEOUT-60} -APP_ROOT=<%= @current_path %> -PID=$APP_ROOT/tmp/pids/unicorn.pid -ENVIRONMENT=<%= @rails_env %> -CMD="cd $APP_ROOT; bin/unicorn -E $ENVIRONMENT -D -c $APP_ROOT/config/unicorn.rb" -action="$1" -set -u - -old_pid="$PID.oldbin" - -cd $APP_ROOT || exit 1 - -sig () { - test -s "$PID" && kill -$1 `cat $PID` -} - -oldsig () { - test -s $old_pid && kill -$1 `cat $old_pid` -} - -workersig () { - workerpid="$APP_ROOT/tmp/pids/unicorn.$2.pid" - test -s "$workerpid" && kill -$1 `cat $workerpid` -} - -case $action in -status ) - sig 0 && echo >&2 "unicorn is running." && exit 0 - echo >&2 "unicorn is not running." && exit 1 - ;; -start) - sig 0 && echo >&2 "Already running" && exit 0 - eval "$CMD" - ;; -stop) - sig QUIT && exit 0 - echo >&2 "Not running" - ;; -force-stop) - sig TERM && exit 0 - echo >&2 "Not running" - ;; -restart|reload) - sig HUP && echo reloaded OK && exit 0 - echo >&2 "Couldn't reload, starting '$CMD' instead" - eval "$CMD" - ;; -upgrade) - if sig USR2 && sleep 20 && sig 0 && oldsig QUIT - then - n=$TIMEOUT - while test -s $old_pid && test $n -ge 0 - do - printf '.' && sleep 1 && n=$(( $n - 1 )) - done - echo - - if test $n -lt 0 && test -s $old_pid - then - echo >&2 "$old_pid still exists after $TIMEOUT seconds" - exit 1 - fi - exit 0 - fi - echo >&2 "Couldn't upgrade, starting '$CMD' instead" - eval "$CMD" - ;; -kill_worker) - workersig QUIT $2 && exit 0 - echo >&2 "Worker not running" - ;; - -reopen-logs) - sig USR1 - ;; -*) - echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>" - exit 1 - ;; -esac diff --git a/templates/nginx.conf.erb b/templates/nginx.conf.erb new file mode 100644 index 0000000..ac7e624 --- /dev/null +++ b/templates/nginx.conf.erb @@ -0,0 +1,91 @@ +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + client_max_body_size 4G; + <% @blacklisted_ips.each do |ip| %> + deny <%= ip %>; + <% end %> + + upstream backend { + server 127.0.0.1:9292 fail_timeout=0; + } + + server { + listen 80 deferred; + server_name <%= @domain %>; + server_tokens off; + rewrite ^ https://$server_name$request_uri? permanent; + } + server { + listen 443 default_server ssl; + server_name <%= @domain %>; + server_tokens off; + root <%= node['stronglifters']['root_path'] %>/current/public; + ssl_certificate /etc/nginx/ssl/<%= @domain %>.crt; + ssl_certificate_key /etc/nginx/ssl/<%= @domain %>.key; + + ssl_session_timeout 5m; + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; + ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH; + ssl_prefer_server_ciphers on; + ssl_session_cache shared:SSL:10m; + #ssl_stapling on; + #ssl_stapling_verify on; + #resolver 8.8.8.8 8.8.4.4 valid=300s; + #resolver_timeout 5s; + + error_log /var/log/nginx/<%= @domain %>.error.log; + access_log /var/log/nginx/<%= @domain %>.access.log; + + # enable HTST + add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"; + + # disable loading in an iframe + add_header X-Frame-Options "DENY"; + + if ($host = '<%= @domain.gsub(/www/, '') %>' ) { + rewrite ^/(.*)$ https://<%= @domain %>/$1 permanent; + } + + try_files $uri/index.html $uri @application; + location ^~ /assets/ { + gzip_static on; + expires max; + add_header Cache-Control public; + } + + location @application { + proxy_set_header X_FORWARDED_PROTO https; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header HOST $http_host; + proxy_set_header X-Url-Scheme $scheme; + proxy_redirect off; + proxy_pass http://backend; + } + + error_page 500 502 503 504 /500.html; + keepalive_timeout 10; + } +} diff --git a/templates/default/nginx_logrotate.erb b/templates/nginx_logrotate.erb index 1f16f97..1f16f97 100644 --- a/templates/default/nginx_logrotate.erb +++ b/templates/nginx_logrotate.erb diff --git a/templates/default/rails_logrotate.erb b/templates/rails_logrotate.erb index 1650678..1650678 100644 --- a/templates/default/rails_logrotate.erb +++ b/templates/rails_logrotate.erb diff --git a/templates/default/ssl.crt.erb b/templates/ssl.crt.erb index 2a06083..2a06083 100644 --- a/templates/default/ssl.crt.erb +++ b/templates/ssl.crt.erb diff --git a/templates/default/ssl.key.erb b/templates/ssl.key.erb index 1bd8519..1bd8519 100644 --- a/templates/default/ssl.key.erb +++ b/templates/ssl.key.erb diff --git a/templates/sv-foreman-run.erb b/templates/sv-foreman-run.erb new file mode 100755 index 0000000..68930b5 --- /dev/null +++ b/templates/sv-foreman-run.erb @@ -0,0 +1,7 @@ +#!/bin/sh +exec 2>&1 +source /etc/profile.d/rbenv.sh +envdir=$(pwd)/env +cd <%= node['stronglifters']['root_path'] %>/current +exec chpst -u <%= node['stronglifters']['username'] %> \ + -e $envdir /usr/local/rbenv/shims/foreman start diff --git a/templates/sv-puma-run.erb b/templates/sv-puma-run.erb new file mode 100755 index 0000000..78993b5 --- /dev/null +++ b/templates/sv-puma-run.erb @@ -0,0 +1,6 @@ +#!/bin/sh +exec 2>&1 +source /etc/profile.d/rbenv.sh +envdir=$(pwd)/env +cd <%= node['stronglifters']['root_path'] %>/current +exec chpst -u <%= node['stronglifters']['username'] %> -e $envdir /usr/local/rbenv/shims/bundle exec puma -C config/puma_production.rb diff --git a/templates/sv-sidekiq-run.erb b/templates/sv-sidekiq-run.erb new file mode 100755 index 0000000..30b46e9 --- /dev/null +++ b/templates/sv-sidekiq-run.erb @@ -0,0 +1,6 @@ +#!/bin/sh +exec 2>&1 +source /etc/profile.d/rbenv.sh +envdir=$(pwd)/env +cd <%= node['stronglifters']['root_path'] %>/current +exec chpst -u <%= node['stronglifters']['username'] %> -e $envdir /usr/local/rbenv/shims/bundle exec sidekiq diff --git a/test/integration/db/serverspec/default_spec.rb b/test/integration/db/serverspec/default_spec.rb new file mode 100644 index 0000000..6497043 --- /dev/null +++ b/test/integration/db/serverspec/default_spec.rb @@ -0,0 +1,10 @@ +require "serverspec" + +set :backend, :exec + +describe "db" do + it "runs postgres" do + expect(service("postgresql")).to be_running + expect(port("5432")).to be_listening + end +end diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb new file mode 100644 index 0000000..2216d03 --- /dev/null +++ b/test/integration/default/serverspec/default_spec.rb @@ -0,0 +1,13 @@ +require "serverspec" + +set :backend, :exec + +describe "default" do + it 'installs the default version of ruby' do + expect(command("/usr/local/rbenv/shims/ruby -v").stdout).to match(/2\.2\.3/) + end + + it 'installs bundler' do + expect(file("/usr/local/rbenv/shims/bundle")).to be_file + end +end diff --git a/test/integration/web/serverspec/default_spec.rb b/test/integration/web/serverspec/default_spec.rb new file mode 100644 index 0000000..360abe9 --- /dev/null +++ b/test/integration/web/serverspec/default_spec.rb @@ -0,0 +1,15 @@ +require "serverspec" + +set :backend, :exec + +describe "web" do + it 'starts nginx' do + expect(service("nginx")).to be_running + expect(port(80)).to be_listening + expect(port(443)).to be_listening + end + + it 'installs foreman' do + expect(file("/usr/local/rbenv/shims/foreman")).to be_file + end +end |
