Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Commit

Permalink
Capistrano updates for DLSS practices
Browse files Browse the repository at this point in the history
  • Loading branch information
dazza-codes committed Jun 27, 2017
1 parent 0847a0d commit f515e02
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 102 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
.yardoc
*~
config/certs
config/deploy/*
!config/deploy/localhost.rb
!config/deploy/server_settings.rb
config/environments/*
!config/environments/development.rb
!config/environments/robots_development.yml
Expand Down
38 changes: 14 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ See the [Wiki](https://github.com/sul-dlss/robot-master/wiki) for general docume

```bash
alias sdr2='cd ~/sdr-preservation-core/current/bin'
alias ingest='sdr2 ; ./bundle-exec.sh menu.rb sdrIngestWF; cd $OLDPWD'
alias ingest='sdr2 ; bundle exec menu.rb sdrIngestWF; cd $OLDPWD'
alias ingest-log='log sdrIngestWF'
function log() { cd ~/sdr-preservation-core/current/log/$1/current; }
```
Expand All @@ -64,17 +64,9 @@ See `bin/cron_jobs.txt` or `ssh` onto a deploy system and run `crontab -e`.
cd sdr-preservation-core
bundle install
```
* create or update `config/deploy/github_repo.rb`
```ruby
# This is required when capistrano does a remote git operation with https authentication
# ensure config/deploy/github_repo.rb contains the following content:
set :repo_url, 'https://AuthUser:AuthToken@github.com/sul-dlss/sdr-preservation-core.git'
# AuthUser:AuthToken is replaced with credentials for authorized access to the 'repo' scope, see
# https://help.github.com/articles/creating-an-access-token-for-command-line-use/
```
* create or update `config/deploy/<deploy_server>.rb` to specify the server parameters, e.g.
* create or update `config/deploy/{stage}.rb` to specify the server parameters, e.g.
```bash
cp config/deploy/localhost.rb config/deploy/staging1.rb
cp config/deploy/dev.rb config/deploy/{stage}.rb
```
```ruby
# modify the defaults, e.g.
Expand All @@ -85,28 +77,26 @@ See `bin/cron_jobs.txt` or `ssh` onto a deploy system and run `crontab -e`.
# config/environments/${ROBOT_ENVIRONMENT}.rb
# config/environments/robots_${ROBOT_ENVIRONMENT}.yml
```
```bash
cp config/deploy/staging1.rb config/deploy/staging2.rb
# modify ENV['SDR_HOST']; other settings are likely to be the same.
```
* there is one `config/deploy/<deploy_server>.rb` file for every vm in the deployment system
* capistrano can deploy to multiple servers simultaneously, but that's not desired for this app
* the <deploy_server> file name can be any name, it doesn't have to be the same as a ROBOT_ENVIRONMENT
* capistrano can deploy to multiple servers simultaneously
* the `{stage}` file name can be any name, it doesn't have to be the same as a ROBOT_ENVIRONMENT
* create or update `config/environments/<ROBOT_ENVIRONMENT>.rb`
* see config/environments/development.rb
* create or update `config/environments/robots_<ROBOT_ENVIRONMENT>.yml`
* This defines robot names, queue lanes they are associated with, and the number of instances of the robot
* See the extensive comments in the example file at `config/environments/robots_development.yml`
* check and initialize the deployment directory structure on each <deploy_server>, e.g.
```bash
cap staging1 deploy:check
cap staging2 deploy:check
cap {stage} deploy:check
#cap -T # this should display all the available capistrano tasks (and subtasks)
```
* program puppet to manage the shared_configs for <deploy_server>
* ensure the configs are in https://github.com/sul-dlss/shared_configs/tree/sdr-preservation-core-{stage}
* e.g. https://github.com/sul-dlss/shared_configs/tree/sdr-preservation-core-dev
* e.g. https://github.com/sul-dlss/shared_configs/tree/sdr-preservation-core-stage
* e.g. https://github.com/sul-dlss/shared_configs/tree/sdr-preservation-core-prod
* deploy and restart the robots, e.g.
```bash
cap staging1 deploy
cap staging2 deploy
cap {stage} deploy
# to undo a deploy, use:
#cap <deploy_server> deploy:rollback
```
Expand All @@ -123,7 +113,7 @@ cap <deploy_server> deploy:restart # restarts all the robots
```bash
ssh <deploy_server>
cd ~/sdr-preservation-core/current
export ROBOT_ENVIRONMENT=<environment>
export ROBOT_ENVIRONMENT={environment}
bundle exec controller status # shows the status of the robots
bundle exec controller restart # to restart all of them
bundle exec controller restart sdr_sdrIngestWF_register-sdr # to restart just this robot
Expand All @@ -133,7 +123,7 @@ bundle exec controller restart sdr_sdrIngestWF_register-sdr # to restart just th
```bash
ssh <deploy_server>
cd ~/sdr-preservation-core/current
export ROBOT_ENVIRONMENT=<environment>
export ROBOT_ENVIRONMENT={environment}
bundle exec controller stop
bundle exec controller quit
bundle exec controller boot
Expand Down
29 changes: 18 additions & 11 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@
# Default value for :scm is :git
# set :scm, :git

# ssh access to github is restricted, using https instead (see config/deploy/github_repo.rb)
#set :repo_url, 'git@github.com:sul-dlss/sdr-preservation-core.git'

# Ensure config/deploy/github_repo.rb contains the following content, where
# AuthUser:AuthToken is replaced with credentials for authorized access to the repository.
# The personal access token should have at least the 'repo' scope.
# https://help.github.com/articles/creating-an-access-token-for-command-line-use/
# https://github.com/blog/1509-personal-api-tokens
#set :repo_url, 'https://AuthUser:AuthToken@github.com/sul-dlss/sdr-preservation-core.git'
require_relative 'deploy/github_repo'
set :repo_url, 'https://github.com/sul-dlss/sdr-preservation-core.git'

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

set :deploy_to, '/var/sdr2service/sdr-preservation-core'

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

Expand All @@ -29,12 +22,26 @@
# Default value for :pty is false
# set :pty, true

# https://github.com/capistrano/bundler#usage
# Options, with defaults:
#set :bundle_roles, :all # this is default
#set :bundle_servers, -> { release_roles(fetch(:bundle_roles)) } # this is default
#set :bundle_binstubs, -> { shared_path.join('bin') } # this is default
#set :bundle_gemfile, -> { release_path.join('MyGemfile') } # default: nil
#set :bundle_path, -> { shared_path.join('bundle') } # this is default
#set :bundle_without, %w{development test}.join(' ') # this is default
#set :bundle_flags, '--deployment --quiet' # this is default
#set :bundle_env_variables, {} # this is default
set :bundle_binstubs, -> { shared_path.join('.binstubs') }
set :bundle_without, 'development test'
set :bundle_flags, '--deployment'

# Default value for :linked_files is []
# set :linked_files, %w{config/database.yml}

# Default value for linked_dirs is []
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :linked_dirs, %w(log run config/environments config/certs)
set :linked_dirs, %w(.binstubs log run config/environments config/certs)

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
Expand Down
12 changes: 12 additions & 0 deletions config/deploy/dev.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Note: capistrano reads this file AFTER config/deploy.rb

set :default_env, {
# ROBOT_ENVIRONMENT implies remote :deploy_to contains
# config/environments/#{ROBOT_ENVIRONMENT}.rb
# config/environments/robots_#{ROBOT_ENVIRONMENT}.rb
'ROBOT_ENVIRONMENT' => 'integration'
}

server 'sul-sdr-services-dev.stanford.edu', user: 'sdr2service', roles: %w{app}

Capistrano::OneTimeKey.generate_one_time_key!
15 changes: 9 additions & 6 deletions config/deploy/localhost.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Note: capistrano reads this file AFTER config/deploy.rb

ENV['SDR_APP'] ||= fetch(:application)
ENV['SDR_HOST'] ||= 'localhost'
ENV['SDR_USER'] ||= ENV['USER']
set :default_env, {
# ROBOT_ENVIRONMENT implies remote :deploy_to contains
# config/environments/#{ROBOT_ENVIRONMENT}.rb
# config/environments/robots_#{ROBOT_ENVIRONMENT}.rb
'ROBOT_ENVIRONMENT' => 'development'
}

ENV['ROBOT_ENVIRONMENT'] = 'development'
set :deploy_to, '/tmp/sdr-preservation-core'

puts File.expand_path(__FILE__)
require_relative 'server_settings'
server 'localhost', user: ENV['USER'], roles: %w{app}

Capistrano::OneTimeKey.generate_one_time_key!
14 changes: 14 additions & 0 deletions config/deploy/prod.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Note: capistrano reads this file AFTER config/deploy.rb

set :log_level, :info

set :default_env, {
# ROBOT_ENVIRONMENT implies remote :deploy_to contains
# config/environments/#{ROBOT_ENVIRONMENT}.rb
# config/environments/robots_#{ROBOT_ENVIRONMENT}.rb
'ROBOT_ENVIRONMENT' => 'production'
}

server 'sul-sdr-services.stanford.edu', user: 'sdr2service', roles: %w{app}

Capistrano::OneTimeKey.generate_one_time_key!
58 changes: 0 additions & 58 deletions config/deploy/server_settings.rb

This file was deleted.

13 changes: 13 additions & 0 deletions config/deploy/stage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Note: capistrano reads this file AFTER config/deploy.rb

set :default_env, {
# ROBOT_ENVIRONMENT implies remote :deploy_to contains
# config/environments/#{ROBOT_ENVIRONMENT}.rb
# config/environments/robots_#{ROBOT_ENVIRONMENT}.rb
'ROBOT_ENVIRONMENT' => 'test'
}

server 'sdr-services-test.stanford.edu', user: 'sdr2service', roles: %w{app}
server 'sdr-services-test2.stanford.edu', user: 'sdr2service', roles: %w{app}

Capistrano::OneTimeKey.generate_one_time_key!

0 comments on commit f515e02

Please sign in to comment.