contained 0.3.0 → 0.4.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/lib/contained/cli/init.rb +49 -21
- data/lib/contained/cli/setup.rb +46 -3
- data/lib/contained/cli.rb +1 -1
- data/lib/contained/command/deploy.rb +4 -4
- 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: b0cb59a30f87b9f812ea82750eaf3ec2aa709646117f2bd3cd267b74a0a93f4b
|
4
|
+
data.tar.gz: 3f0de08deaa75360d26125eaf1c3e82a1c068a2357eb93d69f9bb15ebe9b7ac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20db27de1725d9aceffaa923e919315b12beb3f1ec7bedc969af903da579f491fd087ce90fa4c86edbf40a88f4898537f9b3419649159a2c3a17ab739edcc6b5
|
7
|
+
data.tar.gz: 3781c551e71dd8ae8e0fd81bf38d07c9e75b64d1f08eb8371359a409575c86636383fc0ec7428f1fe6fb29a41079fb315ff0aee050e5ca71acb1d593dfa561c6
|
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:
|
@@ -26,37 +41,46 @@ module Contained
|
|
26
41
|
servers:
|
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
@@ -14,10 +14,10 @@ module Contained
|
|
14
14
|
|
15
15
|
on servers, 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} servers=#{servers}")
|
15
|
+
|
16
|
+
on servers, 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.4.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
|