Commit 7333ef6
Changed files (13)
attributes
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
files/gemrc
@@ -0,0 +1,1 @@
+gem: --no-document
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 -)"
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")
recipes/redis.rb
@@ -0,0 +1,1 @@
+package "redis-server"
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
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")
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")
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;
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
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
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
.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]