capistrano-ops 0.2.14 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +121 -29
- data/lib/capistrano/ops/backup/helper.rb +56 -0
- data/lib/capistrano/ops/{capistrano/v3/tasks/backup → backup/tasks}/database/create.rake +1 -2
- data/lib/capistrano/ops/{capistrano/v3/tasks/backup → backup/tasks}/database/pull.rake +1 -2
- data/lib/capistrano/ops/{capistrano/v3/tasks/backup → backup/tasks}/storage/create.rake +1 -2
- data/lib/capistrano/ops/{capistrano/v3/tasks/backup → backup/tasks}/storage/pull.rake +1 -2
- data/lib/capistrano/ops/backup.rb +14 -4
- data/lib/capistrano/ops/capistrano.rb +8 -13
- data/lib/capistrano/ops/figaro_yml/helpers.rb +184 -0
- data/lib/capistrano/ops/figaro_yml/paths.rb +19 -0
- data/lib/capistrano/ops/figaro_yml/tasks/backup.rake +26 -0
- data/lib/capistrano/ops/figaro_yml/tasks/check.rake +12 -0
- data/lib/capistrano/ops/figaro_yml/tasks/check_config_present.rake +12 -0
- data/lib/capistrano/ops/figaro_yml/tasks/check_figaro_file_exists.rake +12 -0
- data/lib/capistrano/ops/figaro_yml/tasks/check_git_tracking.rake +12 -0
- data/lib/capistrano/ops/{capistrano/v3/tasks/figaro_yml → figaro_yml/tasks}/compare.rake +10 -19
- data/lib/capistrano/ops/figaro_yml/tasks/create_local.rake +27 -0
- data/lib/capistrano/ops/figaro_yml/tasks/figaro_yml_symlink.rake +10 -0
- data/lib/capistrano/ops/figaro_yml/tasks/get.rake +45 -0
- data/lib/capistrano/ops/figaro_yml/tasks/get_stage.rake +15 -0
- data/lib/capistrano/ops/figaro_yml/tasks/load.rake +10 -0
- data/lib/capistrano/ops/figaro_yml/tasks/rollback.rake +22 -0
- data/lib/capistrano/ops/figaro_yml/tasks/setup.rake +16 -0
- data/lib/capistrano/ops/{capistrano/v3/tasks/figaro_yml → figaro_yml/tasks}/sort_local.rake +2 -4
- data/lib/capistrano/ops/figaro_yml.rb +29 -0
- data/lib/capistrano/ops/helper.rb +14 -0
- data/lib/capistrano/ops/invoke/tasks/invoke.rake +25 -0
- data/lib/capistrano/ops/invoke.rb +3 -0
- data/lib/capistrano/ops/logrotate/helpers.rb +50 -0
- data/lib/capistrano/ops/logrotate/paths.rb +47 -0
- data/lib/capistrano/ops/{capistrano/v3/tasks/logrotate → logrotate/tasks}/check.rake +3 -5
- data/lib/capistrano/ops/{capistrano/v3/tasks/logrotate → logrotate/tasks}/disable.rake +2 -5
- data/lib/capistrano/ops/logrotate/tasks/enable.rake +28 -0
- data/lib/capistrano/ops/logrotate/tasks/load.rake +10 -0
- data/lib/capistrano/ops/logrotate.rb +19 -0
- data/lib/capistrano/ops/logs/helpers.rb +16 -0
- data/lib/capistrano/ops/logs/paths.rb +23 -0
- data/lib/capistrano/ops/logs/tasks/load.rake +9 -0
- data/lib/capistrano/ops/logs/tasks/rails.rake +18 -0
- data/lib/capistrano/ops/logs/tasks/sidekiq.rake +42 -0
- data/lib/capistrano/ops/logs.rb +18 -0
- data/lib/capistrano/ops/{backup → rails/lib/backup}/s3.rb +1 -1
- data/lib/capistrano/ops/rails/lib/backup.rb +6 -0
- data/lib/capistrano/ops/rails/lib/notification.rb +9 -0
- data/lib/capistrano/ops/rails/lib/railtie.rb +17 -0
- data/lib/capistrano/ops/{tasks → rails/lib/tasks}/pg/postgres_helper.rb +1 -1
- data/lib/capistrano/ops/version.rb +1 -1
- data/lib/capistrano/ops/{capistrano/v3/tasks/whenever.rake → whenever/tasks/show_crontab.rake} +1 -3
- data/lib/capistrano/ops/whenever.rb +17 -0
- data/lib/capistrano/ops/wkhtmltopdf/helpers.rb +50 -0
- data/lib/capistrano/ops/wkhtmltopdf/tasks/setup.rake +17 -0
- data/lib/capistrano/ops/wkhtmltopdf.rb +17 -1
- data/lib/capistrano/ops.rb +4 -3
- metadata +60 -36
- data/lib/capistrano/ops/capistrano/tasks/wkhtmltopdf.rake +0 -48
- data/lib/capistrano/ops/capistrano/v3/tasks/backup/backup_helper.rb +0 -50
- data/lib/capistrano/ops/capistrano/v3/tasks/figaro_yml/figaro_yaml_helper.rb +0 -74
- data/lib/capistrano/ops/capistrano/v3/tasks/figaro_yml/get.rake +0 -68
- data/lib/capistrano/ops/capistrano/v3/tasks/figaro_yml/get_stage.rake +0 -13
- data/lib/capistrano/ops/capistrano/v3/tasks/figaro_yml.rb +0 -3
- data/lib/capistrano/ops/capistrano/v3/tasks/invoke.rake +0 -23
- data/lib/capistrano/ops/capistrano/v3/tasks/logrotate/enable.rake +0 -24
- data/lib/capistrano/ops/capistrano/v3/tasks/logrotate/logrotate_helper.rb +0 -68
- data/lib/capistrano/ops/capistrano/v3/tasks/logs/rails.rake +0 -16
- data/lib/capistrano/ops/notification.rb +0 -9
- data/lib/capistrano/ops/railtie.rb +0 -15
- /data/lib/capistrano/ops/{capistrano/v3/tasks/logrotate → logrotate/tasks}/templates/logrotate.conf.erb +0 -0
- /data/lib/capistrano/ops/{capistrano/v3/tasks/logrotate → logrotate/tasks}/templates/schedule.rb.erb +0 -0
- /data/lib/capistrano/ops/{backup → rails/lib/backup}/api.rb +0 -0
- /data/lib/capistrano/ops/{backup → rails/lib/backup}/s3_helper.rb +0 -0
- /data/lib/capistrano/ops/{notification → rails/lib/notification}/api.rb +0 -0
- /data/lib/capistrano/ops/{notification → rails/lib/notification}/slack.rb +0 -0
- /data/lib/capistrano/ops/{notification → rails/lib/notification}/webhook.rb +0 -0
- /data/lib/capistrano/ops/{tasks → rails/lib/tasks}/pg/dump.rake +0 -0
- /data/lib/capistrano/ops/{tasks → rails/lib/tasks}/pg/remove_old_dumps.rake +0 -0
- /data/lib/capistrano/ops/{tasks → rails/lib/tasks}/storage/backup.rake +0 -0
- /data/lib/capistrano/ops/{tasks → rails/lib/tasks}/storage/remove_old_backups.rake +0 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :logs do
|
4
|
+
include Capistrano::Ops::Logs::Paths
|
5
|
+
include Capistrano::Ops::Logs::Helpers
|
6
|
+
|
7
|
+
desc 'Tail Rails info logs'
|
8
|
+
task 'sidekiq:info' do
|
9
|
+
on roles(fetch(:rake_roles, :app)) do
|
10
|
+
trap_interrupt
|
11
|
+
|
12
|
+
execute "tail -f #{sidekiq_log_file_path}" do |_channel, stream, data|
|
13
|
+
puts data
|
14
|
+
break if stream == :err
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Tail Sidekiq error logs'
|
20
|
+
task 'sidekiq:errors' do
|
21
|
+
on roles(fetch(:rake_roles, :app)) do
|
22
|
+
trap_interrupt
|
23
|
+
|
24
|
+
execute "tail -f #{sidekiq_error_log_file_path}" do |_channel, stream, data|
|
25
|
+
puts data
|
26
|
+
break if stream == :err
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Tail all Sidekiq logs'
|
32
|
+
task :sidekiq do
|
33
|
+
on roles(fetch(:rake_roles, :app)) do
|
34
|
+
trap_interrupt
|
35
|
+
|
36
|
+
execute "tail -f #{sidekiq_log_file_path} & tail -f #{sidekiq_error_log_file_path}" do |_channel, stream, data|
|
37
|
+
puts data
|
38
|
+
break if stream == :err
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'capistrano/ops/helper'
|
4
|
+
require 'capistrano/ops/logs/paths'
|
5
|
+
require 'capistrano/ops/logs/helpers'
|
6
|
+
|
7
|
+
module TaskLoader
|
8
|
+
extend Capistrano::Ops::Helper
|
9
|
+
def self.load_tasks_if_gem_present(gem_name, task_path, warning_message)
|
10
|
+
if gem_in_gemfile?(gem_name)
|
11
|
+
Dir.glob("#{File.expand_path(__dir__)}/#{task_path}/**/*.rake").each { |f| load f }
|
12
|
+
else
|
13
|
+
puts warning_message
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
TaskLoader.load_tasks_if_gem_present('rails', 'logs/tasks', 'WARNING: Gemfile does not include rails gem which is required for logs tasks')
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'capistrano/ops/rails/lib/notification/api'
|
4
|
+
require 'capistrano/ops/rails/lib/notification/slack'
|
5
|
+
require 'capistrano/ops/rails/lib/notification/webhook'
|
6
|
+
|
7
|
+
module Notification
|
8
|
+
class Error < StandardError; end
|
9
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails'
|
4
|
+
# require 'capistrano/ops'
|
5
|
+
module Capistrano
|
6
|
+
module Ops
|
7
|
+
module Libs
|
8
|
+
class Railtie < ::Rails::Railtie
|
9
|
+
railtie_name :ops
|
10
|
+
rake_tasks do
|
11
|
+
path = File.expand_path(__dir__)
|
12
|
+
Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -54,7 +54,7 @@ module PostgresHelper
|
|
54
54
|
commandlist = []
|
55
55
|
commandlist << "export PGPASSWORD='#{@password}'"
|
56
56
|
commandlist << "cd #{@backup_path}"
|
57
|
-
commandlist << "pg_dump -
|
57
|
+
commandlist << "pg_dump --no-acl --no-owner #{options.join('')} > #{@filename}"
|
58
58
|
commandlist.join(' && ')
|
59
59
|
end
|
60
60
|
|
data/lib/capistrano/ops/{capistrano/v3/tasks/whenever.rake → whenever/tasks/show_crontab.rake}
RENAMED
@@ -1,11 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
namespace :whenever do
|
4
|
-
# Default to :app role
|
5
|
-
rake_roles = fetch(:rake_roles, :app)
|
6
4
|
desc 'show crontab'
|
7
5
|
task :show_crontab do
|
8
|
-
on roles(rake_roles) do
|
6
|
+
on roles(fetch(:rake_roles, :app)) do
|
9
7
|
puts capture 'crontab -l'
|
10
8
|
end
|
11
9
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'capistrano/ops/helper'
|
4
|
+
|
5
|
+
module TaskLoader
|
6
|
+
extend Capistrano::Ops::Helper
|
7
|
+
|
8
|
+
def self.load_tasks_if_gem_present(gem_name, task_path, warning_message)
|
9
|
+
if gem_in_gemfile?(gem_name)
|
10
|
+
Dir.glob("#{File.expand_path(__dir__)}/#{task_path}/**/*.rake").each { |f| load f }
|
11
|
+
else
|
12
|
+
puts warning_message
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
TaskLoader.load_tasks_if_gem_present('whenever', 'whenever/tasks', 'WARNING: Gemfile does not include whenever gem which is required for logrotate tasks')
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Ops
|
5
|
+
module Helper
|
6
|
+
def binary_path
|
7
|
+
gem_path = capture(:bundle, 'show', 'wkhtmltopdf-binary').strip
|
8
|
+
"#{gem_path}/bin"
|
9
|
+
end
|
10
|
+
|
11
|
+
def gem_version
|
12
|
+
capture(:cat, 'config/initializers/wicked_pdf.rb').scan(/wkhtmltopdf_ubuntu_(\d+\.\d+)_amd64/).flatten.first
|
13
|
+
end
|
14
|
+
|
15
|
+
def binary_path_and_version
|
16
|
+
[binary_path, gem_version]
|
17
|
+
end
|
18
|
+
|
19
|
+
def file_existing?(file)
|
20
|
+
test("[ -f #{file} ]")
|
21
|
+
end
|
22
|
+
|
23
|
+
def right_permissions?(file)
|
24
|
+
test("[ $(stat -c '%a' #{file}) = '777' ]")
|
25
|
+
end
|
26
|
+
|
27
|
+
def check_file_and_permissions(binary_path, version)
|
28
|
+
binary_file = "#{binary_path}/wkhtmltopdf_ubuntu_#{version}_amd64"
|
29
|
+
|
30
|
+
if file_existing?(binary_file)
|
31
|
+
info('wkhtmltopdf binary already extracted')
|
32
|
+
|
33
|
+
if right_permissions?(binary_file)
|
34
|
+
info('wkhtmltopdf binary has already the right permissions')
|
35
|
+
else
|
36
|
+
info('adding right permissions to wkhtmltopdf binary')
|
37
|
+
execute("chmod 777 #{binary_file}")
|
38
|
+
end
|
39
|
+
else
|
40
|
+
info('extracting wkhtmltopdf binary')
|
41
|
+
# extract the binary but keep the gzip file
|
42
|
+
execute("cd #{binary_path} && gzip -dk wkhtmltopdf_ubuntu_#{version}_amd64.gz")
|
43
|
+
# add execute permission to the binary
|
44
|
+
execute("chmod 777 #{binary_file}")
|
45
|
+
end
|
46
|
+
info('wkhtmltopdf setup finished')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :wkhtmltopdf do
|
4
|
+
include Capistrano::Ops::Wkhtmltopdf::Helpers
|
5
|
+
after 'deploy:symlink:release', 'wkhtmltopdf:setup'
|
6
|
+
|
7
|
+
desc 'unzip wkhtmltopdf if necessary'
|
8
|
+
task :setup do
|
9
|
+
on roles(:app) do
|
10
|
+
within release_path do
|
11
|
+
binary_path, version = binary_path_and_version
|
12
|
+
info("setup wkhtmltopdf version #{version}")
|
13
|
+
check_file_and_permissions(binary_path, version)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,3 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'capistrano/ops/helper'
|
4
|
+
require 'capistrano/ops/wkhtmltopdf/helpers'
|
5
|
+
|
6
|
+
module TaskLoader
|
7
|
+
extend Capistrano::Ops::Helper
|
8
|
+
|
9
|
+
def self.load_tasks_if_gem_present(gem_name, task_path, warning_message)
|
10
|
+
if gem_in_gemfile?(gem_name)
|
11
|
+
Dir.glob("#{File.expand_path(__dir__)}/#{task_path}/**/*.rake").each { |f| load f }
|
12
|
+
else
|
13
|
+
puts warning_message
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
TaskLoader.load_tasks_if_gem_present('wicked-pdf', 'wkhtmltopdf/tasks',
|
19
|
+
'WARNING: Gemfile does not include wkhtmltopdf-binary gem which is required for wkhtmltopdf tasks')
|
data/lib/capistrano/ops.rb
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
module Capistrano
|
4
4
|
module Ops
|
5
|
-
require 'capistrano/ops/backup'
|
6
|
-
require 'capistrano/ops/notification'
|
7
|
-
require 'capistrano/ops/railtie' if defined?(Rails)
|
5
|
+
require 'capistrano/ops/rails/lib/backup'
|
6
|
+
require 'capistrano/ops/rails/lib/notification'
|
7
|
+
require 'capistrano/ops/rails/lib/railtie' if defined?(Rails)
|
8
8
|
require 'capistrano/ops/capistrano' if defined?(Capistrano::VERSION)
|
9
|
+
|
9
10
|
def self.path
|
10
11
|
Dir.pwd
|
11
12
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-ops
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Crusius
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-s3
|
@@ -144,44 +144,68 @@ files:
|
|
144
144
|
- capistrano-ops.gemspec
|
145
145
|
- lib/capistrano/ops.rb
|
146
146
|
- lib/capistrano/ops/backup.rb
|
147
|
-
- lib/capistrano/ops/backup/
|
148
|
-
- lib/capistrano/ops/backup/
|
149
|
-
- lib/capistrano/ops/backup/
|
147
|
+
- lib/capistrano/ops/backup/helper.rb
|
148
|
+
- lib/capistrano/ops/backup/tasks/database/create.rake
|
149
|
+
- lib/capistrano/ops/backup/tasks/database/pull.rake
|
150
|
+
- lib/capistrano/ops/backup/tasks/storage/create.rake
|
151
|
+
- lib/capistrano/ops/backup/tasks/storage/pull.rake
|
150
152
|
- lib/capistrano/ops/capistrano.rb
|
151
|
-
- lib/capistrano/ops/capistrano/tasks/wkhtmltopdf.rake
|
152
153
|
- lib/capistrano/ops/capistrano/v3/tasks/backup.rake
|
153
|
-
- lib/capistrano/ops/
|
154
|
-
- lib/capistrano/ops/
|
155
|
-
- lib/capistrano/ops/
|
156
|
-
- lib/capistrano/ops/
|
157
|
-
- lib/capistrano/ops/
|
158
|
-
- lib/capistrano/ops/
|
159
|
-
- lib/capistrano/ops/
|
160
|
-
- lib/capistrano/ops/
|
161
|
-
- lib/capistrano/ops/
|
162
|
-
- lib/capistrano/ops/
|
163
|
-
- lib/capistrano/ops/
|
164
|
-
- lib/capistrano/ops/
|
165
|
-
- lib/capistrano/ops/
|
166
|
-
- lib/capistrano/ops/
|
167
|
-
- lib/capistrano/ops/
|
168
|
-
- lib/capistrano/ops/
|
169
|
-
- lib/capistrano/ops/
|
170
|
-
- lib/capistrano/ops/
|
171
|
-
- lib/capistrano/ops/
|
172
|
-
- lib/capistrano/ops/
|
173
|
-
- lib/capistrano/ops/
|
174
|
-
- lib/capistrano/ops/
|
175
|
-
- lib/capistrano/ops/
|
176
|
-
- lib/capistrano/ops/
|
177
|
-
- lib/capistrano/ops/
|
178
|
-
- lib/capistrano/ops/tasks/
|
179
|
-
- lib/capistrano/ops/tasks/
|
180
|
-
- lib/capistrano/ops/tasks/
|
181
|
-
- lib/capistrano/ops/tasks/
|
182
|
-
- lib/capistrano/ops/
|
154
|
+
- lib/capistrano/ops/figaro_yml.rb
|
155
|
+
- lib/capistrano/ops/figaro_yml/helpers.rb
|
156
|
+
- lib/capistrano/ops/figaro_yml/paths.rb
|
157
|
+
- lib/capistrano/ops/figaro_yml/tasks/backup.rake
|
158
|
+
- lib/capistrano/ops/figaro_yml/tasks/check.rake
|
159
|
+
- lib/capistrano/ops/figaro_yml/tasks/check_config_present.rake
|
160
|
+
- lib/capistrano/ops/figaro_yml/tasks/check_figaro_file_exists.rake
|
161
|
+
- lib/capistrano/ops/figaro_yml/tasks/check_git_tracking.rake
|
162
|
+
- lib/capistrano/ops/figaro_yml/tasks/compare.rake
|
163
|
+
- lib/capistrano/ops/figaro_yml/tasks/create_local.rake
|
164
|
+
- lib/capistrano/ops/figaro_yml/tasks/figaro_yml_symlink.rake
|
165
|
+
- lib/capistrano/ops/figaro_yml/tasks/get.rake
|
166
|
+
- lib/capistrano/ops/figaro_yml/tasks/get_stage.rake
|
167
|
+
- lib/capistrano/ops/figaro_yml/tasks/load.rake
|
168
|
+
- lib/capistrano/ops/figaro_yml/tasks/rollback.rake
|
169
|
+
- lib/capistrano/ops/figaro_yml/tasks/setup.rake
|
170
|
+
- lib/capistrano/ops/figaro_yml/tasks/sort_local.rake
|
171
|
+
- lib/capistrano/ops/helper.rb
|
172
|
+
- lib/capistrano/ops/invoke.rb
|
173
|
+
- lib/capistrano/ops/invoke/tasks/invoke.rake
|
174
|
+
- lib/capistrano/ops/logrotate.rb
|
175
|
+
- lib/capistrano/ops/logrotate/helpers.rb
|
176
|
+
- lib/capistrano/ops/logrotate/paths.rb
|
177
|
+
- lib/capistrano/ops/logrotate/tasks/check.rake
|
178
|
+
- lib/capistrano/ops/logrotate/tasks/disable.rake
|
179
|
+
- lib/capistrano/ops/logrotate/tasks/enable.rake
|
180
|
+
- lib/capistrano/ops/logrotate/tasks/load.rake
|
181
|
+
- lib/capistrano/ops/logrotate/tasks/templates/logrotate.conf.erb
|
182
|
+
- lib/capistrano/ops/logrotate/tasks/templates/schedule.rb.erb
|
183
|
+
- lib/capistrano/ops/logs.rb
|
184
|
+
- lib/capistrano/ops/logs/helpers.rb
|
185
|
+
- lib/capistrano/ops/logs/paths.rb
|
186
|
+
- lib/capistrano/ops/logs/tasks/load.rake
|
187
|
+
- lib/capistrano/ops/logs/tasks/rails.rake
|
188
|
+
- lib/capistrano/ops/logs/tasks/sidekiq.rake
|
189
|
+
- lib/capistrano/ops/rails/lib/backup.rb
|
190
|
+
- lib/capistrano/ops/rails/lib/backup/api.rb
|
191
|
+
- lib/capistrano/ops/rails/lib/backup/s3.rb
|
192
|
+
- lib/capistrano/ops/rails/lib/backup/s3_helper.rb
|
193
|
+
- lib/capistrano/ops/rails/lib/notification.rb
|
194
|
+
- lib/capistrano/ops/rails/lib/notification/api.rb
|
195
|
+
- lib/capistrano/ops/rails/lib/notification/slack.rb
|
196
|
+
- lib/capistrano/ops/rails/lib/notification/webhook.rb
|
197
|
+
- lib/capistrano/ops/rails/lib/railtie.rb
|
198
|
+
- lib/capistrano/ops/rails/lib/tasks/pg/dump.rake
|
199
|
+
- lib/capistrano/ops/rails/lib/tasks/pg/postgres_helper.rb
|
200
|
+
- lib/capistrano/ops/rails/lib/tasks/pg/remove_old_dumps.rake
|
201
|
+
- lib/capistrano/ops/rails/lib/tasks/storage/backup.rake
|
202
|
+
- lib/capistrano/ops/rails/lib/tasks/storage/remove_old_backups.rake
|
183
203
|
- lib/capistrano/ops/version.rb
|
204
|
+
- lib/capistrano/ops/whenever.rb
|
205
|
+
- lib/capistrano/ops/whenever/tasks/show_crontab.rake
|
184
206
|
- lib/capistrano/ops/wkhtmltopdf.rb
|
207
|
+
- lib/capistrano/ops/wkhtmltopdf/helpers.rb
|
208
|
+
- lib/capistrano/ops/wkhtmltopdf/tasks/setup.rake
|
185
209
|
homepage: https://github.com/zauberware/capistrano-ops
|
186
210
|
licenses:
|
187
211
|
- MIT
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
namespace :wkhtmltopdf do
|
4
|
-
after 'deploy:symlink:release', 'wkhtmltopdf:setup'
|
5
|
-
|
6
|
-
desc 'unzip wkhtmltopdf if necessary'
|
7
|
-
task :setup do
|
8
|
-
on roles(:app) do
|
9
|
-
within release_path do
|
10
|
-
binary_path, version = binary_path_and_version
|
11
|
-
info("setup wkhtmltopdf version #{version}")
|
12
|
-
check_file_and_permissions(binary_path, version)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
def binary_path_and_version
|
18
|
-
# get the binary path of wkhtmltopdf-binary
|
19
|
-
gem_path = capture(:bundle, 'show', 'wkhtmltopdf-binary').strip
|
20
|
-
binary_path = "#{gem_path}/bin"
|
21
|
-
|
22
|
-
# get the use wkhtmltopdf_ubuntu version from the wicked_pdf initializer
|
23
|
-
version = capture(:cat, 'config/initializers/wicked_pdf.rb').scan(/wkhtmltopdf_ubuntu_(\d+\.\d+)_amd64/).flatten.first
|
24
|
-
|
25
|
-
[binary_path, version]
|
26
|
-
end
|
27
|
-
|
28
|
-
def check_file_and_permissions(binary_path, version)
|
29
|
-
binary_file = "#{binary_path}/wkhtmltopdf_ubuntu_#{version}_amd64"
|
30
|
-
|
31
|
-
if test("[ -f #{binary_file} ]")
|
32
|
-
info('wkhtmltopdf binary already extracted')
|
33
|
-
|
34
|
-
if test("[ $(stat -c '%a' #{binary_file}) = '777' ]")
|
35
|
-
info('wkhtmltopdf binary has already the right permissions')
|
36
|
-
else
|
37
|
-
info('adding right permissions to wkhtmltopdf binary')
|
38
|
-
execute("chmod 777 #{binary_file}")
|
39
|
-
end
|
40
|
-
else
|
41
|
-
info('extracting wkhtmltopdf binary')
|
42
|
-
# extract the binary but keep the gzip file
|
43
|
-
execute("cd #{binary_path} && gzip -dk wkhtmltopdf_ubuntu_#{version}_amd64.gz")
|
44
|
-
# add execute permission to the binary
|
45
|
-
execute("chmod 777 #{binary_file}")
|
46
|
-
end
|
47
|
-
info('wkhtmltopdf setup finished')
|
48
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module BackupHelper
|
4
|
-
def backup_file_name(type)
|
5
|
-
regex = type == 'storage' ? "'.{0,}\.tar.gz'" : "'.{0,}\.dump'"
|
6
|
-
@backup_file_name ||= capture "cd #{shared_path}/backups && ls -lt | grep -E -i #{regex} | head -n 1 | awk '{print $9}'"
|
7
|
-
end
|
8
|
-
|
9
|
-
def backup_file_size
|
10
|
-
@backup_file_size ||= capture "cd #{shared_path}/backups && wc -c #{@backup_file_name} | awk '{print $1}'"
|
11
|
-
end
|
12
|
-
|
13
|
-
def download_backup(backup_file, type)
|
14
|
-
puts "Downloading #{type} backup"
|
15
|
-
download! "#{shared_path}/backups/#{backup_file}", backup_file
|
16
|
-
puts "Download finished\nDeleting temporary backup..."
|
17
|
-
cleanup_backup(backup_file, "Download finished\nDeleting temporary backup...")
|
18
|
-
end
|
19
|
-
|
20
|
-
def cleanup_backup(backup_file, message)
|
21
|
-
puts message
|
22
|
-
execute "cd #{shared_path}/backups && rm #{backup_file}"
|
23
|
-
puts 'Temporary backup deleted'
|
24
|
-
end
|
25
|
-
|
26
|
-
def question(question, default = 'n', &block)
|
27
|
-
print "#{question} #{default.downcase == 'n' ? '(y/N)' : '(Y/n)'}: "
|
28
|
-
input = $stdin.gets.strip.downcase
|
29
|
-
answer = (input.empty? ? default : input).downcase.to_s
|
30
|
-
|
31
|
-
if %w[y n].include?(answer)
|
32
|
-
block.call(answer == 'y')
|
33
|
-
else
|
34
|
-
question(question, default, &block)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def prepare_env
|
39
|
-
@env = "RAILS_ENV=#{fetch(:stage)}"
|
40
|
-
@path_cmd = "PATH=$HOME/.rbenv/versions/#{RUBY_VERSION}/bin:$PATH"
|
41
|
-
@test_command = "cd #{release_path} && #{@path_cmd} && #{@env}"
|
42
|
-
end
|
43
|
-
|
44
|
-
def size_str(size)
|
45
|
-
units = %w[B KB MB GB TB]
|
46
|
-
e = (Math.log(size) / Math.log(1024)).floor
|
47
|
-
s = format('%.2f', size.to_f / 1024**e)
|
48
|
-
s.sub(/\.?0*$/, units[e])
|
49
|
-
end
|
50
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module FigaroYmlHelper
|
4
|
-
def environments
|
5
|
-
Dir.glob('config/deploy/*.rb')
|
6
|
-
end
|
7
|
-
|
8
|
-
def local_yaml
|
9
|
-
YAML.safe_load(File.read('config/application.yml')) || {}
|
10
|
-
end
|
11
|
-
|
12
|
-
def write_to_file(file, content)
|
13
|
-
File.open(file, 'w') do |f|
|
14
|
-
f.write(content)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def write_combined_yaml(yamls_combined)
|
19
|
-
if yamls_combined.empty?
|
20
|
-
info 'No data to write.'
|
21
|
-
else
|
22
|
-
# write to new file
|
23
|
-
info 'writing to config/application.yml'
|
24
|
-
write_to_file('config/application.yml', yamls_combined.to_yaml)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def compare_hashes(hash1, hash2)
|
29
|
-
all_keys = hash1.keys | hash2.keys # Union of all keys from both hashes
|
30
|
-
all_keys.each_with_object({}) do |key, changes_hash|
|
31
|
-
old_value = hash2[key].nil? ? 'nil' : hash2[key].to_s
|
32
|
-
new_value = hash1[key].nil? ? 'nil' : hash1[key].to_s
|
33
|
-
|
34
|
-
changes_hash[key] = { old: old_value, new: new_value } if old_value != new_value
|
35
|
-
end.tap { |changes| return changes.empty? ? nil : changes }
|
36
|
-
end
|
37
|
-
|
38
|
-
def print_changes(changes, message)
|
39
|
-
return unless changes
|
40
|
-
|
41
|
-
puts "#{message}:\n\n"
|
42
|
-
changes.each do |key, diff|
|
43
|
-
puts "#{key}: #{diff[:old]} => #{diff[:new]}"
|
44
|
-
end
|
45
|
-
puts "\n"
|
46
|
-
end
|
47
|
-
|
48
|
-
def ask_to_overwrite(question)
|
49
|
-
answer = ''
|
50
|
-
until %w[y n].include?(answer)
|
51
|
-
print "#{question}? (y/N): "
|
52
|
-
answer = $stdin.gets.strip.downcase
|
53
|
-
end
|
54
|
-
answer == 'y'
|
55
|
-
end
|
56
|
-
|
57
|
-
def configs(yaml, env)
|
58
|
-
stage_yml = yaml[env.to_s]&.sort.to_h
|
59
|
-
global_yml = remove_nested(yaml)&.sort.to_h
|
60
|
-
[global_yml, stage_yml]
|
61
|
-
end
|
62
|
-
|
63
|
-
def remove_nested(hash)
|
64
|
-
hash.each_with_object({}) do |(key, value), new_hash|
|
65
|
-
new_hash[key] = value unless value.is_a?(Hash)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def sort_with_nested(hash)
|
70
|
-
hash.each_with_object({}) do |(key, value), new_hash|
|
71
|
-
new_hash[key] = value.is_a?(Hash) ? sort_with_nested(value) : value
|
72
|
-
end.sort.to_h
|
73
|
-
end
|
74
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'figaro_yaml_helper'
|
4
|
-
|
5
|
-
namespace :figaro_yml do
|
6
|
-
include FigaroYmlHelper
|
7
|
-
|
8
|
-
rake_roles = fetch(:rake_roles, :app)
|
9
|
-
desc 'get the `application.yml` file from server and create local if it does not exist'
|
10
|
-
task :get do
|
11
|
-
env = fetch(:stage)
|
12
|
-
if !File.exist?('config/application.yml')
|
13
|
-
run_locally do
|
14
|
-
puts "found #{environments.count} stages"
|
15
|
-
yamls_combined = {}
|
16
|
-
|
17
|
-
stages.each do |f|
|
18
|
-
stage = File.basename(f, '.rb')
|
19
|
-
puts "download #{stage} application.yml"
|
20
|
-
begin
|
21
|
-
res = capture "cap #{stage} figaro_yml:get_stage"
|
22
|
-
stage_yaml = YAML.safe_load(res)
|
23
|
-
stage_yaml[stage.to_s] = stage_yaml[stage.to_s].sort.to_h
|
24
|
-
yamls_combined.merge!(stage_yaml) if stage_yaml
|
25
|
-
rescue StandardError
|
26
|
-
puts "could not get #{stage} application.yml"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
write_combined_yaml(yamls_combined.sort.to_h)
|
31
|
-
end
|
32
|
-
else
|
33
|
-
on roles(rake_roles) do
|
34
|
-
local_yml = local_yaml.sort.to_h
|
35
|
-
local_global, local_stage = configs(local_yml, env)
|
36
|
-
|
37
|
-
remote = capture("cat #{shared_path}/config/application.yml")
|
38
|
-
remote_yml = YAML.safe_load(remote).sort.to_h
|
39
|
-
remote_global, remote_stage = configs(remote_yml, env)
|
40
|
-
|
41
|
-
differences_global = compare_hashes(remote_global, local_global || {})
|
42
|
-
differences_stage = compare_hashes(remote_stage, local_stage || {})
|
43
|
-
|
44
|
-
print_changes(differences_global,
|
45
|
-
'Remote application.yml has extra/different global entries compared to local.')
|
46
|
-
print_changes(differences_stage, "Remote application.yml has extra/different entries in #{env} section compared to local.") if differences_stage
|
47
|
-
|
48
|
-
puts 'No Differences found between remote and local application.yml' unless differences_global || differences_stage
|
49
|
-
|
50
|
-
# ask to overwrite local yml if differences found
|
51
|
-
stage_overwrite = ask_to_overwrite("Overwrite local application.yml #{env} section") if differences_stage
|
52
|
-
global_overwrite = ask_to_overwrite('Overwrite local application.yml globals') if differences_global
|
53
|
-
puts 'Nothing written to local application.yml' unless stage_overwrite || global_overwrite
|
54
|
-
exit unless stage_overwrite || global_overwrite
|
55
|
-
|
56
|
-
# compose new yml
|
57
|
-
composed_yml = {}
|
58
|
-
composed_yml.merge!(local_yml) # local yml is always included to avoid losing any data
|
59
|
-
composed_yml.merge!(local_global) unless global_overwrite
|
60
|
-
composed_yml.merge!(remote_global) if global_overwrite
|
61
|
-
composed_yml[env.to_s] = stage_overwrite ? remote_stage : local_stage
|
62
|
-
|
63
|
-
# write to new file
|
64
|
-
write_combined_yaml(composed_yml.sort.to_h)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'figaro_yaml_helper'
|
4
|
-
|
5
|
-
namespace :figaro_yml do
|
6
|
-
rake_roles = fetch(:rake_roles, :app)
|
7
|
-
|
8
|
-
task :get_stage do
|
9
|
-
on roles(rake_roles) do
|
10
|
-
puts capture "cat #{shared_path}/config/application.yml"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|