Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add capistrano support #79

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Capfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git

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

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

task :use_rvm do
require 'capistrano/rvm'
end

task local: :use_rvm
task curly: :use_rvm
8 changes: 5 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ gem 'redis', '~> 3.0'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

Expand Down Expand Up @@ -79,6 +76,11 @@ gem 'jquery-rails'
gem 'rsolr', '>= 1.0', '< 3'
gem 'twitter-typeahead-rails', '0.11.1.pre.corejavascript'
group :development, :test do
# Use Capistrano for deployment
gem 'capistrano', '~> 3.10', require: false
gem 'capistrano-bundler', '~> 1.6', require: false
gem 'capistrano-rails', '~> 1.3', require: false
gem 'capistrano-rvm', require: false
gem 'dotenv-rails'
gem 'fcrepo_wrapper'
gem 'rspec_junit_formatter'
Expand Down
29 changes: 27 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ GEM
tzinfo (~> 1.1)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
airbrussh (1.4.0)
sshkit (>= 1.6.1, != 1.7.0)
almond-rails (0.3.0)
rails (>= 4.2)
archive-zip (0.12.0)
Expand Down Expand Up @@ -141,6 +143,19 @@ GEM
builder (3.2.4)
byebug (11.1.3)
cancancan (1.17.0)
capistrano (3.14.1)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
sshkit (>= 1.9.0)
capistrano-bundler (1.6.0)
capistrano (~> 3.1)
capistrano-rails (1.6.1)
capistrano (~> 3.1)
capistrano-bundler (>= 1.1, < 3)
capistrano-rvm (0.1.2)
capistrano (~> 3.0)
sshkit (~> 1.2)
capybara (3.33.0)
addressable
mini_mime (>= 0.1.3)
Expand All @@ -165,7 +180,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.1.6)
concurrent-ruby (1.1.7)
connection_pool (2.2.3)
coveralls (0.8.23)
json (>= 1.8, < 3)
Expand Down Expand Up @@ -397,7 +412,7 @@ GEM
signet
solrizer (>= 3.4, < 5)
tinymce-rails (~> 4.1)
i18n (1.8.3)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
iiif-image-api (0.2.0)
Expand Down Expand Up @@ -526,6 +541,9 @@ GEM
redic
net-http-persistent (3.1.0)
connection_pool (~> 2.2)
net-scp (3.0.0)
net-ssh (>= 2.6.5, < 7.0.0)
net-ssh (6.1.0)
nio4r (2.5.2)
noid (0.9.0)
noid-rails (3.0.2)
Expand Down Expand Up @@ -797,6 +815,9 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
sshkit (1.21.0)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
sxp (1.1.0)
rdf (~> 3.1)
sync (0.5.0)
Expand Down Expand Up @@ -846,6 +867,10 @@ DEPENDENCIES
bootsnap (>= 1.1.0)
bootstrap-sass (~> 3.0)
byebug
capistrano (~> 3.10)
capistrano-bundler (~> 1.6)
capistrano-rails (~> 1.3)
capistrano-rvm
capybara (>= 2.15)
chromedriver-helper
coffee-rails (~> 4.2)
Expand Down
20 changes: 20 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# config valid for current version and patch releases of Capistrano
lock '~> 3.11.0'
set :application, 'UC DRC'
set :repo_url, 'https://github.com/uclibs/uc_drc.git'
set :keep_releases, 2

task :shared_db do
on roles(:all) do
execute "mkdir -p #{fetch(:deploy_to)}/shared/db/ && touch #{fetch(:deploy_to)}/shared/db/development.sqlite3"
execute "cp #{fetch(:deploy_to)}/static/.env.development.local #{fetch(:release_path)}/ || true"
end
end

task :start_curly do
on roles(:all) do
execute "export PATH=$PATH:/usr/sbin/ && cd #{fetch(:deploy_to)}/current/script && chmod u+x * && source start_curly.sh"
end
end
15 changes: 15 additions & 0 deletions config/deploy/curly.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

set :rails_env, :development
set :bundle_without, %w[production test].join(' ')
set :branch, 'sandbox'
set :default_env, path: '$PATH:/usr/sbin/'
append :linked_files, 'db/development.sqlite3'
# Note: Fedora and Solr are external
append :linked_dirs, 'tmp', 'log', 'public/system'
ask(:username, nil)
ask(:password, nil, echo: false)
server 'curly.libraries.uc.edu', user: fetch(:username), password: fetch(:password), port: 22, roles: %i[web app db]
set :deploy_to, '/opt/rails-apps/uc_drc_capistrano'
after 'deploy:updating', 'shared_db'
before 'deploy:cleanup', 'start_curly'
42 changes: 42 additions & 0 deletions script/restart_sidekiq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

# Kill the Sidekiq process (if it exists) and restart it
# script/restart_sidekiq.sh [production|development]

ENVIRONMENT=$1
THREADS=$2
RVM=$3
APP_DIRECTORY="$(dirname "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" )"
if [[ $RVM == "yes" ]]; then
source "$HOME/.rvm/scripts/rvm"
export PATH=$PATH:"$(rvm gemdir)/bin"
fi
function banner {
echo -e "$0 ↠ $1"
}

if [ $# -eq 0 ]; then
echo -e "ERROR: no environment argument [production|development] provided"
exit 1
fi

if [ $ENVIRONMENT != "production" ] && [ $ENVIRONMENT != "development" ]; then
echo -e "ERROR: environment argument must be either [production|development] most likely this will be development for local machines and production otherwise"
exit 1
fi
# Check if threads were set
re='^[0-9]+$'
if ! [[ $THREADS =~ $re ]] ; then
THREADS=8
fi

$APP_DIRECTORY/script/kill_sidekiq.sh

banner "starting Sidekiq"
if [[ -z "${FITS_HOME}" ]]; then
export FITS_HOME=/opt/fits/fits
export PATH=$PATH:/opt/fits/fits
fi
cd $APP_DIRECTORY
bundle exec sidekiq -d -c $THREADS -q ingest -q default -q event -q change -L log/sidekiq.log -C config/sidekiq.yml -e $ENVIRONMENT

14 changes: 14 additions & 0 deletions script/start_curly.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
if [ ! -f "$(dirname "$(dirname "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" )" )/static/.env.development.local" ]; then
echo "Missing updated .env.development.local file in the static directory. The server may not function properly"
else
cp "$(dirname "$(dirname "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" )" )/static/.env.development.local" "$(dirname "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" )"
fi

# Kill rails server if exists
kill -9 $(lsof -i tcp:3002 -t) 2> /dev/null
source "$HOME/.rvm/scripts/rvm" && bundle exec rails server -p 3002 -b 0.0.0.0 -d
source restart_sidekiq.sh development 1
bin/rails hyrax:default_admin_set:create
bundle exec rails hyrax:default_collection_types:create
bin/rails hyrax:workflow:load