mrsk 0.5.0 → 0.5.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/lib/mrsk/cli/accessory.rb +36 -8
- data/lib/mrsk/cli/app.rb +33 -9
- data/lib/mrsk/cli/build.rb +4 -1
- data/lib/mrsk/cli/main.rb +7 -0
- data/lib/mrsk/cli/prune.rb +8 -2
- data/lib/mrsk/cli/registry.rb +1 -1
- data/lib/mrsk/cli/traefik.rb +16 -4
- data/lib/mrsk/commander.rb +6 -1
- data/lib/mrsk/commands/auditor.rb +31 -0
- data/lib/mrsk/commands/base.rb +4 -0
- data/lib/mrsk/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d76643b4635191a3301d23e41f5f4c18ca0db674c44d66b98610df0279c85c66
|
4
|
+
data.tar.gz: cd19d1ed503529b6876232d88f5133f782ddfca7f16e13d781120ed269e155d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3fc1e47cc35077797dbcc366924c470d877f3f7980ba3b0c87c1dcd4230eb563f4b478a6ee1dfe48cf07c1ae1373d2f746dbd9433c494fd20bfd64a6096058b
|
7
|
+
data.tar.gz: 4c6c4875c4f91712b6dd2fbeeb0c662c45aaf373508a9696a2cf47cd7d9a2fe486774f9b2897c9416dc9bb7f1dcb6890a5be3ef781654e264792c0858beb9f6c
|
data/lib/mrsk/cli/accessory.rb
CHANGED
@@ -9,7 +9,10 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
|
9
9
|
with_accessory(name) do |accessory|
|
10
10
|
directories(name)
|
11
11
|
upload(name)
|
12
|
-
on(accessory.host)
|
12
|
+
on(accessory.host) do
|
13
|
+
execute *MRSK.auditor.record("accessory #{name} boot"), verbosity: :debug
|
14
|
+
execute *accessory.run
|
15
|
+
end
|
13
16
|
end
|
14
17
|
end
|
15
18
|
end
|
@@ -18,6 +21,8 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
|
18
21
|
def upload(name)
|
19
22
|
with_accessory(name) do |accessory|
|
20
23
|
on(accessory.host) do
|
24
|
+
execute *MRSK.auditor.record("accessory #{name} upload files"), verbosity: :debug
|
25
|
+
|
21
26
|
accessory.files.each do |(local, remote)|
|
22
27
|
accessory.ensure_local_file_present(local)
|
23
28
|
|
@@ -33,6 +38,8 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
|
33
38
|
def directories(name)
|
34
39
|
with_accessory(name) do |accessory|
|
35
40
|
on(accessory.host) do
|
41
|
+
execute *MRSK.auditor.record("accessory #{name} create directories"), verbosity: :debug
|
42
|
+
|
36
43
|
accessory.directories.keys.each do |host_path|
|
37
44
|
execute *accessory.make_directory(host_path)
|
38
45
|
end
|
@@ -52,14 +59,20 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
|
52
59
|
desc "start [NAME]", "Start existing accessory on host"
|
53
60
|
def start(name)
|
54
61
|
with_accessory(name) do |accessory|
|
55
|
-
on(accessory.host)
|
62
|
+
on(accessory.host) do
|
63
|
+
execute *MRSK.auditor.record("accessory #{name} start"), verbosity: :debug
|
64
|
+
execute *accessory.start
|
65
|
+
end
|
56
66
|
end
|
57
67
|
end
|
58
68
|
|
59
69
|
desc "stop [NAME]", "Stop accessory on host"
|
60
70
|
def stop(name)
|
61
71
|
with_accessory(name) do |accessory|
|
62
|
-
on(accessory.host)
|
72
|
+
on(accessory.host) do
|
73
|
+
execute *MRSK.auditor.record("accessory #{name} stop"), verbosity: :debug
|
74
|
+
execute *accessory.stop, raise_on_non_zero_exit: false
|
75
|
+
end
|
63
76
|
end
|
64
77
|
end
|
65
78
|
|
@@ -98,11 +111,17 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
|
98
111
|
|
99
112
|
when options[:reuse]
|
100
113
|
say "Launching command from existing container...", :magenta
|
101
|
-
on(accessory.host)
|
114
|
+
on(accessory.host) do
|
115
|
+
execute *MRSK.auditor.record("accessory #{name} cmd '#{cmd}'"), verbosity: :debug
|
116
|
+
capture_with_info(*accessory.execute_in_existing_container(cmd))
|
117
|
+
end
|
102
118
|
|
103
119
|
else
|
104
120
|
say "Launching command from new container...", :magenta
|
105
|
-
on(accessory.host)
|
121
|
+
on(accessory.host) do
|
122
|
+
execute *MRSK.auditor.record("accessory #{name} cmd '#{cmd}'"), verbosity: :debug
|
123
|
+
capture_with_info(*accessory.execute_in_new_container(cmd))
|
124
|
+
end
|
106
125
|
end
|
107
126
|
end
|
108
127
|
end
|
@@ -150,21 +169,30 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
|
150
169
|
desc "remove_container [NAME]", "Remove accessory container from host"
|
151
170
|
def remove_container(name)
|
152
171
|
with_accessory(name) do |accessory|
|
153
|
-
on(accessory.host)
|
172
|
+
on(accessory.host) do
|
173
|
+
execute *MRSK.auditor.record("accessory #{name} remove container"), verbosity: :debug
|
174
|
+
execute *accessory.remove_container
|
175
|
+
end
|
154
176
|
end
|
155
177
|
end
|
156
178
|
|
157
179
|
desc "remove_image [NAME]", "Remove accessory image from host"
|
158
180
|
def remove_image(name)
|
159
181
|
with_accessory(name) do |accessory|
|
160
|
-
on(accessory.host)
|
182
|
+
on(accessory.host) do
|
183
|
+
execute *MRSK.auditor.record("accessory #{name} remove image"), verbosity: :debug
|
184
|
+
execute *accessory.remove_image
|
185
|
+
end
|
161
186
|
end
|
162
187
|
end
|
163
188
|
|
164
189
|
desc "remove_service_directory [NAME]", "Remove accessory directory used for uploaded files and data directories from host"
|
165
190
|
def remove_service_directory(name)
|
166
191
|
with_accessory(name) do |accessory|
|
167
|
-
on(accessory.host)
|
192
|
+
on(accessory.host) do
|
193
|
+
execute *MRSK.auditor.record("accessory #{name} remove service directory"), verbosity: :debug
|
194
|
+
execute *accessory.remove_service_directory
|
195
|
+
end
|
168
196
|
end
|
169
197
|
end
|
170
198
|
|
data/lib/mrsk/cli/app.rb
CHANGED
@@ -14,6 +14,8 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
|
14
14
|
|
15
15
|
MRSK.config.roles.each do |role|
|
16
16
|
on(role.hosts) do |host|
|
17
|
+
execute *MRSK.auditor.record("app boot version #{version}"), verbosity: :debug
|
18
|
+
|
17
19
|
begin
|
18
20
|
execute *MRSK.app.run(role: role.name)
|
19
21
|
rescue SSHKit::Command::Failed => e
|
@@ -33,12 +35,18 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
|
33
35
|
|
34
36
|
desc "start", "Start existing app on servers (use --version=<git-hash> to designate specific version)"
|
35
37
|
def start
|
36
|
-
on(MRSK.hosts)
|
38
|
+
on(MRSK.hosts) do
|
39
|
+
execute *MRSK.auditor.record("app start version #{MRSK.version}"), verbosity: :debug
|
40
|
+
execute *MRSK.app.start, raise_on_non_zero_exit: false
|
41
|
+
end
|
37
42
|
end
|
38
43
|
|
39
44
|
desc "stop", "Stop app on servers"
|
40
45
|
def stop
|
41
|
-
on(MRSK.hosts)
|
46
|
+
on(MRSK.hosts) do
|
47
|
+
execute *MRSK.auditor.record("app stop"), verbosity: :debug
|
48
|
+
execute *MRSK.app.stop, raise_on_non_zero_exit: false
|
49
|
+
end
|
42
50
|
end
|
43
51
|
|
44
52
|
desc "details", "Display details about app containers"
|
@@ -68,15 +76,22 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
|
68
76
|
when options[:reuse]
|
69
77
|
say "Get current version of running container...", :magenta unless options[:version]
|
70
78
|
using_version(options[:version] || current_running_version) do |version|
|
71
|
-
say "Launching command with version #{version} from existing container
|
72
|
-
|
79
|
+
say "Launching command with version #{version} from existing container...", :magenta
|
80
|
+
|
81
|
+
on(MRSK.hosts) do |host|
|
82
|
+
execute *MRSK.auditor.record("app cmd '#{cmd}' with version #{version}"), verbosity: :debug
|
83
|
+
puts_by_host host, capture_with_info(*MRSK.app.execute_in_existing_container(cmd))
|
84
|
+
end
|
73
85
|
end
|
74
86
|
|
75
87
|
else
|
76
88
|
say "Get most recent version available as an image...", :magenta unless options[:version]
|
77
89
|
using_version(options[:version] || most_recent_version_available) do |version|
|
78
|
-
say "Launching command with version #{version} from new container
|
79
|
-
on(MRSK.hosts)
|
90
|
+
say "Launching command with version #{version} from new container...", :magenta
|
91
|
+
on(MRSK.hosts) do |host|
|
92
|
+
execute *MRSK.auditor.record("app cmd '#{cmd}' with version #{version}"), verbosity: :debug
|
93
|
+
puts_by_host host, capture_with_info(*MRSK.app.execute_in_new_container(cmd))
|
94
|
+
end
|
80
95
|
end
|
81
96
|
end
|
82
97
|
end
|
@@ -134,17 +149,26 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
|
134
149
|
|
135
150
|
desc "remove_container [VERSION]", "Remove app container with given version from servers"
|
136
151
|
def remove_container(version)
|
137
|
-
on(MRSK.hosts)
|
152
|
+
on(MRSK.hosts) do
|
153
|
+
execute *MRSK.auditor.record("app remove container #{version}"), verbosity: :debug
|
154
|
+
execute *MRSK.app.remove_container(version: version)
|
155
|
+
end
|
138
156
|
end
|
139
157
|
|
140
158
|
desc "remove_containers", "Remove all app containers from servers"
|
141
159
|
def remove_containers
|
142
|
-
on(MRSK.hosts)
|
160
|
+
on(MRSK.hosts) do
|
161
|
+
execute *MRSK.auditor.record("app remove containers"), verbosity: :debug
|
162
|
+
execute *MRSK.app.remove_containers
|
163
|
+
end
|
143
164
|
end
|
144
165
|
|
145
166
|
desc "remove_images", "Remove all app images from servers"
|
146
167
|
def remove_images
|
147
|
-
on(MRSK.hosts)
|
168
|
+
on(MRSK.hosts) do
|
169
|
+
execute *MRSK.auditor.record("app remove images"), verbosity: :debug
|
170
|
+
execute *MRSK.app.remove_images
|
171
|
+
end
|
148
172
|
end
|
149
173
|
|
150
174
|
desc "current_version", "Shows the version currently running"
|
data/lib/mrsk/cli/build.rb
CHANGED
@@ -30,7 +30,10 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
|
|
30
30
|
|
31
31
|
desc "pull", "Pull app image from the registry onto servers"
|
32
32
|
def pull
|
33
|
-
on(MRSK.hosts)
|
33
|
+
on(MRSK.hosts) do
|
34
|
+
execute *MRSK.auditor.record("build pull image #{MRSK.version}"), verbosity: :debug
|
35
|
+
execute *MRSK.builder.pull
|
36
|
+
end
|
34
37
|
end
|
35
38
|
|
36
39
|
desc "create", "Create a local build setup"
|
data/lib/mrsk/cli/main.rb
CHANGED
@@ -70,6 +70,13 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
|
70
70
|
invoke "mrsk:cli:accessory:details", [ "all" ]
|
71
71
|
end
|
72
72
|
|
73
|
+
desc "audit", "Show audit log from servers"
|
74
|
+
def audit
|
75
|
+
on(MRSK.hosts) do |host|
|
76
|
+
puts_by_host host, capture_with_info(*MRSK.auditor.reveal)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
73
80
|
desc "config", "Show combined config"
|
74
81
|
def config
|
75
82
|
run_locally do
|
data/lib/mrsk/cli/prune.rb
CHANGED
@@ -9,11 +9,17 @@ class Mrsk::Cli::Prune < Mrsk::Cli::Base
|
|
9
9
|
|
10
10
|
desc "images", "Prune unused images older than 30 days"
|
11
11
|
def images
|
12
|
-
on(MRSK.hosts)
|
12
|
+
on(MRSK.hosts) do
|
13
|
+
execute *MRSK.auditor.record("prune images"), verbosity: :debug
|
14
|
+
execute *MRSK.prune.images
|
15
|
+
end
|
13
16
|
end
|
14
17
|
|
15
18
|
desc "containers", "Prune stopped containers for the service older than 3 days"
|
16
19
|
def containers
|
17
|
-
on(MRSK.hosts)
|
20
|
+
on(MRSK.hosts) do
|
21
|
+
execute *MRSK.auditor.record("prune containers"), verbosity: :debug
|
22
|
+
execute *MRSK.prune.containers
|
23
|
+
end
|
18
24
|
end
|
19
25
|
end
|
data/lib/mrsk/cli/registry.rb
CHANGED
@@ -3,7 +3,7 @@ require "mrsk/cli/base"
|
|
3
3
|
class Mrsk::Cli::Registry < Mrsk::Cli::Base
|
4
4
|
desc "login", "Login to the registry locally and remotely"
|
5
5
|
def login
|
6
|
-
run_locally
|
6
|
+
run_locally { execute *MRSK.registry.login }
|
7
7
|
on(MRSK.hosts) { execute *MRSK.registry.login }
|
8
8
|
rescue ArgumentError => e
|
9
9
|
puts e.message
|
data/lib/mrsk/cli/traefik.rb
CHANGED
@@ -15,12 +15,18 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
|
|
15
15
|
|
16
16
|
desc "start", "Start existing Traefik on servers"
|
17
17
|
def start
|
18
|
-
on(MRSK.traefik_hosts)
|
18
|
+
on(MRSK.traefik_hosts) do
|
19
|
+
execute *MRSK.auditor.record("traefik start"), verbosity: :debug
|
20
|
+
execute *MRSK.traefik.start, raise_on_non_zero_exit: false
|
21
|
+
end
|
19
22
|
end
|
20
23
|
|
21
24
|
desc "stop", "Stop Traefik on servers"
|
22
25
|
def stop
|
23
|
-
on(MRSK.traefik_hosts)
|
26
|
+
on(MRSK.traefik_hosts) do
|
27
|
+
execute *MRSK.auditor.record("traefik stop"), verbosity: :debug
|
28
|
+
execute *MRSK.traefik.stop, raise_on_non_zero_exit: false
|
29
|
+
end
|
24
30
|
end
|
25
31
|
|
26
32
|
desc "restart", "Restart Traefik on servers"
|
@@ -67,11 +73,17 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
|
|
67
73
|
|
68
74
|
desc "remove_container", "Remove Traefik container from servers"
|
69
75
|
def remove_container
|
70
|
-
on(MRSK.traefik_hosts)
|
76
|
+
on(MRSK.traefik_hosts) do
|
77
|
+
execute *MRSK.auditor.record("traefik remove container"), verbosity: :debug
|
78
|
+
execute *MRSK.traefik.remove_container
|
79
|
+
end
|
71
80
|
end
|
72
81
|
|
73
82
|
desc "remove_container", "Remove Traefik image from servers"
|
74
83
|
def remove_image
|
75
|
-
on(MRSK.traefik_hosts)
|
84
|
+
on(MRSK.traefik_hosts) do
|
85
|
+
execute *MRSK.auditor.record("traefik remove image"), verbosity: :debug
|
86
|
+
execute *MRSK.traefik.remove_image
|
87
|
+
end
|
76
88
|
end
|
77
89
|
end
|
data/lib/mrsk/commander.rb
CHANGED
@@ -3,6 +3,7 @@ require "active_support/core_ext/enumerable"
|
|
3
3
|
require "mrsk/configuration"
|
4
4
|
require "mrsk/commands/accessory"
|
5
5
|
require "mrsk/commands/app"
|
6
|
+
require "mrsk/commands/auditor"
|
6
7
|
require "mrsk/commands/builder"
|
7
8
|
require "mrsk/commands/prune"
|
8
9
|
require "mrsk/commands/traefik"
|
@@ -77,6 +78,10 @@ class Mrsk::Commander
|
|
77
78
|
Mrsk::Commands::Accessory.new(config, name: name)
|
78
79
|
end
|
79
80
|
|
81
|
+
def auditor
|
82
|
+
@auditor ||= Mrsk::Commands::Auditor.new(config)
|
83
|
+
end
|
84
|
+
|
80
85
|
|
81
86
|
def with_verbosity(level)
|
82
87
|
old_level = SSHKit.config.output_verbosity
|
@@ -89,7 +94,7 @@ class Mrsk::Commander
|
|
89
94
|
# Test-induced damage!
|
90
95
|
def reset
|
91
96
|
@config = @config_file = @destination = @version = nil
|
92
|
-
@app = @builder = @traefik = @registry = @prune = nil
|
97
|
+
@app = @builder = @traefik = @registry = @prune = @auditor = nil
|
93
98
|
@verbosity = :info
|
94
99
|
end
|
95
100
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "active_support/core_ext/time/conversions"
|
2
|
+
require "mrsk/commands/base"
|
3
|
+
|
4
|
+
class Mrsk::Commands::Auditor < Mrsk::Commands::Base
|
5
|
+
def record(line)
|
6
|
+
append \
|
7
|
+
[ :echo, "'#{tags} #{line}'" ],
|
8
|
+
audit_log_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def reveal
|
12
|
+
[ :tail, "-n", 50, audit_log_file ]
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def audit_log_file
|
17
|
+
"mrsk-#{config.service}-audit.log"
|
18
|
+
end
|
19
|
+
|
20
|
+
def tags
|
21
|
+
"[#{timestamp}] [#{performer}]"
|
22
|
+
end
|
23
|
+
|
24
|
+
def performer
|
25
|
+
`whoami`.strip
|
26
|
+
end
|
27
|
+
|
28
|
+
def timestamp
|
29
|
+
Time.now.to_fs(:db)
|
30
|
+
end
|
31
|
+
end
|
data/lib/mrsk/commands/base.rb
CHANGED
data/lib/mrsk/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mrsk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/mrsk/commands.rb
|
93
93
|
- lib/mrsk/commands/accessory.rb
|
94
94
|
- lib/mrsk/commands/app.rb
|
95
|
+
- lib/mrsk/commands/auditor.rb
|
95
96
|
- lib/mrsk/commands/base.rb
|
96
97
|
- lib/mrsk/commands/builder.rb
|
97
98
|
- lib/mrsk/commands/builder/base.rb
|