contained 0.3.0 → 0.5.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 +6 -8
- data/lib/contained/cli/init.rb +51 -23
- data/lib/contained/cli/setup.rb +46 -3
- data/lib/contained/cli.rb +1 -1
- data/lib/contained/command/base.rb +5 -2
- data/lib/contained/command/deploy.rb +5 -5
- data/lib/contained/command/setup.rb +34 -0
- data/lib/contained/version.rb +1 -1
- metadata +16 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 527971bc3fd7a83ceb0cffc2bf5b50ed59e49a3a5b43c4d7068f11194c36e554
|
|
4
|
+
data.tar.gz: 289aa2ca3ae5d3a9b121c186a12302b6a38cc5196fc3fd6c4bb8af94c143cb02
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bf6504165dc79786708c23074deb59f7007a233a43eaf3bbf8ae671ba6774b0e534691c5949a787a877a733460567430b5ba79cf741e3a12514ec9ed38e09566
|
|
7
|
+
data.tar.gz: d9b6657138f0d35a9538e3595ee3ef65648ea0a3da8dc61ed4720273a1059adc4169d9830374d4de01f1356bb3598d8e3607292e94febd7602830f37a26e0b13
|
data/README.md
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
stack: example
|
|
9
9
|
|
|
10
10
|
environments:
|
|
11
|
-
production:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- 4.3.2.1
|
|
18
|
-
- 8.7.6.5
|
|
11
|
+
production: hosts
|
|
12
|
+
- 1.2.3.4
|
|
13
|
+
- 5.6.7.8
|
|
14
|
+
test: hosts
|
|
15
|
+
- 4.3.2.1
|
|
16
|
+
- 8.7.6.5
|
|
19
17
|
|
|
20
18
|
config:
|
|
21
19
|
services:
|
data/lib/contained/cli/init.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "fileutils"
|
|
4
|
+
|
|
3
5
|
module Contained
|
|
4
6
|
class CLI
|
|
5
7
|
# @example
|
|
@@ -7,7 +9,20 @@ module Contained
|
|
|
7
9
|
class Init < Base
|
|
8
10
|
Arguments = Data.define(:image, :stack)
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
CONFIG_DEPLOY_COMPOSE_YML = <<~YAML
|
|
13
|
+
services:
|
|
14
|
+
app:
|
|
15
|
+
image: example/app
|
|
16
|
+
ports:
|
|
17
|
+
- "80:80"
|
|
18
|
+
healthcheck:
|
|
19
|
+
test: ["CMD", "curl", "-f", "http://localhost/up"]
|
|
20
|
+
interval: 30s
|
|
21
|
+
timeout: 10s
|
|
22
|
+
retries: 3
|
|
23
|
+
YAML
|
|
24
|
+
|
|
25
|
+
CONFIG_DEPLOY_YML = <<~YAML
|
|
11
26
|
stack: example
|
|
12
27
|
|
|
13
28
|
registry:
|
|
@@ -19,44 +34,53 @@ module Contained
|
|
|
19
34
|
|
|
20
35
|
environments:
|
|
21
36
|
production:
|
|
22
|
-
|
|
37
|
+
hosts
|
|
23
38
|
- 1.2.3.4
|
|
24
39
|
- 5.6.7.8
|
|
25
40
|
test:
|
|
26
|
-
|
|
41
|
+
hosts
|
|
27
42
|
- 4.3.2.1
|
|
28
43
|
- 8.7.6.5
|
|
29
|
-
|
|
30
|
-
config:
|
|
31
|
-
services:
|
|
32
|
-
app:
|
|
33
|
-
image: example/app
|
|
34
|
-
ports:
|
|
35
|
-
- "80:80"
|
|
36
|
-
healthcheck:
|
|
37
|
-
test: ["CMD", "curl", "-f", "http://localhost/up"]
|
|
38
|
-
interval: 30s
|
|
39
|
-
timeout: 10s
|
|
40
|
-
retries: 3
|
|
41
44
|
YAML
|
|
42
45
|
|
|
43
46
|
def handle!
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
arguments = arguments!
|
|
48
|
+
path = arguments.fetch(:path)
|
|
49
|
+
|
|
50
|
+
setup_config_dir(path:)
|
|
51
|
+
setup_config_deploy_yml(path:)
|
|
52
|
+
setup_config_deploy_compose_yml(path:)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def setup_config_dir(path:)
|
|
58
|
+
FileUtils.mkdir_p("#{path}/config/deploy")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def setup_config_deploy_yml(path:)
|
|
62
|
+
if File.exist?("#{path}/config/deploy.yml")
|
|
63
|
+
@stdout.puts("overwrite '#{path}/config/deploy.yml' (yes/no)?")
|
|
46
64
|
@stdin.gets { |response| return unless response.strip.eql?("yes") }
|
|
47
65
|
end
|
|
48
66
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
@stdout.puts("setup 'config/deploy.yml'")
|
|
67
|
+
File.write("#{path}/config/deploy.yml", CONFIG_DEPLOY_YML)
|
|
68
|
+
@stdout.puts("setup '#{path}/config/deploy.yml'")
|
|
53
69
|
end
|
|
54
70
|
|
|
55
|
-
|
|
71
|
+
def setup_config_deploy_compose_yml(path:)
|
|
72
|
+
if File.exist?("#{path}/config/deploy/compose.yml")
|
|
73
|
+
@stdout.puts("overwrite '#{path}/config/deploy/compose.yml' (yes/no)?")
|
|
74
|
+
@stdin.gets { |response| return unless response.strip.eql?("yes") }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
File.write("#{path}/config/deploy/compose.yml", CONFIG_DEPLOY_COMPOSE_YML)
|
|
78
|
+
@stdout.puts("setup '#{path}/config/deploy/compose.yml'")
|
|
79
|
+
end
|
|
56
80
|
|
|
57
81
|
# @return [Arguments]
|
|
58
82
|
def arguments!
|
|
59
|
-
|
|
83
|
+
{ path: "." }.tap do |arguments|
|
|
60
84
|
parser(into: arguments).parse!(@argv)
|
|
61
85
|
end
|
|
62
86
|
end
|
|
@@ -67,6 +91,10 @@ module Contained
|
|
|
67
91
|
OptionParser.new do |options|
|
|
68
92
|
options.banner = "usage: contained init [options]"
|
|
69
93
|
|
|
94
|
+
options.on("-p", "--path=PATH", "path") do |path|
|
|
95
|
+
into[:path] = path
|
|
96
|
+
end
|
|
97
|
+
|
|
70
98
|
options.on("-h", "--help", "help") do
|
|
71
99
|
@stdout.puts(options)
|
|
72
100
|
exit
|
data/lib/contained/cli/setup.rb
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Contained
|
|
4
|
+
class CLI
|
|
5
|
+
# @example
|
|
6
|
+
# Contained::CLI::Setup.handle!(stdout: $stdout, stderr: $stderr, argv: %i[--environment demo])
|
|
7
|
+
class Setup < Contained::CLI::Base
|
|
8
|
+
def handle!
|
|
9
|
+
arguments = arguments!
|
|
10
|
+
|
|
11
|
+
config = Contained::Config.load_file(path: arguments.fetch(:config))
|
|
12
|
+
environment = arguments.fetch(:environment)
|
|
13
|
+
|
|
14
|
+
Contained::Command::Setup.execute!(stdin: @stdin, stdout: @stdout, environment:, config:)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
# @return [Hash]
|
|
20
|
+
def arguments!
|
|
21
|
+
{ config: "./config/deploy.yml", environment: "default" }.tap do |arguments|
|
|
22
|
+
parser(into: arguments).parse!
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @param into [Hash]
|
|
27
|
+
# @return [OptionParser]
|
|
28
|
+
def parser(into:)
|
|
29
|
+
OptionParser.new do |options|
|
|
30
|
+
options.banner = "usage: contained setup [options] "
|
|
31
|
+
|
|
32
|
+
options.on("-h", "--help", "help") do
|
|
33
|
+
@stdout.puts(options)
|
|
34
|
+
exit
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
options.on("-c", "--config=CONFIG", "config") do |config|
|
|
38
|
+
into[:config] = config
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
options.on("-e", "--environment=ENVIRONMENT", "environment") do |environment|
|
|
42
|
+
into[:environment] = environment
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
4
47
|
end
|
|
5
48
|
end
|
data/lib/contained/cli.rb
CHANGED
|
@@ -29,8 +29,11 @@ module Contained
|
|
|
29
29
|
|
|
30
30
|
protected
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
# @return [Array<Hash>]
|
|
33
|
+
def hosts
|
|
34
|
+
@config.dig("environments", @environment, "hosts").map do |hostname|
|
|
35
|
+
@config.fetch("ssh", {}).merge({ hostname: })
|
|
36
|
+
end
|
|
34
37
|
end
|
|
35
38
|
end
|
|
36
39
|
end
|
|
@@ -12,12 +12,12 @@ module Contained
|
|
|
12
12
|
|
|
13
13
|
@stdout.puts("[deploying] stack=#{stack} environment=#{@environment}")
|
|
14
14
|
|
|
15
|
-
on
|
|
15
|
+
on hosts, in: :sequence do |host|
|
|
16
16
|
puts("[starting] host=#{host.hostname}")
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
execute(<<~BASH)
|
|
18
|
+
source ./.contained/#{stack}/.env
|
|
19
|
+
docker stack deploy -c ./.contained/#{stack}/compose.yml #{stack} --with-registry-auth
|
|
20
|
+
BASH
|
|
21
21
|
puts("[done] host=#{host.hostname}")
|
|
22
22
|
end
|
|
23
23
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Contained
|
|
4
|
+
module Command
|
|
5
|
+
# @example
|
|
6
|
+
# Contained::Command::Setup.execute(environment: "production", config: {})
|
|
7
|
+
class Setup < Base
|
|
8
|
+
def execute!
|
|
9
|
+
stack = @config.fetch("stack")
|
|
10
|
+
|
|
11
|
+
deploy_compose_yml = File.open("./config/deploy/compose.yml")
|
|
12
|
+
deploy_env = File.open("./config/deploy/.#{@environment}.env")
|
|
13
|
+
|
|
14
|
+
@stdout.puts("[setup] stack=#{stack} environment=#{@environment} hosts=#{hosts}")
|
|
15
|
+
|
|
16
|
+
on hosts, in: :sequence do |host|
|
|
17
|
+
puts("[starting] host=#{host.hostname}")
|
|
18
|
+
|
|
19
|
+
execute("mkdir -p ./.contained/#{stack}")
|
|
20
|
+
|
|
21
|
+
upload!(deploy_compose_yml, "./.contained/#{stack}/compose.yml")
|
|
22
|
+
upload!(deploy_env, "./.contained/#{stack}/.env")
|
|
23
|
+
|
|
24
|
+
execute(<<~BASH)
|
|
25
|
+
source ./.contained/#{stack}/.env
|
|
26
|
+
docker stack deploy -c ./.contained/#{stack}/compose.yml #{stack} --with-registry-auth
|
|
27
|
+
BASH
|
|
28
|
+
|
|
29
|
+
puts("[done] host=#{host.hostname}")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/contained/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: contained
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kevin Sylvestre
|
|
@@ -23,6 +23,20 @@ dependencies:
|
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: fileutils
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
26
40
|
- !ruby/object:Gem::Dependency
|
|
27
41
|
name: optparse
|
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -102,6 +116,7 @@ files:
|
|
|
102
116
|
- lib/contained/command/base.rb
|
|
103
117
|
- lib/contained/command/deploy.rb
|
|
104
118
|
- lib/contained/command/login.rb
|
|
119
|
+
- lib/contained/command/setup.rb
|
|
105
120
|
- lib/contained/config.rb
|
|
106
121
|
- lib/contained/config/registry.rb
|
|
107
122
|
- lib/contained/version.rb
|