Skip to content

Commit

Permalink
Enable Pomegranate Deploys
Browse files Browse the repository at this point in the history
Closes #15.
  • Loading branch information
Trey Terrell committed Jan 15, 2016
1 parent 4a8ca7f commit f8c5d75
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 9 deletions.
14 changes: 14 additions & 0 deletions Capfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Load DSL and set up stages
require 'capistrano/setup'

# Include default deployment tasks
require 'capistrano/deploy'

require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/passenger'
require 'capistrano/rails/console'

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
8 changes: 7 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ group :development, :test do
gem 'pry-rails'
gem 'simplecov', '~> 0.9', require: false
gem 'coveralls', require: false
gem 'rubocop', require: false
gem 'rubocop-rspec', require: false
gem 'vcr'
gem 'webmock', require: false
gem 'capybara'
gem 'factory_girl_rails', require: false
gem 'poltergeist'
gem 'capistrano-rails'
gem 'capistrano-passenger'
gem 'capistrano-rails-console'
end

group :development do
Expand All @@ -56,7 +58,11 @@ group :development do
gem 'spring'
end

group :production do
gem 'pg'
end

gem 'rubocop', require: false
gem 'blacklight', '~> 5.16'
gem 'blacklight-spotlight', github: 'sul-dlss/spotlight'
gem 'jettywrapper', '>= 2.0'
Expand Down
25 changes: 25 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ GEM
builder (3.2.2)
byebug (8.2.1)
cancancan (1.13.1)
capistrano (3.4.0)
i18n
rake (>= 10.0.0)
sshkit (~> 1.3)
capistrano-bundler (1.1.4)
capistrano (~> 3.1)
sshkit (~> 1.2)
capistrano-passenger (0.2.0)
capistrano (~> 3.0)
capistrano-rails (1.1.5)
capistrano (~> 3.1)
capistrano-bundler (~> 1.1)
capistrano-rails-console (1.0.0)
capistrano (>= 3.1.0, < 4.0.0)
capybara (2.5.0)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
Expand Down Expand Up @@ -262,6 +276,9 @@ GEM
multi_json (1.11.2)
multi_xml (0.5.5)
multipart-post (2.0.0)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (3.0.2)
netrc (0.11.0)
nokogiri (1.6.7.1)
mini_portile2 (~> 2.0.0.rc2)
Expand All @@ -288,6 +305,7 @@ GEM
request_store (~> 1.1)
parser (2.2.3.0)
ast (>= 1.1, < 3.0)
pg (0.18.4)
poltergeist (1.8.1)
capybara (~> 2.1)
cliver (~> 0.3.1)
Expand Down Expand Up @@ -421,6 +439,9 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.11)
sshkit (1.8.1)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
term-ansicolor (1.3.2)
tins (~> 1.0)
test_xml (0.1.7)
Expand Down Expand Up @@ -473,6 +494,9 @@ DEPENDENCIES
blacklight-oembed
blacklight-spotlight!
byebug
capistrano-passenger
capistrano-rails
capistrano-rails-console
capybara
coffee-rails (~> 4.1.0)
coveralls
Expand All @@ -486,6 +510,7 @@ DEPENDENCIES
jettywrapper (>= 2.0)
jquery-rails
omniauth-cas
pg
poltergeist
pry-rails
rails (= 4.2.5)
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ def guest_username_authentication_key(key)
return key if key
"guest_" + guest_user_unique_suffix
end

def create_guest_user(key = nil)
User.new do |g|
g.username = guest_username_authentication_key(key)
g.email = guest_email_authentication_key(key)
g.guest = true if g.respond_to? :guest
g.skip_confirmation! if g.respond_to?(:skip_confirmation!)
g.save(validate: false)
end
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def to_s
end

def self.from_omniauth(access_token)
User.where(provider: access_token.provider, uid: access_token.uid).first_or_create do |user|
User.where(provider: access_token.provider, uid: access_token.uid, email: "#{access_token.uid}@princeton.edu").first_or_create do |user|
user.uid = access_token.uid
user.provider = access_token.provider
user.username = access_token.uid
Expand Down
6 changes: 4 additions & 2 deletions config/blacklight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ development:
test: &test
adapter: solr
url: <%= "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8983}/solr/blacklight-test" %>
production:
production: &production
adapter: solr
url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:8983/solr/blacklight-core" %>
url: <%= ENV['POMEGRANATE_SOLR_URL'] || "http://127.0.0.1:8983/solr/blacklight-core" %>
staging:
<<: *production
8 changes: 6 additions & 2 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ test:
<<: *default
database: db/test.sqlite3

production:
production: &production
<<: *default
database: db/production.sqlite3
adapter: postgresql
database: <%= ENV["POMEGRANATE_DB"] %>

staging:
<<: *production
47 changes: 47 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# config valid only for current version of Capistrano
lock '3.4.0'

set :application, 'pomegranate'
set :repo_url, 'https://github.com/pulibrary/pomegranate.git'

# Default branch is :master
ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp

# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, '/var/www/my_app_name'
set :deploy_to, '/opt/pomegranate'

# Default value for :scm is :git
# set :scm, :git

# Default value for :format is :pretty
# set :format, :pretty

# Default value for :log_level is :debug
# set :log_level, :debug

# Default value for :pty is false
# set :pty, true

# Default value for :linked_files is []
# set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml', 'config/blacklight.yml', 'config/fedora.yml', 'config/config.yml')

# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'vendor/bundle')

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

# Default value for keep_releases is 5
# set :keep_releases, 5

namespace :deploy do
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
56 changes: 56 additions & 0 deletions config/deploy/staging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# server-based syntax
# ======================
# Defines a single server with a list of roles and multiple properties.
# You can define all roles on a single server, or split them:

# server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
# server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
# server 'db.example.com', user: 'deploy', roles: %w{db}
server 'pom-dev', user: 'deploy', roles: %w(app db web)

# role-based syntax
# ==================

# Defines a role with one or multiple servers. The primary server in each
# group is considered to be the first unless any hosts have the primary
# property set. Specify the username and a domain or IP for the server.
# Don't use `:all`, it's a meta role.

# role :app, %w{deploy@example.com}, my_property: :my_value
# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
# role :db, %w{deploy@example.com}

# Configuration
# =============
# You can set any configuration variable like in config/deploy.rb
# These variables are then only loaded and set in this stage.
# For available Capistrano configuration variables see the documentation page.
# http://capistranorb.com/documentation/getting-started/configuration/
# Feel free to add new variables to customise your setup.

# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
#
# The server-based syntax can be used to override options:
# ------------------------------------
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: 'please use keys'
# }
6 changes: 6 additions & 0 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require_relative 'production'

Rails.application.configure do
config.action_mailer.default_url_options = { host: 'pom-dev.princeton.edu' }
config.action_mailer.delivery_method = :sendmail
end
7 changes: 5 additions & 2 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ test:

# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
production: &production
secret_key_base: <%= ENV["POMEGRANATE_SECRET_KEY_BASE"] %>

staging:
<<: *production
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def change
create_table :spotlight_filters do |t|
t.string :field
t.string :value
t.references :exhibit, index: true, foreign_key: true
t.references :exhibit, index: true

t.timestamps null: false
end
Expand Down

0 comments on commit f8c5d75

Please sign in to comment.