dry-stack 0.0.67 → 0.0.68
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/stack.drs +7 -0
- data/lib/dry-stack/command_compose.rb +2 -1
- data/lib/dry-stack/command_line.rb +9 -1
- data/lib/dry-stack/command_swarm_deploy.rb +29 -3
- data/lib/dry-stack/stack.rb +22 -4
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 146c4a166dd6b6136a2b3f9c4068bcdf01fa38f64665148523bb7e4192d91cc7
|
4
|
+
data.tar.gz: 27e180472c79e5b351d51086c5595b8d5326d67bf18b0b1661d849ab9315be0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74afa47a72fe82c508baedd4feaf3e8280f6890c540161f1fc87a3a2787d0330f6d3d05e8bc37ad5152a16243d485d477488969c37119b140cdfa6bb3a9c98a5
|
7
|
+
data.tar.gz: cb99fb3f874fbd03c04b9c8cef3a28ca660f60c65304e0c2977485a85f6af140a700a12d7430de0f10400aaa54dbbade3c1fa0dbd6460976328f56bf5c034da7
|
data/bin/stack.drs
CHANGED
@@ -2,6 +2,13 @@ Description <<~DSC
|
|
2
2
|
|
3
3
|
DSC
|
4
4
|
|
5
|
+
Options name: 'stack_name'
|
6
|
+
SwarmDeploy :sky_gates do
|
7
|
+
context_host 'ssh://root@10.0.0.1'
|
8
|
+
stack_name 'remote_stack'
|
9
|
+
env REGISTRY_HOST: '10.100.0.2:5000'
|
10
|
+
end
|
11
|
+
|
5
12
|
PublishPorts admin: 4000, operator: 4001, navigator: 4002, reports: 7000 # mode: ingress, protocol: tcp
|
6
13
|
|
7
14
|
Service :admin, image: 'frontend', env: {APP: 'admin'}, ports: 5000
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require_relative 'command_line'
|
2
2
|
|
3
3
|
Dry::CommandLine::COMMANDS[:to_compose] = Class.new do
|
4
|
-
def run(stack, params)
|
4
|
+
def run(stack, params, args)
|
5
|
+
raise "unsupported args: #{args}" unless args.empty?
|
5
6
|
_params = stack.options.merge params
|
6
7
|
stack.name = _params[:name] if _params[:name]
|
7
8
|
yaml = stack.to_compose(_params).lines[1..].join
|
@@ -14,6 +14,14 @@ def exec_i(cmd, input_string = nil)
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
def exec_o_lines(cmd,&)
|
18
|
+
IO.popen(cmd, 'r') do |f|
|
19
|
+
f.each_line do |line|
|
20
|
+
yield line
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
17
25
|
module Dry
|
18
26
|
module CommandLine
|
19
27
|
COMMANDS = {}
|
@@ -74,7 +82,7 @@ module Dry
|
|
74
82
|
safe_eval stack_text # isolate context
|
75
83
|
|
76
84
|
Stack.last_stack.name = params[:name] if params[:name]
|
77
|
-
COMMANDS[command.to_sym].run Stack.last_stack, params
|
85
|
+
COMMANDS[command.to_sym].run Stack.last_stack, params, args
|
78
86
|
rescue => e
|
79
87
|
puts e.message
|
80
88
|
ENV['DEBUG'] ? raise : exit(1)
|
@@ -1,12 +1,38 @@
|
|
1
1
|
require_relative 'command_line'
|
2
2
|
|
3
3
|
Dry::CommandLine::COMMANDS[:swarm_deploy] = Class.new do
|
4
|
-
def run(stack, params)
|
4
|
+
def run(stack, params, args)
|
5
|
+
unless args.empty?
|
6
|
+
raise "deploy config not found: #{args[0]}" unless stack.swarm_deploy.key? args[0].to_sym
|
7
|
+
context = stack.swarm_deploy[args[0].to_sym]
|
8
|
+
end
|
5
9
|
_params = stack.options.merge params
|
6
10
|
stack.name = _params[:name] if _params[:name]
|
7
|
-
|
11
|
+
|
12
|
+
if context
|
13
|
+
name = context[:context_name]&.to_sym || args[0].to_sym
|
14
|
+
host = context[:context_host]
|
15
|
+
contexts = {}
|
16
|
+
exec_o_lines "docker context ls --format json" do |line|
|
17
|
+
ctx = JSON.parse line, symbolize_names: true
|
18
|
+
contexts[ctx[:Name].to_sym] = ctx # {"Current":false,"Description":"","DockerEndpoint":"ssh://root@x.x.x.x","Error":"","Name":"prod-swarm"}
|
19
|
+
end
|
20
|
+
|
21
|
+
if contexts[name] && contexts[name][:DockerEndpoint] != host
|
22
|
+
raise "context '#{name}' has different host value: #{contexts[name][:DockerEndpoint]} != #{host}"
|
23
|
+
end
|
24
|
+
|
25
|
+
exec_i "docker context create #{name} --docker host=#{host}" unless contexts[name]
|
26
|
+
|
27
|
+
ENV['DOCKER_CONTEXT'] = name.to_s
|
28
|
+
stack.name = context[:stack_name] || stack.name
|
29
|
+
context[:stack_name][:environment].each do |k,v|
|
30
|
+
ENV[k.to_s] = v.to_s
|
31
|
+
end
|
32
|
+
end
|
8
33
|
|
9
34
|
# substitute ENV variables
|
35
|
+
yaml = stack.to_compose(_params).lines[1..].join
|
10
36
|
yaml = _params[:'no-env'] ? yaml : `echo \"#{yaml.gsub("`", '\\\`')}\"`
|
11
37
|
system " echo \"#{yaml.gsub("`", '\\\`')}\"" if _params[:v]
|
12
38
|
# system " echo \"#{yaml.gsub("`", '\\\`')}\" | docker stack deploy -c - #{stack.name} --prune --resolve-image changed"
|
@@ -14,7 +40,7 @@ Dry::CommandLine::COMMANDS[:swarm_deploy] = Class.new do
|
|
14
40
|
exec_i "docker stack deploy -c - #{stack.name} --prune --resolve-image changed", yaml
|
15
41
|
system "docker config rm $(docker config ls --filter label=com.docker.stack.namespace=#{stack.name} --format \"{{.ID}}\")"
|
16
42
|
|
17
|
-
exec_i "docker config rm #{stack.name}_readme || echo 'failed to remove config#{stack.name}_readme'"
|
43
|
+
exec_i "docker config rm #{stack.name}_readme || echo 'failed to remove config #{stack.name}_readme'"
|
18
44
|
puts "stack description: #{stack.description}"
|
19
45
|
exec_i "docker config create #{stack.name}_readme -", stack.description
|
20
46
|
end
|
data/lib/dry-stack/stack.rb
CHANGED
@@ -42,12 +42,20 @@ module Dry
|
|
42
42
|
def network(names) = (@service[:networks] ||= []) << names
|
43
43
|
end
|
44
44
|
|
45
|
+
class SwarmFunction
|
46
|
+
def initialize(swarm, &); @swarm = swarm; instance_exec(&) end
|
47
|
+
def env(variables)= @swarm[:environment].merge! variables
|
48
|
+
def context_host(host)= @swarm[:context_host] = host
|
49
|
+
def context_name(name)= @swarm[:context_name] = name
|
50
|
+
def stack_name(name)= @swarm[:stack_name] = name
|
51
|
+
end
|
52
|
+
|
45
53
|
class Stack
|
46
54
|
COMPOSE_VERSION = '3.8'
|
47
55
|
class << self
|
48
56
|
attr_accessor :last_stack
|
49
57
|
end
|
50
|
-
attr_accessor :name, :options, :description
|
58
|
+
attr_accessor :name, :options, :description, :swarm_deploy
|
51
59
|
|
52
60
|
def Stack(name = nil, &)
|
53
61
|
Stack.last_stack = Stack.new name
|
@@ -69,6 +77,7 @@ module Dry
|
|
69
77
|
@labels = {}
|
70
78
|
@configs = {}
|
71
79
|
@logging = {}
|
80
|
+
@swarm_deploy = {}
|
72
81
|
end
|
73
82
|
|
74
83
|
def expand_hash(hash)
|
@@ -235,9 +244,9 @@ module Dry
|
|
235
244
|
opts[:ports] = [opts[:ports]].flatten if opts.key? :ports
|
236
245
|
opts[:environment] = opts.delete(:env) if opts.key? :env
|
237
246
|
|
238
|
-
@services[name] ||= {environment: {}, deploy: {labels: []}}
|
239
|
-
|
240
|
-
ServiceFunction.new(
|
247
|
+
service = @services[name.to_sym] ||= {environment: {}, deploy: {labels: []}}
|
248
|
+
service.merge! opts
|
249
|
+
ServiceFunction.new(service, &) if block_given?
|
241
250
|
end
|
242
251
|
|
243
252
|
def Description(string)
|
@@ -299,6 +308,15 @@ module Dry
|
|
299
308
|
@volumes[name].merge! opts
|
300
309
|
yield if block_given?
|
301
310
|
end
|
311
|
+
|
312
|
+
def SwarmDeploy(name, opts = {}, &)
|
313
|
+
opts[:environment] = opts.delete(:env) if opts.key? :env
|
314
|
+
|
315
|
+
swarm = @swarm_deploy[name.to_sym] ||= { environment: {} }
|
316
|
+
swarm.merge! opts
|
317
|
+
SwarmFunction.new(swarm, &) if block_given?
|
318
|
+
end
|
319
|
+
|
302
320
|
end
|
303
321
|
end
|
304
322
|
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-stack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.68
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artyom B
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|