From 36fea81d2f0a22eb2ecd398bccb0d646fa84c428 Mon Sep 17 00:00:00 2001 From: Alex Skrenchuk Date: Thu, 20 Jul 2017 15:24:43 -0700 Subject: [PATCH] capistrano v3.8 + appliance deployment update --- Capfile | 3 ++ Gemfile | 4 +- Gemfile.lock | 16 +++++-- ...ase.yml.production => database.yml.sample} | 10 +++- config/deploy.rb | 32 ++++++++----- config/deploy/appliance.rb | 48 +++++++++++++++++++ 6 files changed, 95 insertions(+), 18 deletions(-) rename config/{database.yml.production => database.yml.sample} (87%) create mode 100644 config/deploy/appliance.rb diff --git a/Capfile b/Capfile index 28845322d..dc336aa13 100644 --- a/Capfile +++ b/Capfile @@ -18,9 +18,12 @@ require 'capistrano/deploy' # require 'capistrano/rbenv' # require 'capistrano/chruby' require 'capistrano/bundler' +require "capistrano/scm/git" +install_plugin Capistrano::SCM::Git #require 'capistrano/rails/assets' #require 'capistrano/rails/migrations' require 'capistrano/rails' +require 'capistrano/locally' # Loads custom tasks from `lib/capistrano/tasks' if you have any defined. Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r } diff --git a/Gemfile b/Gemfile index a1eae6d8e..51a8e415d 100644 --- a/Gemfile +++ b/Gemfile @@ -60,7 +60,9 @@ end group :development do #Capistrano - gem 'capistrano', '~> 3.4.1', require: false + gem 'capistrano', '~> 3.8.2', require: false + #capistrano-locally required for deployments to localhost + gem 'capistrano-locally', require: false # rails specific capistrano funcitons gem 'capistrano-rails', '~> 1.1.0', require: false # integrate bundler with capistrano diff --git a/Gemfile.lock b/Gemfile.lock index 0b76f4945..244c0db4a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/ncbo/ontologies_api_ruby_client.git - revision: 3ecd094615b84253cac0d81ccdc757b9d6743637 + revision: f2a5b3ddef23b642ed8430517612c8f9d8ada91a branch: staging specs: ontologies_api_client (0.0.6) @@ -59,6 +59,8 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + airbrussh (1.3.0) + sshkit (>= 1.6.1, != 1.7.0) arel (6.0.4) autoprefixer-rails (7.1.2.3) execjs @@ -66,13 +68,16 @@ GEM autoprefixer-rails (>= 5.2.1) sass (>= 3.3.4) builder (3.2.3) - capistrano (3.4.1) + capistrano (3.8.2) + airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) - sshkit (~> 1.3) + sshkit (>= 1.9.0) capistrano-bundler (1.2.0) capistrano (~> 3.1) sshkit (~> 1.2) + capistrano-locally (0.2.4) + capistrano (~> 3.0) capistrano-passenger (0.2.0) capistrano (~> 3.0) capistrano-rails (1.1.8) @@ -243,8 +248,9 @@ PLATFORMS DEPENDENCIES bootstrap-sass (~> 3.3.7) - capistrano (~> 3.4.1) + capistrano (~> 3.8.2) capistrano-bundler + capistrano-locally capistrano-passenger capistrano-rails (~> 1.1.0) chart-js-rails @@ -283,4 +289,4 @@ DEPENDENCIES will_paginate (~> 3.0) BUNDLED WITH - 1.13.7 + 1.15.1 diff --git a/config/database.yml.production b/config/database.yml.sample similarity index 87% rename from config/database.yml.production rename to config/database.yml.sample index 8f867e876..4ebadd878 100755 --- a/config/database.yml.production +++ b/config/database.yml.sample @@ -39,4 +39,12 @@ production: database: bioportal_ui username: bp_user password: bp_user!!! - host: localhost \ No newline at end of file + host: localhost + +appliance: + adapter: mysql + socket: /var/lib/mysql/mysql.sock + database: bioportal_ui_appliance + username: bp_user + password: bp_user!!! + host: localhost diff --git a/config/deploy.rb b/config/deploy.rb index bf83431c9..9482b0d41 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,11 +1,10 @@ -# config valid only for Capistrano 3.1 -lock '3.4.1' +#lock '3.7.1' set :application, 'bioportal_web_ui' -set :repo_url, "git@github.com:ncbo/#{fetch(:application)}.git" +set :repo_url, "https://github.com/ncbo/#{fetch(:application)}.git" -#set :deploy_via, :remote_cache +set :deploy_via, :remote_cache # Default branch is :master # ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp } @@ -26,7 +25,7 @@ # set :pty, true # Default value for :linked_files is [] -#set :linked_files, %w{config/bioportal_config.rb config/database.yml public/robots.txt config/newrelic.yml} +#set :linked_files, %w{config/bioportal_config.rb config/database.yml public/robots.txt} # Default value for linked_dirs is [] #set :linked_dirs, %w{bin log tmp/pids tmp/cache public/system public/assets config/locales} @@ -49,18 +48,30 @@ namespace :deploy do + desc 'display remote system env vars' + task :show_remote_env do + on roles(:all) do + remote_env = capture("env") + puts remote_env + end + end + desc 'Incorporate the bioportal_conf private repository content' - #Get cofiguration from repo if PRIVATE_CONFIG_REPO is set - #(should be set to NCBO private config repo) + #Get cofiguration from repo if PRIVATE_CONFIG_REPO env var is set + #or get config from local directory if LOCAL_CONFIG_PATH env var is set task :get_config do if defined?(PRIVATE_CONFIG_REPO) - TMP_CONFIG_PATH = "/tmp/#{SecureRandom.hex(15)}" on roles(:web) do + TMP_CONFIG_PATH = "/tmp/#{SecureRandom.hex(15)}" execute "git clone -q #{PRIVATE_CONFIG_REPO} #{TMP_CONFIG_PATH}" execute "rsync -av #{TMP_CONFIG_PATH}/#{fetch(:application)}/ #{release_path}/" execute "rm -rf #{TMP_CONFIG_PATH}" - end - end + end + elsif defined?(LOCAL_CONFIG_PATH) + on roles(:web) do + execute "rsync -av #{LOCAL_CONFIG_PATH}/#{fetch(:application)}/ #{release_path}/" + end + end end desc 'Restart application' @@ -71,7 +82,6 @@ end end - #before :started, :get_config after :updating, :get_config after :publishing, :restart diff --git a/config/deploy/appliance.rb b/config/deploy/appliance.rb new file mode 100644 index 000000000..fe3c97644 --- /dev/null +++ b/config/deploy/appliance.rb @@ -0,0 +1,48 @@ +# Simple Role Syntax +# ================== +# Supports bulk-adding hosts to roles, the primary +# server in each group is considered to be the first +# unless any hosts have the primary property set. +# Don't declare `role :all`, it's a meta role +#role :app, %w{deploy@example.com} +#role :web, %w{deploy@example.com} +#role :db, %w{deploy@example.com} + +# Extended Server Syntax +# ====================== +# This can be used to drop a more detailed server +# definition into the server list. The second argument +# something that quacks like a hash can be used to set +# extended properties on the server. +server 'localhost', roles: %w{web db} + +# you can set custom ssh options +# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options +# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start) +# set it globally +# set :ssh_options, { +# keys: %w(/home/rlisowski/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(password) +# } +# and/or per server +# 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' +# } +# setting per server overrides global ssh_options +# +NCBO_BRANCH = ENV.include?('NCBO_BRANCH') ? ENV['NCBO_BRANCH'] : 'master' +set :branch, "#{NCBO_BRANCH}" + +#private git repo for configuraiton +#PRIVATE_CONFIG_REPO = ENV.include?('PRIVATE_CONFIG_REPO') ? ENV['PRIVATE_CONFIG_REPO'] : 'git@github.com:your_org/private-config-repo.git' + +#location of configuration files +LOCAL_CONFIG_PATH = ENV.include?('LOCAL_CONFIG_PATH') ? ENV['LOCAL_CONFIG_PATH'] : '~/virtual_appliance/appliance_config'