Skip to content

Commit

Permalink
Add deploy configs
Browse files Browse the repository at this point in the history
Allows for OD2 to be deployed to staging.
  • Loading branch information
Trey Terrell committed Jun 23, 2015
1 parent d20aaae commit 3b7f86e
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -32,3 +32,5 @@ rspec
config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml
/config/god.conf

4 changes: 4 additions & 0 deletions Capfile
@@ -0,0 +1,4 @@
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks
9 changes: 8 additions & 1 deletion Gemfile
Expand Up @@ -68,14 +68,21 @@ gem 'hurley'
gem 'rails_config'

gem 'marmotta'
gem 'passenger'
gem 'capistrano', '~> 2.0'
gem 'rspec-rails'
gem 'sprockets', '~>2.0'

group :production, :staging do
gem 'mysql2'
end

group :development, :test do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'rspec-rails'
gem 'spring-commands-rspec'
gem 'factory_girl_rails'
gem 'pry-byebug'
Expand Down
30 changes: 28 additions & 2 deletions Gemfile.lock
Expand Up @@ -143,6 +143,12 @@ GEM
columnize (~> 0.3)
debugger-linecache (~> 1.2)
cancancan (1.10.1)
capistrano (2.15.5)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
capybara (2.4.4)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
Expand Down Expand Up @@ -219,6 +225,8 @@ GEM
activesupport (>= 4.1.0)
haml (4.0.6)
tilt
highline (1.7.2)
hike (1.2.3)
htmlentities (4.3.3)
http-cookie (1.0.2)
domain_name (~> 0.5)
Expand Down Expand Up @@ -290,7 +298,15 @@ GEM
minitest (5.7.0)
multi_json (1.11.0)
multipart-post (2.0.0)
mysql2 (0.3.18)
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)
netrc (0.10.3)
newrelic_rpm (3.11.2.286)
noid (0.7.1)
Expand All @@ -308,6 +324,9 @@ GEM
orm_adapter (0.5.0)
parslet (1.7.0)
blankslate (>= 2.0, <= 4.0)
passenger (5.0.7)
rack
rake (>= 0.8.1)
poltergeist (1.5.1)
capybara (~> 2.1)
cliver (~> 0.3.1)
Expand All @@ -322,7 +341,7 @@ GEM
pry (~> 0.9.12)
pry-rails (0.3.4)
pry (>= 0.9.10)
rack (1.6.0)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.0)
Expand Down Expand Up @@ -477,8 +496,11 @@ GEM
spring (1.3.6)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
sprockets (3.0.3)
sprockets (2.12.3)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.2.4)
actionpack (>= 3.0)
activesupport (>= 3.0)
Expand Down Expand Up @@ -529,6 +551,7 @@ DEPENDENCIES
attr_extras
blacklight
blacklight_advanced_search
capistrano (~> 2.0)
capybara
capybara-screenshot
coffee-rails (~> 4.1.0)
Expand All @@ -549,8 +572,10 @@ DEPENDENCIES
jquery-rails
marmotta
mini_magick
mysql2
newrelic_rpm
noid
passenger
poltergeist
pry-byebug
pry-rails
Expand All @@ -566,6 +591,7 @@ DEPENDENCIES
simplecov
spring
spring-commands-rspec
sprockets (~> 2.0)
sqlite3
timecop
uglifier (>= 1.3.0)
Expand Down
5 changes: 4 additions & 1 deletion config/blacklight.yml
Expand Up @@ -7,5 +7,8 @@ test: &TEST
cucumber:
<<: *TEST
production:
url: http://your.production.server:8080/bl_solr/core0
url: <%= ENV["OD2_SOLR_URL"] %>
adapter: solr
staging:
url: <%= ENV["OD2_SOLR_URL"] %>
adapter: solr
17 changes: 14 additions & 3 deletions config/database.yml
Expand Up @@ -20,6 +20,17 @@ test:
<<: *default
database: db/test.sqlite3

production:
<<: *default
database: db/production.sqlite3
production: &production
adapter: <%= ENV['OD2_ADAPTER'] || "sqlite3" %>
database: <%= ENV['OD2_DB'] || 'db/production.sqlite3' %>
encoding: utf8
reconnect: false
username: <%= ENV['OD2_DB_USERNAME'] %>
password: <%= ENV['OD2_DB_PASSWORD'] %>
host: <%= ENV['OD2_DB_HOST'] %>
port: <%= ENV['OD2_DB_PORT'] || 3306 %>
pool: 5
timeout: 5000

staging:
<<: *production
52 changes: 52 additions & 0 deletions config/deploy.rb
@@ -0,0 +1,52 @@
require 'yaml'
config = YAML.load_file('config/settings.local.yml')["deployment"] || {}

require 'bundler/capistrano'

set :stages, config['stages'] || []
set :default_stage, config['default_stage'] || (config['stages'] || []).first
require 'capistrano/ext/multistage'

set :application, 'OregonDigital2'
set :repository, config['repository']
set :user, config['user']
set :default_environment, config['default_environment'] || {}
default_run_options[:pty] = true
set :scm, :git
set :branch, config['branch']
set :deploy_via, :remote_cache
set :use_sudo, false
set :keep_releases, 5
set :shared_children, shared_children + %w{pids sockets tmp public/uploads jetty}
set :ssh_options, {:forward_agent => true}

# if you want to clean up old releases on each deploy uncomment this:
after 'deploy:restart', 'deploy:cleanup'

after 'deploy:finalize_update', 'deploy:symlink_config'
after 'deploy:update_code', 'deploy:migrate'
after 'deploy:restart', 'deploy:cleanup'


