diff options
| author | mo khan <mo@mokhan.ca> | 2015-11-11 16:51:18 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-11-11 16:51:18 -0700 |
| commit | 7333ef66532c03d534dd2266373ba4329d019410 (patch) | |
| tree | 31cbca59e058a6f1435c49c2c923d3c4e37877d1 | |
| parent | 948586298f0991d652ecd2dede61e1bfb7b3aed1 (diff) | |
add sidekiq worker role.
| -rw-r--r-- | .kitchen.yml | 28 | ||||
| -rw-r--r-- | attributes/default.rb | 12 | ||||
| -rw-r--r-- | files/gemrc | 1 | ||||
| -rw-r--r-- | files/rbenv.sh | 1 | ||||
| -rw-r--r-- | recipes/rails.rb | 51 | ||||
| -rw-r--r-- | recipes/redis.rb | 1 | ||||
| -rw-r--r-- | recipes/ruby.rb | 1 | ||||
| -rw-r--r-- | recipes/web.rb | 11 | ||||
| -rw-r--r-- | recipes/worker.rb | 11 | ||||
| -rw-r--r-- | templates/nginx.conf.erb | 2 | ||||
| -rwxr-xr-x | templates/sv-foreman-run.erb | 2 | ||||
| -rwxr-xr-x | templates/sv-puma-run.erb | 6 | ||||
| -rwxr-xr-x | templates/sv-sidekiq-run.erb | 6 |
13 files changed, 86 insertions, 47 deletions
diff --git a/.kitchen.yml b/.kitchen.yml index 27faefb..9f06509 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -13,10 +13,26 @@ suites: - name: default run_list: - 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" + username: "rails" + password: "password" + host: "localhost" - name: web run_list: - recipe[stronglifters::default] - - recipe[stronglifters::rails] + - recipe[stronglifters::web] attributes: env: app_api_key: "api-key" @@ -26,6 +42,16 @@ suites: 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] diff --git a/attributes/default.rb b/attributes/default.rb index b504815..896af4c 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -29,11 +29,13 @@ else libcurl4-openssl-dev libffi-dev libreadline-dev + libsqlite3-dev libssl-dev libxml2-dev libxslt1-dev libyaml-dev python-software-properties + sqlite3 zlib1g-dev } end @@ -43,16 +45,22 @@ 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']['current_path'] = "#{node['stronglifters']['root_path']}/current" 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: '' + secret_token: '', } default['stronglifters']['nginx']['ssl']['key'] = <<-SELFSIGNED 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 index 0b3a2de..b6f9ad8 100644 --- a/files/rbenv.sh +++ b/files/rbenv.sh @@ -1,3 +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/recipes/rails.rb b/recipes/rails.rb index 8987163..ba6ca3b 100644 --- a/recipes/rails.rb +++ b/recipes/rails.rb @@ -1,60 +1,27 @@ include_recipe "stronglifters::user" include_recipe "stronglifters::aws" -include_recipe "stronglifters::nginx" -root_path = node['stronglifters']['root_path'] -shared_path = File.join(root_path, 'shared') -current_path = File.join(root_path, 'current') +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 -directories = [ - root_path, - shared_path, - "#{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 - mode "0755" - recursive true - action :create - end -end - -username = node['stronglifters']['username'] -execute "chown -R #{username}:#{username} #{root_path}" do - 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'], - }) +directory root_path do + mode "0755" + owner node["stronglifters"]["username"] + group node["stronglifters"]["username"] + recursive true end gem "foreman" -startup = File.exists?("#{current_path}/Gemfile") runit_service "foreman" do action [:enable, :start] default_logger true - env node['stronglifters']['env'] + env node["stronglifters"]["env"] log true retries 3 -end if startup +end if File.exists?("#{File.join(root_path, "current")}/Procfile") 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 index 6b7c635..6ebd5b6 100644 --- a/recipes/ruby.rb +++ b/recipes/ruby.rb @@ -3,6 +3,7 @@ git "/usr/local/rbenv" do 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 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/templates/nginx.conf.erb b/templates/nginx.conf.erb index 0505091..ebe1377 100644 --- a/templates/nginx.conf.erb +++ b/templates/nginx.conf.erb @@ -40,7 +40,7 @@ http { server { listen 443 default_server ssl; server_name <%= @domain %>; - root <%= node['stronglifters']['current_path'] %>/public; + root <%= node['stronglifters']['root_path'] %>/current/public; ssl_certificate /etc/nginx/ssl/<%= @domain %>.crt; ssl_certificate_key /etc/nginx/ssl/<%= @domain %>.key; diff --git a/templates/sv-foreman-run.erb b/templates/sv-foreman-run.erb index 79dcfca..ac9f376 100755 --- a/templates/sv-foreman-run.erb +++ b/templates/sv-foreman-run.erb @@ -2,5 +2,5 @@ exec 2>&1 source /etc/profile.d/rbenv.sh envdir=$(pwd)/env -cd <%= node['stronglifters']['foreman']['current_path'] %> +cd <%= node['stronglifters']['root_path'] %>/current exec chpst -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..79e535a --- /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 -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..cde9e21 --- /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 -e $envdir /usr/local/rbenv/shims/bundle exec sidekiq |
