Commit b457a38f authored by pierre.tremouilhac's avatar pierre.tremouilhac
Browse files

Merge branch '252-add-slackistrano' into 'development'

Resolve "add slackistrano"

Closes #252

See merge request !449
parents e2fa25a5 06184942
......@@ -3,7 +3,8 @@ require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
require 'capistrano/rvm' # Ruby version manager
require 'capistrano/nvm' # Node version manager
require 'capistrano/npm' # Node package manager
......@@ -12,6 +13,7 @@ require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
#require 'capistrano/delayed_job'
require 'whenever/capistrano'
require 'slackistrano/capistrano'
require_relative 'lib/slackistrano_custom_messaging'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
......@@ -161,13 +161,14 @@ group :development, :test do
# Remove all assets requests
gem 'quiet_assets'
gem 'capistrano', '3.4.1'
gem 'capistrano', '3.9.1'
gem 'capistrano-bundler'
gem 'capistrano-npm'
gem 'capistrano-nvm', require: false
gem 'capistrano-rails'
gem 'capistrano-rvm'
# gem 'capistrano3-delayed-job'
gem 'slackistrano'
end
group :test do
......
......@@ -101,6 +101,8 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
airbrussh (1.3.0)
sshkit (>= 1.6.1, != 1.7.0)
ancestry (2.1.0)
activerecord (>= 3.0.0)
archive-zip (0.7.0)
......@@ -140,10 +142,11 @@ GEM
uniform_notifier (~> 1.10.0)
byebug (8.2.5)
callsite (0.0.11)
capistrano (3.4.1)
capistrano (3.9.1)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
sshkit (~> 1.3)
sshkit (>= 1.9.0)
capistrano-bundler (1.1.4)
capistrano (~> 3.1)
sshkit (~> 1.2)
......@@ -292,7 +295,7 @@ GEM
httparty (0.13.7)
json (~> 1.8)
multi_xml (>= 0.5.2)
i18n (0.7.0)
i18n (0.8.6)
i18n_data (0.7.0)
ice_nine (0.11.2)
io-like (0.3.0)
......@@ -354,7 +357,7 @@ GEM
net-ssh (>= 2.6.5)
net-sftp (2.1.2)
net-ssh (>= 2.6.5)
net-ssh (3.1.1)
net-ssh (4.2.0)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
open4 (1.3.4)
......@@ -423,7 +426,7 @@ GEM
thor (>= 0.18.1, < 2.0)
rainbow (2.2.2)
rake
rake (12.0.0)
rake (12.1.0)
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
......@@ -498,6 +501,8 @@ GEM
skinny (0.2.4)
eventmachine (~> 1.0.0)
thin (>= 1.5, < 1.7)
slackistrano (3.8.1)
capistrano (>= 3.8.1)
spring (1.7.1)
sprite-factory (1.7.1)
sprockets (3.7.1)
......@@ -508,7 +513,7 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.11)
sshkit (1.10.0)
sshkit (1.14.0)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
stackprof (0.2.10)
......@@ -578,7 +583,7 @@ DEPENDENCIES
browserify-rails (~> 3.0.1)
bullet
byebug
capistrano (= 3.4.1)
capistrano (= 3.9.1)
capistrano-bundler
capistrano-npm
capistrano-nvm
......@@ -644,6 +649,7 @@ DEPENDENCIES
sass-rails (~> 5.0, >= 5.0.6)
sdoc (~> 0.4.0)
selenium-webdriver (~> 3.0.5)
slackistrano
spring
stackprof
swot
......@@ -657,4 +663,4 @@ DEPENDENCIES
yaml_db
BUNDLED WITH
1.15.3
1.15.4
lock '3.4.1'
lock '3.9.1'
set :application, 'chemotion'
set :repo_url, 'git@github.com:ComPlat/chemotion_ELN.git'
......@@ -23,6 +23,8 @@ set :nvm_map_bins, fetch(:nvm_map_bins, []).push('rake')
# Default value for :log_level is :debug
# set :log_level, :debug
set :format_options, command_output: true
set :log_file, 'log/capistrano.log'
# Default value for :pty is false
# set :pty, true
......@@ -48,6 +50,8 @@ set :linked_dirs, fetch(:linked_dirs, []).push(
set :rvm_ruby_version, (`cat .ruby-version`).strip
set :slackistrano, false
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
......
......@@ -91,9 +91,4 @@ Rails.application.configure do
}
config.browserify_rails.commandline_options = "-t [ babelify --presets [ es2015 react ] --plugins [ transform-object-rest-spread ] ] -g uglifyify -p bundle-collapser/plugin "
unless defined?(Rails::Console)
config.after_initialize do
AppRestartMailJob.set(wait: 1.minute).perform_later if Delayed::Job.where("handler like ?", "%AppRestartMailJob%").empty?
end
end
end
# modified from https://github.com/phallstrom/slackistrano#customizing-the-messaging
if defined?(Slackistrano::Messaging)
module Slackistrano
class SlackistranoCustomMessaging < Messaging::Base
# Send failed message to #ops. Send all other messages to default channels.
# The #ops channel must exist prior.
# def channels_for(action)
# if action == :failed
# "#ops"
# else
# super
# end
# end
# def payload_for_updating
# nil
# end
def payload_for_updating
{
text: "#{member_links}: On server #{server_hostnames} " + super[:text]
}
end
# Fancy updated message.
# See https://api.slack.com/docs/message-attachments
def payload_for_updated
{
text: "#{member_links}",
attachments: [{
color: 'good',
title: ':tada: Application Deployed :tada:',
fields: [{
title: 'Environment',
value: stage,
short: true
}, {
title: 'server',
value: server_hostnames,
short: true
}, {
title: 'Branch',
value: branch,
short: true
}, {
title: 'Deployer',
value: deployer,
short: true
}, {
title: 'Time',
value: elapsed_time,
short: true
}],
fallback: super[:text]
}]
}
end
# Default reverted message. Alternatively simply do not redefine this
# method.
# def payload_for_reverted
# super
# end
# Slightly tweaked failed message.
# See https://api.slack.com/docs/message-formatting
def payload_for_failed
payload = super
payload[:text] = ":shit: on server #{server_hostnames} #{payload[:text]} "
payload
end
# Override the deployer helper to pull the best name available (git, password file, env vars).
# See https://github.com/phallstrom/slackistrano/blob/master/lib/slackistrano/messaging/helpers.rb
# def deployer
# name = `git config user.name`.strip
# name = nil if name.empty?
# name ||= Etc.getpwnam(ENV['USER']).gecos || ENV['USER'] || ENV['USERNAME']
# name
# end
def server_hostnames
roles(:web).map do |host|
"#{host.user}@#{host.hostname}"
end.join(', ')
end
def member_links
fetch(:slack_members, nil)&.inject do |ms,m|
ms << "<@#{m}>"
end
end
end
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment