mrsk 0.0.2 → 0.1.0
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/README.md +131 -53
- data/bin/mrsk +5 -0
- data/lib/mrsk/cli/app.rb +97 -0
- data/lib/mrsk/cli/base.rb +27 -0
- data/lib/mrsk/cli/build.rb +53 -0
- data/lib/mrsk/cli/main.rb +99 -0
- data/lib/mrsk/cli/prune.rb +19 -0
- data/lib/mrsk/cli/registry.rb +14 -0
- data/lib/mrsk/cli/server.rb +8 -0
- data/lib/mrsk/cli/templates/deploy.yml +17 -0
- data/lib/mrsk/cli/traefik.rb +44 -0
- data/lib/mrsk/cli.rb +9 -0
- data/lib/mrsk/commander.rb +57 -0
- data/lib/mrsk/commands/app.rb +12 -15
- data/lib/mrsk/commands/base.rb +27 -0
- data/lib/mrsk/commands/builder/multiarch/remote.rb +58 -0
- data/lib/mrsk/commands/builder/multiarch.rb +30 -0
- data/lib/mrsk/commands/builder/native.rb +25 -0
- data/lib/mrsk/commands/builder.rb +39 -0
- data/lib/mrsk/commands/prune.rb +17 -0
- data/lib/mrsk/commands/registry.rb +2 -0
- data/lib/mrsk/commands/traefik.rb +3 -1
- data/lib/mrsk/commands.rb +0 -23
- data/lib/mrsk/configuration/role.rb +15 -8
- data/lib/mrsk/configuration.rb +14 -4
- data/lib/mrsk/version.rb +1 -1
- data/lib/mrsk.rb +1 -4
- metadata +40 -16
- data/lib/mrsk/engine.rb +0 -4
- data/lib/tasks/mrsk/app.rake +0 -98
- data/lib/tasks/mrsk/mrsk.rake +0 -26
- data/lib/tasks/mrsk/prune.rake +0 -18
- data/lib/tasks/mrsk/registry.rake +0 -18
- data/lib/tasks/mrsk/server.rake +0 -11
- data/lib/tasks/mrsk/setup.rb +0 -16
- data/lib/tasks/mrsk/templates/deploy.yml +0 -21
- data/lib/tasks/mrsk/traefik.rake +0 -38
data/lib/tasks/mrsk/app.rake
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require_relative "setup"
|
2
|
-
|
3
|
-
app = Mrsk::Commands::App.new(MRSK_CONFIG)
|
4
|
-
|
5
|
-
namespace :mrsk do
|
6
|
-
namespace :app do
|
7
|
-
desc "Deliver a newly built app image to servers"
|
8
|
-
task deliver: %i[ push pull ]
|
9
|
-
|
10
|
-
desc "Build locally and push app image to registry"
|
11
|
-
task :push do
|
12
|
-
run_locally { execute *app.push } unless ENV["VERSION"]
|
13
|
-
end
|
14
|
-
|
15
|
-
desc "Pull app image from the registry onto servers"
|
16
|
-
task :pull do
|
17
|
-
on(MRSK_CONFIG.hosts) { execute *app.pull }
|
18
|
-
end
|
19
|
-
|
20
|
-
desc "Run app on servers (or start them if they've already been run)"
|
21
|
-
task :run do
|
22
|
-
MRSK_CONFIG.roles.each do |role|
|
23
|
-
on(role.hosts) do |host|
|
24
|
-
begin
|
25
|
-
execute *app.run(role: role.name)
|
26
|
-
rescue SSHKit::Command::Failed => e
|
27
|
-
if e.message =~ /already in use/
|
28
|
-
puts "Container with same version already deployed on #{host}, starting that instead"
|
29
|
-
execute *app.start, host: host
|
30
|
-
else
|
31
|
-
raise
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
desc "Start existing app on servers"
|
39
|
-
task :start do
|
40
|
-
on(MRSK_CONFIG.hosts) { execute *app.start, raise_on_non_zero_exit: false }
|
41
|
-
end
|
42
|
-
|
43
|
-
desc "Stop app on servers"
|
44
|
-
task :stop do
|
45
|
-
on(MRSK_CONFIG.hosts) { execute *app.stop, raise_on_non_zero_exit: false }
|
46
|
-
end
|
47
|
-
|
48
|
-
desc "Start app on servers (use VERSION=<git-hash> to designate which version)"
|
49
|
-
task restart: %i[ stop start ]
|
50
|
-
|
51
|
-
desc "Display information about app containers"
|
52
|
-
task :info do
|
53
|
-
on(MRSK_CONFIG.hosts) { |host| puts "App Host: #{host}\n" + capture(*app.info) + "\n\n" }
|
54
|
-
end
|
55
|
-
|
56
|
-
desc "Execute a custom task on servers passed in as CMD='bin/rake some:task'"
|
57
|
-
task :exec do
|
58
|
-
on(MRSK_CONFIG.hosts) { |host| puts "App Host: #{host}\n" + capture(*app.exec(ENV["CMD"])) + "\n\n" }
|
59
|
-
end
|
60
|
-
|
61
|
-
namespace :exec do
|
62
|
-
desc "Execute Rails command on servers, like CMD='runner \"puts %(Hello World)\""
|
63
|
-
task :rails do
|
64
|
-
on(MRSK_CONFIG.hosts) { |host| puts "App Host: #{host}\n" + capture(*app.exec("bin/rails", ENV["CMD"])) + "\n\n" }
|
65
|
-
end
|
66
|
-
|
67
|
-
desc "Execute a custom task on the first defined server"
|
68
|
-
task :once do
|
69
|
-
on(MRSK_CONFIG.primary_host) { |host| puts capture(*app.exec(ENV["CMD"])) }
|
70
|
-
end
|
71
|
-
|
72
|
-
namespace :once do
|
73
|
-
desc "Execute Rails command on the first defined server, like CMD='runner \"puts %(Hello World)\""
|
74
|
-
task :rails do
|
75
|
-
on(MRSK_CONFIG.primary_host) { puts capture(*app.exec("bin/rails", ENV["CMD"])) }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
desc "List all the app containers currently on servers"
|
81
|
-
task :containers do
|
82
|
-
on(MRSK_CONFIG.hosts) { |host| puts "App Host: #{host}\n" + capture(*app.list_containers) + "\n\n" }
|
83
|
-
end
|
84
|
-
|
85
|
-
desc "Tail logs from app containers"
|
86
|
-
task :logs do
|
87
|
-
on(MRSK_CONFIG.hosts) { execute *app.logs }
|
88
|
-
end
|
89
|
-
|
90
|
-
desc "Remove app containers and images from servers"
|
91
|
-
task remove: %i[ stop ] do
|
92
|
-
on(MRSK_CONFIG.hosts) do
|
93
|
-
execute *app.remove_containers
|
94
|
-
execute *app.remove_images
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
data/lib/tasks/mrsk/mrsk.rake
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require_relative "setup"
|
2
|
-
|
3
|
-
namespace :mrsk do
|
4
|
-
desc "Deploy app for the first time to a fresh server"
|
5
|
-
task fresh: %w[ server:bootstrap registry:login app:deliver traefik:run app:stop app:run ]
|
6
|
-
|
7
|
-
desc "Push the latest version of the app, ensure Traefik is running, then restart app"
|
8
|
-
task deploy: %w[ registry:login app:deliver traefik:run app:stop app:run prune ]
|
9
|
-
|
10
|
-
desc "Rollback to VERSION=x that was already run as a container on servers"
|
11
|
-
task rollback: %w[ app:restart ]
|
12
|
-
|
13
|
-
desc "Display information about Traefik and app containers"
|
14
|
-
task info: %w[ traefik:info app:info ]
|
15
|
-
|
16
|
-
desc "Create config stub in config/deploy.yml"
|
17
|
-
task :init do
|
18
|
-
require "fileutils"
|
19
|
-
FileUtils.cp_r \
|
20
|
-
Pathname.new(File.expand_path("templates/deploy.yml", __dir__)),
|
21
|
-
Rails.root.join("config/deploy.yml")
|
22
|
-
end
|
23
|
-
|
24
|
-
desc "Remove Traefik, app, and registry session from servers"
|
25
|
-
task remove: %w[ traefik:remove app:remove registry:logout ]
|
26
|
-
end
|
data/lib/tasks/mrsk/prune.rake
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require_relative "setup"
|
2
|
-
|
3
|
-
namespace :mrsk do
|
4
|
-
desc "Prune unused images and stopped containers"
|
5
|
-
task prune: %w[ prune:containers prune:images ]
|
6
|
-
|
7
|
-
namespace :prune do
|
8
|
-
desc "Prune unused images older than 30 days"
|
9
|
-
task :images do
|
10
|
-
on(MRSK_CONFIG.hosts) { execute "docker image prune -f --filter 'until=720h'" }
|
11
|
-
end
|
12
|
-
|
13
|
-
desc "Prune stopped containers for the service older than 3 days"
|
14
|
-
task :containers do
|
15
|
-
on(MRSK_CONFIG.hosts) { execute "docker container prune -f --filter label=service=#{MRSK_CONFIG.service} --filter 'until=72h'" }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require_relative "setup"
|
2
|
-
|
3
|
-
registry = Mrsk::Commands::Registry.new(MRSK_CONFIG)
|
4
|
-
|
5
|
-
namespace :mrsk do
|
6
|
-
namespace :registry do
|
7
|
-
desc "Login to the registry locally and remotely"
|
8
|
-
task :login do
|
9
|
-
run_locally { execute *registry.login }
|
10
|
-
on(MRSK_CONFIG.hosts) { execute *registry.login }
|
11
|
-
end
|
12
|
-
|
13
|
-
desc "Logout of the registry remotely"
|
14
|
-
task :logout do
|
15
|
-
on(MRSK_CONFIG.hosts) { execute *registry.logout }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/tasks/mrsk/server.rake
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require_relative "setup"
|
2
|
-
|
3
|
-
namespace :mrsk do
|
4
|
-
namespace :server do
|
5
|
-
desc "Setup Docker on the remote servers"
|
6
|
-
task :bootstrap do
|
7
|
-
# FIXME: Detect when apt-get is not available and use the appropriate alternative
|
8
|
-
on(MRSK_CONFIG.hosts) { execute "apt-get install docker.io -y" }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
data/lib/tasks/mrsk/setup.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require "sshkit"
|
2
|
-
require "sshkit/dsl"
|
3
|
-
|
4
|
-
include SSHKit::DSL
|
5
|
-
|
6
|
-
if (config_file = Rails.root.join("config/deploy.yml")).exist?
|
7
|
-
MRSK_CONFIG = Mrsk::Configuration.load_file(config_file)
|
8
|
-
|
9
|
-
SSHKit::Backend::Netssh.configure { |ssh| ssh.ssh_options = MRSK_CONFIG.ssh_options }
|
10
|
-
|
11
|
-
# No need to use /usr/bin/env, just clogs up the logs
|
12
|
-
SSHKit.config.command_map[:docker] = "docker"
|
13
|
-
else
|
14
|
-
# MRSK is missing config/deploy.yml – run 'rake mrsk:init'
|
15
|
-
MRSK_CONFIG = Mrsk::Configuration.new({}, validate: false)
|
16
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# Name of your application will be used for uniquely configuring Traefik and app containers.
|
2
|
-
# Your Dockerfile should set LABEL service=the-same-value to ensure image pruning works.
|
3
|
-
service: my-app
|
4
|
-
|
5
|
-
# Name of the container image
|
6
|
-
image: user/chat
|
7
|
-
|
8
|
-
# All the servers targeted for deploy. You can reference a single server for a command by using SERVERS=xxx.xxx.xxx.xxx
|
9
|
-
servers:
|
10
|
-
- xxx.xxx.xxx.xxx
|
11
|
-
|
12
|
-
# The following envs are made available to the container when started
|
13
|
-
env:
|
14
|
-
# Remember never to put passwords or tokens directly into this file, use encrypted credentials
|
15
|
-
# REDIS_URL: redis://x/y
|
16
|
-
|
17
|
-
registry:
|
18
|
-
# Specify the registry server, if you're not using Docker Hub
|
19
|
-
# server: registry.digitalocean.com / ghcr.io / ...
|
20
|
-
username: <%= Rails.application.credentials.registry["username"] %>
|
21
|
-
password: <%= Rails.application.credentials.registry["password"] %>
|
data/lib/tasks/mrsk/traefik.rake
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require_relative "setup"
|
2
|
-
|
3
|
-
traefik = Mrsk::Commands::Traefik.new(MRSK_CONFIG)
|
4
|
-
|
5
|
-
namespace :mrsk do
|
6
|
-
namespace :traefik do
|
7
|
-
desc "Run Traefik on servers"
|
8
|
-
task :run do
|
9
|
-
on(MRSK_CONFIG.role(:web).hosts) { execute *traefik.run, raise_on_non_zero_exit: false }
|
10
|
-
end
|
11
|
-
|
12
|
-
desc "Start existing Traefik on servers"
|
13
|
-
task :start do
|
14
|
-
on(MRSK_CONFIG.role(:web).hosts) { execute *traefik.start, raise_on_non_zero_exit: false }
|
15
|
-
end
|
16
|
-
|
17
|
-
desc "Stop Traefik on servers"
|
18
|
-
task :stop do
|
19
|
-
on(MRSK_CONFIG.role(:web).hosts) { execute *traefik.stop, raise_on_non_zero_exit: false }
|
20
|
-
end
|
21
|
-
|
22
|
-
desc "Restart Traefik on servers"
|
23
|
-
task restart: %i[ stop start ]
|
24
|
-
|
25
|
-
desc "Display information about Traefik containers from servers"
|
26
|
-
task :info do
|
27
|
-
on(MRSK_CONFIG.role(:web).hosts) { |host| puts "Traefik Host: #{host}\n" + capture(*traefik.info) + "\n\n" }
|
28
|
-
end
|
29
|
-
|
30
|
-
desc "Remove Traefik container and image from servers"
|
31
|
-
task remove: %i[ stop ] do
|
32
|
-
on(MRSK_CONFIG.role(:web).hosts) do
|
33
|
-
execute *traefik.remove_container
|
34
|
-
execute *traefik.remove_image
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|