namespace :deploy do
desc "Symlinks required configuration files"
task :symlink_config, :roles => :app do
%w{settings.local.yml god.conf}.each do |config_file|
run "ln -nfs #{deploy_to}/shared/config/#{config_file} #{release_path}/config/#{config_file}"
end
end
desc "Uploads local config files"
task :upload_config, :roles => :app do
%w{settings.local.yml god.conf}.each do |config_file|
top.run "mkdir -p #{deploy_to}/shared/config"
top.upload "config/#{config_file}", "#{deploy_to}/shared/config/#{config_file}", :via => :scp
end
end
end
namespace :rails do
desc "Opens up a rails console"
task :console, :roles => :app do
hostname = find_servers_for_task(current_task).first
exec "ssh -l #{user} #{hostname} -t 'source ~/.bash_profile && cd #{deploy_to}/current && export RBENV_VERSION=#{config[rails_env.to_s]['default_environment']['RBENV_VERSION']} && RAILS_ENV=#{rails_env} bundle exec rails c'"
end
end
52 changes: 52 additions & 0 deletions config/deploy/staging.rb
@@ -0,0 +1,52 @@
config = YAML.load_file('config/settings.local.yml')["deployment"]["staging"] || {}

set :user, config['user']
# Set RBEnv Stuff
set :default_environment, config['default_environment'] || {}
# Servers
role :web, config['hosts']['web'] # Your HTTP server, Apache/etc
role :app, config['hosts']['app'] # This may be the same as your `Web` server
role :db, config['hosts']['db'], :primary => true # This is where Rails migrations will run
# Git Config
set :branch, config['branch']
# God Settings
set(:god_app_path) {"#{current_path}/#{config['god']['app_path']}"}
set :god_sites_path, config['god']['sites_path']
set :deploy_to, config['deploy_to']
set :rails_env, :staging
# Deploy Commands
# Override deploy to inform god to do the restarts.
namespace :deploy do
task :start do
god.start
end
task :stop do
god.stop
end
task :restart do
god.restart
end
end

namespace :god do
desc "Reload god config"
task :reload, :roles => :app, :except => {:no_release => true} do
run "ln -nfs #{god_app_path} #{god_sites_path}/#{application}.conf"
sudo "/etc/init.d/god restart"
end

task :restart, :roles => :app, :except => {:no_release => true} do
run "touch #{shared_path}/tmp/restart.txt"
end

task :start, :roles => :app do
sudo "/etc/init.d/god startapp #{application}"
end

task :stop, :roles => :app do
sudo "/etc/init.d/god stopapp #{application}"
end
task :status, :roles => :app do
sudo "/etc/init.d/god status #{applictaion}"
end
end
5 changes: 5 additions & 0 deletions config/environments/staging.rb
@@ -0,0 +1,5 @@
require_relative 'production'

Rails.application.configure do
config.action_mailer.default_url_options = { host: 'od2-dev.library.oregonstate.edu' }
end
20 changes: 20 additions & 0 deletions config/fedora.yml
@@ -0,0 +1,20 @@
development:
user: fedoraAdmin
password: fedoraAdmin
url: http://127.0.0.1:8983/fedora/rest
base_path: /dev
test:
user: fedoraAdmin
password: fedoraAdmin
url: http://localhost:8983/fedora/rest
base_path: /test
production:
user: <%= ENV["OD2_FEDORA_USERNAME"] || "fedoraAdmin" %>
password: <%= ENV["OD2_FEDORA_PASSWORD"] || "fedoraAdmin" %>
url: <%= ENV["OD2_FEDORA_URL"] || "http://127.0.0.1:8983/fedora/rest" %>
base_path: /prod
staging:
user: <%= ENV["OD2_FEDORA_USERNAME"] || "fedoraAdmin" %>
password: <%= ENV["OD2_FEDORA_PASSWORD"] || "fedoraAdmin" %>
url: <%= ENV["OD2_FEDORA_URL"] || "http://127.0.0.1:8983/fedora/rest" %>
base_path: <%= ENV["OD2_FEDORA_BASE_PATH"] || "/staging" %>
14 changes: 7 additions & 7 deletions config/jetty.yml
@@ -1,12 +1,12 @@
default:
startup_wait: 90
jetty_port: 8983
java_opts:
- "-XX:MaxPermSize=128m"
- "-Xmx256m"
- "-Dmarmotta.home=<%= File.expand_path(MARMOTTA_HOME) %>"
test:
jetty_port: 8983
startup_wait: 60
- "-Xmx512m"
- "-XX:MaxPermSize=128m"
staging:
startup_wait: 90
jetty_port: <%= ENV["OD2_JETTY_PORT"] || "8983" %>
java_opts:
- "-XX:MaxPermSize=256m"
- "-Xmx512m"
- "-XX:MaxPermSize=128m"
5 changes: 4 additions & 1 deletion config/secrets.yml
Expand Up @@ -19,4 +19,7 @@ test:
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
secret_key_base: <%= ENV["OD2_SECRET_KEY_BASE"] %>

staging:
secret_key_base: <%= ENV["OD2_SECRET_KEY_BASE"] %>
2 changes: 2 additions & 0 deletions config/settings/staging.yml
@@ -0,0 +1,2 @@
marmotta:
url: <%= ENV["OD2_MARMOTTA_URL"] || "http://localhost:8983/marmotta" %>
9 changes: 9 additions & 0 deletions config/solr.yml
@@ -0,0 +1,9 @@
# This is a sample config file that points to a solr server for each environment
development:
url: http://localhost:8983/solr/development
test:
url: <%= "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8983}/solr/test" %>
production:
url: <%= ENV["OD2_SOLR_URL"] %>
staging:
url: <%= ENV["OD2_SOLR_URL"] %>

0 comments on commit 3b7f86e

Please sign in to comment.