prun-ops 0.3.9 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +3 -0
- data/.rubocop.yml +11 -0
- data/.rubocop_todo.yml +59 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +76 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +17 -18
- data/README.md +4 -77
- data/Rakefile +10 -0
- data/lib/capistrano/all.rake +13 -13
- data/lib/capistrano/backup.rake +17 -15
- data/lib/capistrano/config/app.rake +11 -11
- data/lib/capistrano/config/config.rake +12 -10
- data/lib/capistrano/config/monitis.rake +3 -1
- data/lib/capistrano/config/mysql.rake +9 -11
- data/lib/capistrano/config/nginx.rake +8 -6
- data/lib/capistrano/config/nodejs.rake +12 -6
- data/lib/capistrano/config/postgres.rake +37 -22
- data/lib/capistrano/config/rails.rake +3 -2
- data/lib/capistrano/config/redis.rake +2 -0
- data/lib/capistrano/config/ruby.rake +7 -5
- data/lib/capistrano/config/ubuntu.rake +5 -3
- data/lib/capistrano/config/yarn.rake +3 -1
- data/lib/capistrano/diagnosis.rake +24 -24
- data/lib/capistrano/git.rake +14 -11
- data/lib/capistrano/{prun-ops.rb → prun_ops.rb} +8 -6
- data/lib/{cred.rb → prun/cred.rb} +5 -2
- data/lib/{prun-ops → prun/ops}/railitie.rb +5 -3
- data/lib/prun/ops/version.rb +7 -0
- data/lib/prun/ops.rb +14 -0
- data/lib/tasks/backup.rake +18 -13
- data/lib/tasks/db.rake +29 -17
- data/lib/tasks/git.rake +3 -3
- data/lib/tasks/http.rake +4 -2
- data/lib/tasks/version.rake +6 -5
- data/sig/prun/ops.rbs +6 -0
- metadata +27 -51
- data/.gitignore +0 -16
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -60
- data/lib/prun-ops/version.rb +0 -3
- data/lib/prun-ops.rb +0 -10
- data/prun-ops.gemspec +0 -28
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
task :config do
|
2
|
-
invoke
|
3
|
-
invoke
|
4
|
-
invoke
|
5
|
-
invoke
|
6
|
-
invoke
|
7
|
-
invoke
|
8
|
-
invoke
|
9
|
-
invoke
|
10
|
-
invoke
|
4
|
+
invoke "ubuntu:install"
|
5
|
+
invoke "ruby:install"
|
6
|
+
invoke "rails:prepare"
|
7
|
+
invoke "postgres:install"
|
8
|
+
invoke "nginx:install"
|
9
|
+
invoke "nodejs:install"
|
10
|
+
invoke "yarn:install"
|
11
|
+
invoke "app:prepare"
|
12
|
+
invoke "deploy:upload_linked_files"
|
11
13
|
# invoke 'app:db_prepare'
|
12
|
-
end
|
14
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# 3UREDUE10EVIA3BFPSDO1ERFJC
|
2
4
|
# wget https://dashboard.monitis.com/downloader/smart-agent-linux-64bit.tar.gz
|
3
5
|
# tar -xvf smart-agent-linux-64bit.tar.gz
|
4
6
|
# cd smartagent
|
5
7
|
# ./smagent.sh conf
|
6
|
-
# ./smagent.sh start
|
8
|
+
# ./smagent.sh start
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
namespace :mysql do
|
2
4
|
task :install do
|
3
5
|
on roles :db do
|
4
|
-
not_if
|
6
|
+
not_if "which mysql" do
|
5
7
|
execute <<-EOBLOCK
|
6
8
|
debconf-set-selections <<< 'mysql-server mysql-server/root_password password #{fetch :my_pass}'
|
7
9
|
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password #{fetch :my_pass}'
|
@@ -16,21 +18,19 @@ namespace :mysql do
|
|
16
18
|
EOBLOCK
|
17
19
|
end
|
18
20
|
|
19
|
-
invoke
|
21
|
+
invoke "mysql:restart"
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
|
24
25
|
task :test do
|
25
26
|
on roles :db do
|
26
27
|
not_if "echo ''" do
|
27
|
-
p
|
28
|
+
p "executing ......"
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
|
-
%w(start stop restart).each do |action|
|
33
|
+
%w[start stop restart].each do |action|
|
34
34
|
desc "MySQL"
|
35
35
|
task :"#{action}" do
|
36
36
|
on roles(:app) do
|
@@ -41,9 +41,7 @@ namespace :mysql do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def not_if(command)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
yield
|
48
|
-
end
|
44
|
+
yield unless execute command
|
45
|
+
rescue Exception
|
46
|
+
yield
|
49
47
|
end
|
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
namespace :nginx do
|
2
4
|
task :install do
|
3
5
|
on roles :web, :api do
|
4
6
|
execute "#{apt_nointeractive} nginx"
|
5
7
|
execute 'sudo sed -i "s/# server_names_hash_bucket_size 64/server_names_hash_bucket_size 64/" /etc/nginx/nginx.conf'
|
6
|
-
template
|
8
|
+
template "vhost.conf", "/etc/nginx/conf.d/vhost.conf"
|
7
9
|
|
8
|
-
invoke
|
10
|
+
invoke "nginx:restart"
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
@@ -22,17 +24,17 @@ namespace :nginx do
|
|
22
24
|
end
|
23
25
|
|
24
26
|
task :ssl do
|
25
|
-
on roles(:web, :api) do |
|
27
|
+
on roles(:web, :api) do |_host|
|
26
28
|
execute <<-EOBLOCK
|
27
29
|
cd /etc/ssl/certs
|
28
30
|
openssl dhparam -out dhparam.pem 4096
|
29
31
|
EOBLOCK
|
30
|
-
template
|
31
|
-
invoke
|
32
|
+
template "vhost_ssl.conf", "/etc/nginx/conf.d/vhost.conf"
|
33
|
+
invoke "nginx:restart"
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
35
|
-
%w
|
37
|
+
%w[start stop restart status].each do |action|
|
36
38
|
desc "Nginx"
|
37
39
|
task :"#{action}" do
|
38
40
|
on roles(:web, :api) do
|
@@ -1,14 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
namespace :nodejs do
|
2
4
|
task :install do
|
3
5
|
on roles :app do
|
4
|
-
execute
|
5
|
-
|
6
|
+
execute "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash"
|
7
|
+
|
8
|
+
execute <<-EOBLOCK
|
9
|
+
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
|
10
|
+
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
|
11
|
+
EOBLOCK
|
12
|
+
execute "{ tail -n 3 .bashrc && head -n -3 .bashrc; } > tempfile && mv tempfile .bashrc"
|
13
|
+
|
6
14
|
execute <<-EOBLOCK
|
7
|
-
export NVM_DIR="$HOME/.nvm"
|
8
|
-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
9
15
|
nvm install node
|
10
|
-
npm install
|
16
|
+
npm install -g yarn
|
11
17
|
EOBLOCK
|
12
18
|
end
|
13
19
|
end
|
14
|
-
end
|
20
|
+
end
|
@@ -1,19 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
namespace :postgres do
|
2
4
|
task :install do
|
3
5
|
stage = fetch(:stage).to_s
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
password = config[stage]["password"]
|
8
|
-
database = config[stage]["database"]
|
6
|
+
Rails.env = "production"
|
7
|
+
config = Rails.configuration.database_configuration
|
8
|
+
version = config["default"]["version"]
|
9
9
|
|
10
10
|
on roles :all do
|
11
11
|
execute <<-EOBLOCK
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
#{apt_nointeractive} curl ca-certificates
|
13
|
+
sudo install -d /usr/share/postgresql-common/pgdg
|
14
|
+
sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
|
15
|
+
EOBLOCK
|
16
|
+
|
17
|
+
execute <<-EOBLOCK
|
18
|
+
. /etc/os-release
|
19
|
+
sudo sh -c "echo 'deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $VERSION_CODENAME-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
|
20
|
+
sudo apt -y update
|
21
|
+
#{apt_nointeractive} postgresql-client-#{version} libpq-dev
|
17
22
|
EOBLOCK
|
18
23
|
end
|
19
24
|
|
@@ -25,26 +30,27 @@ namespace :postgres do
|
|
25
30
|
execute <<-EOBLOCK
|
26
31
|
sudo sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" /etc/postgresql/#{version}/main/postgresql.conf
|
27
32
|
sudo sed -i "s/local all all peer/local all all md5/" /etc/postgresql/#{version}/main/pg_hba.conf
|
28
|
-
sudo sed -i "s/host all all 127.0.0.1
|
33
|
+
sudo sed -i "s/host all all 127.0.0.1\\/32 scram-sha-256/host all all all scram-sha-256/" /etc/postgresql/#{version}/main/pg_hba.conf
|
29
34
|
sudo sed -i "s/ssl = on/ssl = off/" /etc/postgresql/#{version}/main/postgresql.conf
|
30
35
|
sudo service postgresql restart
|
31
36
|
EOBLOCK
|
32
37
|
|
33
38
|
## Rewrite postgres password:
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
if Rails.version.to_i >= 8
|
40
|
+
%w[primary cable queue cache].each do |db|
|
41
|
+
create_db(username: config[stage][db]["username"], password: config[stage][db]["password"],
|
42
|
+
database: config[stage][db]["database"])
|
43
|
+
end
|
44
|
+
else
|
45
|
+
create_db(username: config[stage]["username"], password: config[stage]["password"],
|
46
|
+
database: config[stage]["database"])
|
47
|
+
end
|
42
48
|
|
43
|
-
invoke
|
49
|
+
invoke "postgres:restart"
|
44
50
|
end
|
45
51
|
end
|
46
52
|
|
47
|
-
%w
|
53
|
+
%w[start stop restart].each do |action|
|
48
54
|
desc "PostgreSQL"
|
49
55
|
task :"#{action}" do
|
50
56
|
on roles(:app) do
|
@@ -52,4 +58,13 @@ namespace :postgres do
|
|
52
58
|
end
|
53
59
|
end
|
54
60
|
end
|
55
|
-
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_db(username:, password:, database:)
|
64
|
+
execute <<-EOBLOCK
|
65
|
+
sudo -u postgres psql -c "CREATE USER #{username} WITH PASSWORD '#{password}';"
|
66
|
+
sudo -u postgres psql -c "create database #{database};"
|
67
|
+
sudo -u postgres psql -c "grant all privileges on database #{database} to #{username};"
|
68
|
+
sudo -u postgres psql -c "alter user #{username} with superuser;"
|
69
|
+
EOBLOCK
|
70
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
namespace :rails do
|
2
4
|
task :prepare do
|
3
5
|
on roles :all do
|
@@ -13,7 +15,6 @@ namespace :rails do
|
|
13
15
|
sudo mkdir -p /var/www/#{fetch :application}
|
14
16
|
sudo chown #{host.user}:#{host.user} /var/www/#{fetch :application}
|
15
17
|
EOBLOCK
|
16
|
-
|
17
18
|
end
|
18
19
|
end
|
19
|
-
end
|
20
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
namespace :ruby do
|
2
4
|
task :brightbox do
|
3
|
-
ruby_version = File.read(
|
5
|
+
ruby_version = File.read(".ruby-version").strip[/\Aruby-(.*)\.\d\Z/, 1]
|
4
6
|
on roles :all do
|
5
7
|
execute <<-EOBLOCK
|
6
8
|
sudo apt-add-repository -y ppa:brightbox/ruby-ng
|
@@ -16,13 +18,14 @@ namespace :ruby do
|
|
16
18
|
sudo apt-get update
|
17
19
|
#{apt_nointeractive} rvm
|
18
20
|
sudo usermod -a -G rvm $USER
|
19
|
-
|
21
|
+
cp ~/.bashrc ~/.bashrc.bak
|
22
|
+
{ echo '[[ -s /usr/share/rvm/scripts/rvm ]] && source /usr/share/rvm/scripts/rvm'; cat ~/.bashrc.bak; } > ~/.bashrc
|
20
23
|
EOBLOCK
|
21
24
|
end
|
22
25
|
end
|
23
26
|
task :install_rvm_project_version do
|
24
|
-
ruby_version = File.read(
|
25
|
-
ruby_version = ruby_version.start_with?(
|
27
|
+
ruby_version = File.read(".ruby-version").strip
|
28
|
+
ruby_version = "ruby-#{ruby_version}" unless ruby_version.start_with?("ruby-")
|
26
29
|
|
27
30
|
on roles :all do
|
28
31
|
execute <<-EOBLOCK
|
@@ -32,5 +35,4 @@ namespace :ruby do
|
|
32
35
|
EOBLOCK
|
33
36
|
end
|
34
37
|
end
|
35
|
-
|
36
38
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
namespace :ubuntu do
|
2
4
|
task :prepare do
|
3
5
|
on roles :all do
|
4
|
-
execute
|
6
|
+
execute "sudo apt-get -y update"
|
5
7
|
# Pre-requirements
|
6
8
|
execute <<-EOBLOCK
|
7
|
-
#{apt_nointeractive} git build-essential libsqlite3-dev libssl-dev gawk g++ vim
|
9
|
+
#{apt_nointeractive} git build-essential libsqlite3-dev libssl-dev gawk g++ vim#{" "}
|
8
10
|
#{apt_nointeractive} libssl-dev libreadline-dev libgdbm-dev openssl
|
9
11
|
#{apt_nointeractive} libreadline6-dev libyaml-dev sqlite3 autoconf libgdbm-dev
|
10
|
-
#{apt_nointeractive} libcurl4 libcurl3-gnutls libcurl4-openssl-dev
|
12
|
+
#{apt_nointeractive} libcurl4 libcurl3-gnutls libcurl4-openssl-dev#{" "}
|
11
13
|
#{apt_nointeractive} libncurses5-dev automake libtool bison pkg-config libffi-dev libvips
|
12
14
|
#{apt_nointeractive} software-properties-common gnupg2
|
13
15
|
EOBLOCK
|
@@ -1,16 +1,18 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
desc "SSH connection with server. If many servers are defined, you can pass a hostname part as argument: cap ssh[hostname]"
|
2
4
|
task :ssh, :hostname do |_task, args|
|
3
5
|
server = roles(:app).select do |s|
|
4
6
|
args[:hostname].nil? || (!args[:hostname].nil? && s.hostname.include?(args[:hostname]))
|
5
7
|
end
|
6
8
|
on server do |host|
|
7
9
|
run_locally do
|
8
|
-
run_in host,
|
10
|
+
run_in host, ""
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
|
-
desc
|
15
|
+
desc "Opens a remote Rails console"
|
14
16
|
task :c do
|
15
17
|
on roles(:app) do |host|
|
16
18
|
run_locally do
|
@@ -19,7 +21,7 @@ task :c do
|
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
|
-
desc
|
24
|
+
desc "Opens a remote Database console"
|
23
25
|
task :dbconsole do
|
24
26
|
on roles(:app) do |host|
|
25
27
|
run_locally do
|
@@ -28,23 +30,23 @@ task :dbconsole do
|
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
|
-
desc
|
32
|
-
task :log_tail, :file do |
|
33
|
+
desc "Tails the environment log or the log passed as argument: cap log_tail[thin.3000.log]"
|
34
|
+
task :log_tail, :file do |_task, args|
|
33
35
|
on roles(:app) do
|
34
|
-
file = args[:file]
|
36
|
+
file = args[:file] || "*"
|
35
37
|
execute "tail -f #{current_path}/log/#{file} | grep -vE \"(^\s*$|asset|Render)\""
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
|
-
desc
|
40
|
-
task :log_pattern, :pattern do |
|
41
|
+
desc "Search for a pattern in logs"
|
42
|
+
task :log_pattern, :pattern do |_task, args|
|
41
43
|
on roles(:app) do
|
42
44
|
execute "cat #{current_path}/log/* | grep -A 10 -B 5 '#{args[:pattern]}'"
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
46
48
|
desc "Runs a command in server: cap production x['free -m']"
|
47
|
-
task :x, :command do |
|
49
|
+
task :x, :command do |_task, args|
|
48
50
|
on roles(:app) do |host|
|
49
51
|
run_locally do
|
50
52
|
run_in host, args[:command]
|
@@ -52,19 +54,19 @@ task :x, :command do |task, args|
|
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
55
|
-
desc
|
56
|
-
task :rake, :remote_task do |
|
57
|
+
desc "Executes a rake task in server. i.e.: cap staging rake[db:version]"
|
58
|
+
task :rake, :remote_task do |_task, args|
|
57
59
|
on roles(:app) do
|
58
60
|
within release_path do
|
59
61
|
with rails_env: fetch(:stage) do
|
60
|
-
execute :rake,
|
62
|
+
execute :rake, args[:remote_task].to_s
|
61
63
|
end
|
62
64
|
end
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
66
|
-
desc
|
67
|
-
task :upload, :file_path do |
|
68
|
+
desc "Uploads a file to /tmp folder. i.e.: cap staging upload[tmp/db.sql]"
|
69
|
+
task :upload, :file_path do |_task, args|
|
68
70
|
on roles(:app) do |host|
|
69
71
|
run_locally do
|
70
72
|
upload_scp host, args[:file_path]
|
@@ -72,8 +74,8 @@ task :upload, :file_path do |task, args|
|
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
75
|
-
desc
|
76
|
-
task :download, :file_path do |
|
77
|
+
desc "Downloads a file. i.e.: cap staging download[/tmp/db.sql]"
|
78
|
+
task :download, :file_path do |_task, args|
|
77
79
|
on roles(:app) do |host|
|
78
80
|
run_locally do
|
79
81
|
download_scp host, args[:file_path]
|
@@ -81,16 +83,15 @@ task :download, :file_path do |task, args|
|
|
81
83
|
end
|
82
84
|
end
|
83
85
|
|
84
|
-
|
85
86
|
def run_in(host, remote_cmd)
|
86
87
|
cmd = %w[ssh]
|
87
88
|
opts = fetch(:ssh_options)
|
88
89
|
cmd << "-oProxyCommand='#{opts[:proxy].command_line_template}'" if opts
|
89
90
|
cmd << "#{host.user}@#{host.hostname}"
|
90
|
-
cmd << "-p #{host.port ||
|
91
|
+
cmd << "-p #{host.port || "22"}"
|
91
92
|
cmd << "-tt '#{remote_cmd}'"
|
92
93
|
|
93
|
-
command = cmd.join(
|
94
|
+
command = cmd.join(" ")
|
94
95
|
Rails.logger.info command
|
95
96
|
exec command
|
96
97
|
end
|
@@ -103,7 +104,7 @@ def upload_scp(host, file_path)
|
|
103
104
|
cmd << file_path
|
104
105
|
cmd << "#{host.user}@#{host.hostname}:/tmp"
|
105
106
|
|
106
|
-
command = cmd.join(
|
107
|
+
command = cmd.join(" ")
|
107
108
|
Rails.logger.info command
|
108
109
|
exec command
|
109
110
|
end
|
@@ -113,10 +114,9 @@ def download_scp(host, file_path)
|
|
113
114
|
opts = fetch(:ssh_options)
|
114
115
|
cmd << "-oProxyCommand='#{opts[:proxy].command_line_template}'" if opts
|
115
116
|
cmd << "#{host.user}@#{host.hostname}:#{file_path}"
|
116
|
-
cmd <<
|
117
|
+
cmd << "."
|
117
118
|
|
118
|
-
command = cmd.join(
|
119
|
+
command = cmd.join(" ")
|
119
120
|
Rails.logger.info command
|
120
121
|
exec command
|
121
122
|
end
|
122
|
-
|
data/lib/capistrano/git.rake
CHANGED
@@ -1,31 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
namespace :git do
|
2
|
-
desc
|
4
|
+
desc "Git pull for common code project"
|
3
5
|
task :pull_common do
|
4
6
|
on roles(:app) do
|
5
|
-
|
6
|
-
|
7
|
-
|
7
|
+
if test("[ -d /var/www/common ]")
|
8
|
+
within "/var/www/common" do
|
9
|
+
execute :git, :pull, :origin, :master
|
10
|
+
end
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
after "deploy:updating", "git:pull_common"
|
11
15
|
|
12
|
-
desc
|
16
|
+
desc "Deploy from local git repository"
|
13
17
|
task :deploy_from_local_repo do
|
14
|
-
set :repo_url,
|
18
|
+
set :repo_url, "file:///tmp/.git"
|
15
19
|
run_locally do
|
16
20
|
execute "tar -zcvf /tmp/repo.tgz .git"
|
17
21
|
end
|
18
22
|
on roles(:all) do
|
19
|
-
upload!
|
20
|
-
execute
|
23
|
+
upload! "/tmp/repo.tgz", "/tmp/repo.tgz"
|
24
|
+
execute "tar -zxvf /tmp/repo.tgz -C /tmp"
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
|
-
desc
|
28
|
+
desc "Removes repo (useful when repo_url changes)"
|
25
29
|
task :remove_repo do
|
26
30
|
on roles(:all) do
|
27
31
|
execute "rm -r #{repo_path}"
|
28
32
|
end
|
29
33
|
end
|
30
|
-
|
31
|
-
end
|
34
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Dir.glob("#{File.dirname(__FILE__)}/*.rake").each { |r| load r }
|
2
4
|
Dir.glob("#{File.dirname(__FILE__)}/config/*.rake").each { |r| load r }
|
3
5
|
|
@@ -5,25 +7,25 @@ Dir.glob("#{File.dirname(__FILE__)}/config/*.rake").each { |r| load r }
|
|
5
7
|
def template(template_name, target_path)
|
6
8
|
begin
|
7
9
|
file = File.read("#{File.dirname(__FILE__)}/config/templates/#{template_name}.erb")
|
8
|
-
rescue
|
10
|
+
rescue StandardError
|
9
11
|
file = File.read("lib/capistrano/config/templates/#{template_name}.erb")
|
10
12
|
end
|
11
13
|
|
12
|
-
template = ERB.new
|
14
|
+
template = ERB.new(file, trim_mode: "%")
|
13
15
|
rendered = template.result(binding)
|
14
16
|
tmp_file = "/tmp/#{SecureRandom.hex}.#{template_name}"
|
15
17
|
upload! StringIO.new(rendered), tmp_file
|
16
18
|
execute "sudo cp #{tmp_file} #{target_path}"
|
17
|
-
execute
|
19
|
+
execute "rm #{tmp_file}"
|
18
20
|
end
|
19
21
|
|
20
22
|
## Bastion config
|
21
23
|
def bastion(host, user:)
|
22
|
-
require
|
24
|
+
require "net/ssh/proxy/command"
|
23
25
|
ssh_command = "ssh -W %h:%p -o StrictHostKeyChecking=no #{user}@#{host}"
|
24
26
|
set :ssh_options, proxy: Net::SSH::Proxy::Command.new(ssh_command)
|
25
27
|
end
|
26
28
|
|
27
29
|
def apt_nointeractive
|
28
|
-
|
29
|
-
end
|
30
|
+
"sudo DEBIAN_FRONTEND=noninteractive apt-get install -y"
|
31
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Cred
|
2
4
|
def self.[](name)
|
3
5
|
env_result = Rails.application.credentials.dig(Rails.env.to_sym, name)
|
4
|
-
return Rails.application.credentials
|
6
|
+
return Rails.application.credentials[name] unless env_result
|
7
|
+
|
5
8
|
env_result
|
6
9
|
end
|
7
|
-
end
|
10
|
+
end
|
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "prun/ops"
|
4
|
+
require "rails"
|
3
5
|
module PrunOps
|
4
6
|
class Railtie < Rails::Railtie
|
5
7
|
rake_tasks do
|
6
8
|
Dir.glob("#{File.dirname(__FILE__)}/../tasks/*.rake").each { |r| load r }
|
7
9
|
end
|
8
10
|
end
|
9
|
-
end
|
11
|
+
end
|
data/lib/prun/ops.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "ops/version"
|
4
|
+
require_relative "cred"
|
5
|
+
|
6
|
+
module Prun
|
7
|
+
module Ops
|
8
|
+
class Error < StandardError; end
|
9
|
+
# Your code goes here...
|
10
|
+
require "prun/ops/railitie" if defined?(Rails)
|
11
|
+
|
12
|
+
Rails.logger = Logger.new($stdout) if defined?(Rails) && (Rails.env == "development")
|
13
|
+
end
|
14
|
+
end
|