pups 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +37 -4
- data/CHANGELOG +4 -0
- data/README.md +28 -0
- data/lib/pups/cli.rb +43 -19
- data/lib/pups/command.rb +4 -2
- data/lib/pups/config.rb +110 -37
- data/lib/pups/docker.rb +5 -8
- data/lib/pups/exec_command.rb +46 -31
- data/lib/pups/file_command.rb +5 -7
- data/lib/pups/merge_command.rb +17 -14
- data/lib/pups/replace_command.rb +8 -8
- data/lib/pups/runit.rb +2 -6
- data/lib/pups/version.rb +1 -1
- data/lib/pups.rb +12 -14
- data/test/cli_test.rb +63 -12
- data/test/config_test.rb +102 -32
- data/test/docker_test.rb +52 -16
- data/test/exec_command_test.rb +26 -33
- data/test/file_command_test.rb +8 -9
- data/test/merge_command_test.rb +18 -15
- data/test/replace_command_test.rb +30 -31
- data/test/test_helper.rb +4 -4
- metadata +6 -7
- data/.github/workflows/lint.yml +0 -27
data/lib/pups/merge_command.rb
CHANGED
@@ -9,10 +9,12 @@ module Pups
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.parse_command(command)
|
12
|
-
split = command.split(
|
13
|
-
|
12
|
+
split = command.split(" ")
|
13
|
+
unless split[-1][0] == "$"
|
14
|
+
raise ArgumentError, "Invalid merge command #{command}"
|
15
|
+
end
|
14
16
|
|
15
|
-
[split[0..-2].join(
|
17
|
+
[split[0..-2].join(" "), split[-1][1..-1]]
|
16
18
|
end
|
17
19
|
|
18
20
|
def initialize(command, params)
|
@@ -25,7 +27,7 @@ module Pups
|
|
25
27
|
|
26
28
|
def run
|
27
29
|
merged = self.class.deep_merge(YAML.load_file(@filename), @merge_hash)
|
28
|
-
File.open(@filename,
|
30
|
+
File.open(@filename, "w") { |f| f.write(merged.to_yaml) }
|
29
31
|
Pups.log.info("Merge: #{@filename} with: \n#{@merge_hash.inspect}")
|
30
32
|
end
|
31
33
|
|
@@ -33,17 +35,18 @@ module Pups
|
|
33
35
|
args ||= []
|
34
36
|
merge_arrays = args.include? :merge_arrays
|
35
37
|
|
36
|
-
merger =
|
37
|
-
|
38
|
-
v1.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
merger =
|
39
|
+
proc do |_key, v1, v2|
|
40
|
+
if v1.is_a?(Hash) && v2.is_a?(Hash)
|
41
|
+
v1.merge(v2, &merger)
|
42
|
+
elsif v1.is_a?(Array) && v2.is_a?(Array)
|
43
|
+
merge_arrays ? v1 + v2 : v2
|
44
|
+
elsif v2.is_a?(NilClass)
|
45
|
+
v1
|
46
|
+
else
|
47
|
+
v2
|
48
|
+
end
|
45
49
|
end
|
46
|
-
}
|
47
50
|
first.merge(second, &merger)
|
48
51
|
end
|
49
52
|
end
|
data/lib/pups/replace_command.rb
CHANGED
@@ -6,18 +6,18 @@ module Pups
|
|
6
6
|
|
7
7
|
def self.from_hash(hash, params)
|
8
8
|
replacer = new(params)
|
9
|
-
replacer.from = guess_replace_type(hash[
|
10
|
-
replacer.to = guess_replace_type(hash[
|
11
|
-
replacer.text = File.read(hash[
|
12
|
-
replacer.filename = hash[
|
13
|
-
replacer.direction = hash[
|
14
|
-
replacer.global = hash[
|
9
|
+
replacer.from = guess_replace_type(hash["from"])
|
10
|
+
replacer.to = guess_replace_type(hash["to"])
|
11
|
+
replacer.text = File.read(hash["filename"])
|
12
|
+
replacer.filename = hash["filename"]
|
13
|
+
replacer.direction = hash["direction"].to_sym if hash["direction"]
|
14
|
+
replacer.global = hash["global"].to_s == "true"
|
15
15
|
replacer
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.guess_replace_type(item)
|
19
19
|
# evaling to get all the regex flags easily
|
20
|
-
item[0] ==
|
20
|
+
item[0] == "/" ? eval(item) : item # rubocop:disable Security/Eval
|
21
21
|
end
|
22
22
|
|
23
23
|
def initialize(params)
|
@@ -39,7 +39,7 @@ module Pups
|
|
39
39
|
|
40
40
|
def run
|
41
41
|
Pups.log.info("Replacing #{from} with #{to} in #{filename}")
|
42
|
-
File.open(filename,
|
42
|
+
File.open(filename, "w") { |f| f.write replaced_text }
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/lib/pups/runit.rb
CHANGED
@@ -11,9 +11,7 @@ module Pups
|
|
11
11
|
def setup
|
12
12
|
`mkdir -p /etc/service/#{name}`
|
13
13
|
run = "/etc/service/#{name}/run"
|
14
|
-
File.open(run,
|
15
|
-
f.write(run_script)
|
16
|
-
end
|
14
|
+
File.open(run, "w") { |f| f.write(run_script) }
|
17
15
|
`chmod +x #{run}`
|
18
16
|
end
|
19
17
|
|
@@ -31,9 +29,7 @@ exec 2>&1
|
|
31
29
|
end
|
32
30
|
|
33
31
|
def env_script
|
34
|
-
@env&.map
|
35
|
-
"export #{k}=#{v}"
|
36
|
-
end&.join("\n")
|
32
|
+
@env&.map { |k, v| "export #{k}=#{v}" }&.join("\n")
|
37
33
|
end
|
38
34
|
end
|
39
35
|
end
|
data/lib/pups/version.rb
CHANGED
data/lib/pups.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "logger"
|
4
|
+
require "yaml"
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
6
|
+
require "pups/version"
|
7
|
+
require "pups/config"
|
8
|
+
require "pups/command"
|
9
|
+
require "pups/exec_command"
|
10
|
+
require "pups/merge_command"
|
11
|
+
require "pups/replace_command"
|
12
|
+
require "pups/file_command"
|
13
|
+
require "pups/docker"
|
14
|
+
require "pups/runit"
|
15
15
|
|
16
16
|
module Pups
|
17
17
|
class ExecError < RuntimeError
|
@@ -28,9 +28,7 @@ module Pups
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.silence
|
31
|
-
if @logger
|
32
|
-
@logger.close
|
33
|
-
end
|
31
|
+
@logger.close if @logger
|
34
32
|
|
35
33
|
@logger = Logger.new(File.open(File::NULL, "w"))
|
36
34
|
end
|
data/test/cli_test.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "test_helper"
|
4
|
+
require "tempfile"
|
5
|
+
require "stringio"
|
6
6
|
|
7
7
|
module Pups
|
8
|
-
class CliTest <
|
8
|
+
class CliTest < ::Minitest::Test
|
9
9
|
def test_cli_option_parsing_stdin
|
10
|
-
options = Cli.parse_args([
|
10
|
+
options = Cli.parse_args(["--stdin"])
|
11
11
|
assert_equal(true, options[:stdin])
|
12
12
|
end
|
13
13
|
|
@@ -18,11 +18,11 @@ module Pups
|
|
18
18
|
|
19
19
|
def test_cli_read_config_from_file
|
20
20
|
# for testing output
|
21
|
-
f = Tempfile.new(
|
21
|
+
f = Tempfile.new("test_output")
|
22
22
|
f.close
|
23
23
|
|
24
24
|
# for testing input
|
25
|
-
cf = Tempfile.new(
|
25
|
+
cf = Tempfile.new("test_config")
|
26
26
|
cf.puts <<~YAML
|
27
27
|
params:
|
28
28
|
run: #{f.path}
|
@@ -32,16 +32,16 @@ module Pups
|
|
32
32
|
cf.close
|
33
33
|
|
34
34
|
Cli.run([cf.path])
|
35
|
-
assert_equal(
|
35
|
+
assert_equal("hello world", File.read(f.path).strip)
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_cli_ignore_config_element
|
39
39
|
# for testing output
|
40
|
-
f = Tempfile.new(
|
40
|
+
f = Tempfile.new("test_output")
|
41
41
|
f.close
|
42
42
|
|
43
43
|
# for testing input
|
44
|
-
cf = Tempfile.new(
|
44
|
+
cf = Tempfile.new("test_config")
|
45
45
|
cf.puts <<~YAML
|
46
46
|
env:
|
47
47
|
MY_IGNORED_VAR: a_word
|
@@ -53,7 +53,7 @@ module Pups
|
|
53
53
|
cf.close
|
54
54
|
|
55
55
|
Cli.run(["--ignore", "env,params", cf.path])
|
56
|
-
assert_equal(
|
56
|
+
assert_equal("repeating and also", File.read(f.path).strip)
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_cli_gen_docker_run_args_ignores_other_config
|
@@ -111,7 +111,58 @@ module Pups
|
|
111
111
|
expected.sort!
|
112
112
|
|
113
113
|
assert_equal("", File.read(f.path).strip)
|
114
|
-
assert_output(expected.join(" "))
|
114
|
+
assert_output(expected.join(" ")) do
|
115
|
+
Cli.run(["--gen-docker-run-args", cf.path])
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_cli_tags
|
120
|
+
# for testing output
|
121
|
+
f = Tempfile.new("test_output")
|
122
|
+
f.close
|
123
|
+
|
124
|
+
# for testing input
|
125
|
+
cf = Tempfile.new("test_config")
|
126
|
+
cf.puts <<~YAML
|
127
|
+
run:
|
128
|
+
- exec:
|
129
|
+
tag: '1'
|
130
|
+
cmd: echo 1 >> #{f.path}
|
131
|
+
- exec:
|
132
|
+
tag: '2'
|
133
|
+
cmd: echo 2 >> #{f.path}
|
134
|
+
- exec:
|
135
|
+
tag: '3'
|
136
|
+
cmd: echo 3 >> #{f.path}
|
137
|
+
YAML
|
138
|
+
cf.close
|
139
|
+
|
140
|
+
Cli.run(["--tags", "1,3", cf.path])
|
141
|
+
assert_equal("1\n3", File.read(f.path).strip)
|
142
|
+
end
|
143
|
+
def test_cli_skip_tags
|
144
|
+
# for testing output
|
145
|
+
f = Tempfile.new("test_output")
|
146
|
+
f.close
|
147
|
+
|
148
|
+
# for testing input
|
149
|
+
cf = Tempfile.new("test_config")
|
150
|
+
cf.puts <<~YAML
|
151
|
+
run:
|
152
|
+
- exec:
|
153
|
+
tag: '1'
|
154
|
+
cmd: echo 1 >> #{f.path}
|
155
|
+
- exec:
|
156
|
+
tag: '2'
|
157
|
+
cmd: echo 2 >> #{f.path}
|
158
|
+
- exec:
|
159
|
+
tag: '3'
|
160
|
+
cmd: echo 3 >> #{f.path}
|
161
|
+
YAML
|
162
|
+
cf.close
|
163
|
+
|
164
|
+
Cli.run(["--skip-tags", "1,3", cf.path])
|
165
|
+
assert_equal("2", File.read(f.path).strip)
|
115
166
|
end
|
116
167
|
end
|
117
168
|
end
|
data/test/config_test.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "test_helper"
|
4
|
+
require "tempfile"
|
5
5
|
|
6
6
|
module Pups
|
7
|
-
class ConfigTest <
|
7
|
+
class ConfigTest < ::Minitest::Test
|
8
8
|
def test_config_from_env
|
9
|
-
ENV[
|
9
|
+
ENV["HELLO"] = "world"
|
10
10
|
config = Config.new({})
|
11
|
-
assert_equal(
|
11
|
+
assert_equal("world", config.params["$ENV_HELLO"])
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_env_param
|
15
|
-
ENV[
|
15
|
+
ENV["FOO"] = "BAR"
|
16
16
|
config = <<~YAML
|
17
17
|
env:
|
18
18
|
BAR: baz
|
@@ -22,14 +22,14 @@ module Pups
|
|
22
22
|
|
23
23
|
config = Config.new(YAML.safe_load(config))
|
24
24
|
%w[BAR hello one].each { |e| ENV.delete(e) }
|
25
|
-
assert_equal(
|
26
|
-
assert_equal(
|
27
|
-
assert_equal(
|
28
|
-
assert_equal(
|
25
|
+
assert_equal("BAR", config.params["$ENV_FOO"])
|
26
|
+
assert_equal("baz", config.params["$ENV_BAR"])
|
27
|
+
assert_equal("WORLD", config.params["$ENV_hello"])
|
28
|
+
assert_equal("1", config.params["$ENV_one"])
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_env_with_template
|
32
|
-
ENV[
|
32
|
+
ENV["FOO"] = "BAR"
|
33
33
|
config = <<~YAML
|
34
34
|
env:
|
35
35
|
greeting: "{{hello}}, {{planet}}!"
|
@@ -43,10 +43,10 @@ module Pups
|
|
43
43
|
|
44
44
|
config = Config.new(config_hash)
|
45
45
|
%w[greeting one other].each { |e| ENV.delete(e) }
|
46
|
-
assert_equal(
|
47
|
-
assert_equal(
|
48
|
-
assert_equal(
|
49
|
-
assert_equal(
|
46
|
+
assert_equal("hola, pluto!", config.params["$ENV_greeting"])
|
47
|
+
assert_equal("1", config.params["$ENV_one"])
|
48
|
+
assert_equal("BAR", config.params["$ENV_FOO"])
|
49
|
+
assert_equal("where are we on pluto?", config.params["$ENV_other"])
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_label_with_template
|
@@ -67,11 +67,11 @@ module Pups
|
|
67
67
|
|
68
68
|
config = Config.new(config_hash)
|
69
69
|
%w[greeting one other].each { |e| ENV.delete(e) }
|
70
|
-
assert_equal("various_discourse", config.config[
|
70
|
+
assert_equal("various_discourse", config.config["labels"]["app_name"])
|
71
71
|
end
|
72
72
|
|
73
73
|
def test_env_with_ENV_templated_variable
|
74
|
-
ENV[
|
74
|
+
ENV["env_template_config"] = "my_application"
|
75
75
|
config = <<~YAML
|
76
76
|
env:
|
77
77
|
greeting: "{{hello}}, {{planet}}!"
|
@@ -85,14 +85,14 @@ module Pups
|
|
85
85
|
|
86
86
|
config = Config.new(config_hash)
|
87
87
|
%w[greeting one other].each { |e| ENV.delete(e) }
|
88
|
-
assert_equal(
|
89
|
-
assert_equal(
|
90
|
-
assert_equal(
|
88
|
+
assert_equal("hola, pluto!", config.params["$ENV_greeting"])
|
89
|
+
assert_equal("1", config.params["$ENV_one"])
|
90
|
+
assert_equal("building my_application", config.params["$ENV_other"])
|
91
91
|
ENV["env_template_config"] = nil
|
92
92
|
end
|
93
93
|
|
94
94
|
def test_integration
|
95
|
-
f = Tempfile.new(
|
95
|
+
f = Tempfile.new("test")
|
96
96
|
f.close
|
97
97
|
|
98
98
|
config = <<~YAML
|
@@ -106,8 +106,8 @@ module Pups
|
|
106
106
|
YAML
|
107
107
|
|
108
108
|
Config.new(YAML.safe_load(config)).run
|
109
|
-
ENV.delete(
|
110
|
-
assert_equal(
|
109
|
+
ENV.delete("PLANET")
|
110
|
+
assert_equal("hello world", File.read(f.path).strip)
|
111
111
|
ensure
|
112
112
|
f.unlink
|
113
113
|
end
|
@@ -128,12 +128,12 @@ module Pups
|
|
128
128
|
YAML
|
129
129
|
|
130
130
|
config = Config.load_config(yaml).config
|
131
|
-
assert_equal({
|
132
|
-
assert_equal({
|
131
|
+
assert_equal({ "exec" => 1.9 }, config["run"][1])
|
132
|
+
assert_equal({ "exec" => 2.1 }, config["run"][3])
|
133
133
|
end
|
134
134
|
|
135
135
|
def test_ignored_elements
|
136
|
-
f = Tempfile.new(
|
136
|
+
f = Tempfile.new("test")
|
137
137
|
f.close
|
138
138
|
|
139
139
|
yaml = <<~YAML
|
@@ -157,15 +157,21 @@ module Pups
|
|
157
157
|
|
158
158
|
conf = Config.load_config(yaml, %w[hooks params])
|
159
159
|
config = conf.config
|
160
|
-
assert_equal({
|
161
|
-
assert_equal(
|
162
|
-
|
163
|
-
|
160
|
+
assert_equal({ "exec" => 1 }, config["run"][0])
|
161
|
+
assert_equal(
|
162
|
+
{ "exec" => { "hook" => "middle", "cmd" => 2 } },
|
163
|
+
config["run"][1]
|
164
|
+
)
|
165
|
+
assert_equal({ "exec" => 3 }, config["run"][2])
|
166
|
+
assert_equal(
|
167
|
+
{ "exec" => "echo $greeting $PLANET >> #{f.path}" },
|
168
|
+
config["run"][3]
|
169
|
+
)
|
164
170
|
|
165
171
|
# $greet from params will be an empty var as it was ignored
|
166
172
|
conf.run
|
167
|
-
ENV.delete(
|
168
|
-
assert_equal(
|
173
|
+
ENV.delete("PLANET")
|
174
|
+
assert_equal("world", File.read(f.path).strip)
|
169
175
|
end
|
170
176
|
|
171
177
|
def test_generate_docker_run_arguments
|
@@ -213,5 +219,69 @@ module Pups
|
|
213
219
|
|
214
220
|
assert_equal(expected.join(" "), args)
|
215
221
|
end
|
222
|
+
|
223
|
+
def test_tag_filtering
|
224
|
+
f = Tempfile.new("test")
|
225
|
+
f.close
|
226
|
+
|
227
|
+
yaml = <<~YAML
|
228
|
+
run:
|
229
|
+
- exec: 1
|
230
|
+
- exec:
|
231
|
+
hook: middle
|
232
|
+
cmd: 2
|
233
|
+
tag: one_tag
|
234
|
+
- exec:
|
235
|
+
cmd: 3
|
236
|
+
tag: two_tag
|
237
|
+
hooks:
|
238
|
+
after_middle:
|
239
|
+
- exec: 2.1
|
240
|
+
before_middle:
|
241
|
+
- exec: 1.9
|
242
|
+
YAML
|
243
|
+
|
244
|
+
# No tagging loads everything
|
245
|
+
conf = Config.load_config(yaml)
|
246
|
+
config = conf.config
|
247
|
+
assert_equal({ "exec" => 1 }, config["run"][0])
|
248
|
+
assert_equal({ "exec" => 1.9 }, config["run"][1])
|
249
|
+
assert_equal(
|
250
|
+
{ "exec" => { "hook" => "middle", "cmd" => 2, "tag" => "one_tag" } },
|
251
|
+
config["run"][2]
|
252
|
+
)
|
253
|
+
assert_equal({ "exec" => 2.1 }, config["run"][3])
|
254
|
+
assert_equal(
|
255
|
+
{ "exec" => { "cmd" => 3, "tag" => "two_tag" } },
|
256
|
+
config["run"][4]
|
257
|
+
)
|
258
|
+
|
259
|
+
# hooks get applied if hook command is not filtered
|
260
|
+
conf = Config.load_config(yaml, tags: ["one_tag"])
|
261
|
+
config = conf.config
|
262
|
+
assert_equal({ "exec" => 1.9 }, config["run"][0])
|
263
|
+
assert_equal(
|
264
|
+
{ "exec" => { "hook" => "middle", "cmd" => 2, "tag" => "one_tag" } },
|
265
|
+
config["run"][1]
|
266
|
+
)
|
267
|
+
assert_equal({ "exec" => 2.1 }, config["run"][2])
|
268
|
+
|
269
|
+
# hooks get filtered out if the main hook command is filtered
|
270
|
+
conf = Config.load_config(yaml, tags: ["two_tag"])
|
271
|
+
config = conf.config
|
272
|
+
assert_equal(
|
273
|
+
{ "exec" => { "cmd" => 3, "tag" => "two_tag" } },
|
274
|
+
config["run"][0]
|
275
|
+
)
|
276
|
+
|
277
|
+
# skip tags filter out commands with tags
|
278
|
+
conf = Config.load_config(yaml, skip_tags: ["one_tag"])
|
279
|
+
config = conf.config
|
280
|
+
assert_equal({ "exec" => 1 }, config["run"][0])
|
281
|
+
assert_equal(
|
282
|
+
{ "exec" => { "cmd" => 3, "tag" => "two_tag" } },
|
283
|
+
config["run"][1]
|
284
|
+
)
|
285
|
+
end
|
216
286
|
end
|
217
287
|
end
|
data/test/docker_test.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
2
|
+
require "test_helper"
|
3
|
+
require "tempfile"
|
4
|
+
require "shellwords"
|
5
5
|
|
6
6
|
module Pups
|
7
|
-
class DockerTest <
|
7
|
+
class DockerTest < ::Minitest::Test
|
8
8
|
def test_gen_env_arguments
|
9
9
|
yaml = <<~YAML
|
10
10
|
env:
|
@@ -16,7 +16,10 @@ module Pups
|
|
16
16
|
YAML
|
17
17
|
|
18
18
|
config = Config.load_config(yaml)
|
19
|
-
Config.transform_config_with_templated_vars(
|
19
|
+
Config.transform_config_with_templated_vars(
|
20
|
+
config.config["env_template"],
|
21
|
+
config.config["env"]
|
22
|
+
)
|
20
23
|
args = Docker.generate_env_arguments(config.config["env"])
|
21
24
|
assert_equal("--env foo=1 --env bar=2 --env baz=hello_eggs", args)
|
22
25
|
end
|
@@ -30,7 +33,10 @@ module Pups
|
|
30
33
|
YAML
|
31
34
|
|
32
35
|
config = Config.load_config(yaml)
|
33
|
-
Config.transform_config_with_templated_vars(
|
36
|
+
Config.transform_config_with_templated_vars(
|
37
|
+
config.config["env_template"],
|
38
|
+
config.config["env"]
|
39
|
+
)
|
34
40
|
args = Docker.generate_env_arguments(config.config["env"])
|
35
41
|
assert_equal("--env foo=1 --env bar=2", args)
|
36
42
|
end
|
@@ -44,9 +50,15 @@ module Pups
|
|
44
50
|
YAML
|
45
51
|
|
46
52
|
config = Config.load_config(yaml)
|
47
|
-
Config.transform_config_with_templated_vars(
|
53
|
+
Config.transform_config_with_templated_vars(
|
54
|
+
config.config["env_template"],
|
55
|
+
config.config["env"]
|
56
|
+
)
|
48
57
|
args = Docker.generate_env_arguments(config.config["env"])
|
49
|
-
assert_equal(
|
58
|
+
assert_equal(
|
59
|
+
"--env password=#{Shellwords.escape("eggs*`echo`@e$t| = >>$()&list;#")}",
|
60
|
+
args
|
61
|
+
)
|
50
62
|
end
|
51
63
|
|
52
64
|
def test_gen_env_arguments_quoted_with_a_space
|
@@ -56,7 +68,10 @@ module Pups
|
|
56
68
|
YAML
|
57
69
|
|
58
70
|
config = Config.load_config(yaml)
|
59
|
-
Config.transform_config_with_templated_vars(
|
71
|
+
Config.transform_config_with_templated_vars(
|
72
|
+
config.config["env_template"],
|
73
|
+
config.config["env"]
|
74
|
+
)
|
60
75
|
args = Docker.generate_env_arguments(config.config["env"])
|
61
76
|
assert_equal('--env a_variable=here\ is\ a\ sentence', args)
|
62
77
|
end
|
@@ -75,7 +90,10 @@ this password is
|
|
75
90
|
YAML
|
76
91
|
|
77
92
|
config = Config.load_config(yaml)
|
78
|
-
Config.transform_config_with_templated_vars(
|
93
|
+
Config.transform_config_with_templated_vars(
|
94
|
+
config.config["env_template"],
|
95
|
+
config.config["env"]
|
96
|
+
)
|
79
97
|
args = Docker.generate_env_arguments(config.config["env"])
|
80
98
|
assert_equal('--env password=this\ password\ is\ a\ weird\ one\ ', args)
|
81
99
|
end
|
@@ -90,7 +108,10 @@ this password is
|
|
90
108
|
|
91
109
|
config = Config.load_config(yaml)
|
92
110
|
args = Docker.generate_expose_arguments(config.config["expose"])
|
93
|
-
assert_equal(
|
111
|
+
assert_equal(
|
112
|
+
"--publish 2222:22 --publish 127.0.0.1:20080:80 --expose 5555",
|
113
|
+
args
|
114
|
+
)
|
94
115
|
end
|
95
116
|
|
96
117
|
def test_gen_volume_arguments
|
@@ -106,7 +127,10 @@ this password is
|
|
106
127
|
|
107
128
|
config = Config.load_config(yaml)
|
108
129
|
args = Docker.generate_volume_arguments(config.config["volumes"])
|
109
|
-
assert_equal(
|
130
|
+
assert_equal(
|
131
|
+
"--volume /var/discourse/shared:/shared --volume /bar:/baz",
|
132
|
+
args
|
133
|
+
)
|
110
134
|
end
|
111
135
|
|
112
136
|
def test_gen_link_arguments
|
@@ -135,9 +159,15 @@ this password is
|
|
135
159
|
YAML
|
136
160
|
|
137
161
|
config = Config.load_config(yaml)
|
138
|
-
Config.transform_config_with_templated_vars(
|
162
|
+
Config.transform_config_with_templated_vars(
|
163
|
+
config.config["env_template"],
|
164
|
+
config.config["labels"]
|
165
|
+
)
|
139
166
|
args = Docker.generate_label_arguments(config.config["labels"])
|
140
|
-
assert_equal(
|
167
|
+
assert_equal(
|
168
|
+
"--label monitor=true --label app_name=my_app_discourse",
|
169
|
+
args
|
170
|
+
)
|
141
171
|
end
|
142
172
|
|
143
173
|
def test_gen_label_arguments_escaped
|
@@ -149,9 +179,15 @@ this password is
|
|
149
179
|
YAML
|
150
180
|
|
151
181
|
config = Config.load_config(yaml)
|
152
|
-
Config.transform_config_with_templated_vars(
|
182
|
+
Config.transform_config_with_templated_vars(
|
183
|
+
config.config["env_template"],
|
184
|
+
config.config["labels"]
|
185
|
+
)
|
153
186
|
args = Docker.generate_label_arguments(config.config["labels"])
|
154
|
-
assert_equal(
|
187
|
+
assert_equal(
|
188
|
+
"--label app_name=#{Shellwords.escape("my_app's_di$course")}",
|
189
|
+
args
|
190
|
+
)
|
155
191
|
end
|
156
192
|
end
|
157
193
|
end
|