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

capistrano configs and shared-configs #58

Merged
merged 4 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
.bundle
.capistrano/*
.DS_Store
.env
.idea
.rspec-local
.ruby-gemset
Expand All @@ -12,9 +11,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
4 changes: 4 additions & 0 deletions Capfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'

# Use git
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git

# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
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
16 changes: 0 additions & 16 deletions bin/sync_configs.sh

This file was deleted.

13 changes: 3 additions & 10 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 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!