minio_runner 1.0.1 → 1.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/Gemfile.lock +1 -1
- data/lib/minio_runner/mc_manager.rb +52 -24
- data/lib/minio_runner/minio_health_check.rb +3 -1
- data/lib/minio_runner/minio_server_manager.rb +1 -1
- data/lib/minio_runner/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce06f5ad735c373c93d962a986aa801275ea6d176793dbe3aa68de4aae4bca9f
|
|
4
|
+
data.tar.gz: dec506832311083518a2a54e07a11e845bf8829ff3384456921652ecde0280ca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4385d8054248c2870106a0c27796642f2667bf134588ce773714769021d673e328ac2a9bf958de5494918f8036da03316a3c50dac4d8aac2e4ccf92e735b0f1c
|
|
7
|
+
data.tar.gz: a69728fe684c1abf2edd638f38d9bf202de77a9d1d4129523b84d80ea7c42257e8b67d83fff75fbb75b840e8f2e7618995850e87b0033938aab7809defe7ef61
|
data/Gemfile.lock
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "open3"
|
|
4
|
+
|
|
3
5
|
module MinioRunner
|
|
4
6
|
class McManager
|
|
7
|
+
CommandError = Class.new(StandardError)
|
|
8
|
+
|
|
9
|
+
DEFAULT_RETRIES = 5
|
|
10
|
+
RETRY_DELAY = 1
|
|
11
|
+
|
|
5
12
|
class << self
|
|
6
13
|
def command
|
|
7
14
|
["#{MinioRunner::McBinary.binary_file_path}"]
|
|
8
15
|
end
|
|
9
16
|
|
|
10
17
|
def bucket_exists?(alias_name, name)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
18
|
+
# `mc ls` exits non-zero when the bucket is missing, which is fine here.
|
|
19
|
+
_, _, status = run_mc(["ls", "#{alias_name}/#{name}"], allow_failure: true, retries: 0)
|
|
20
|
+
status.success?
|
|
15
21
|
end
|
|
16
22
|
|
|
17
23
|
def create_bucket(alias_name, name)
|
|
18
24
|
MinioRunner.logger.debug("Creating bucket #{alias_name}/#{name}...")
|
|
19
25
|
if !bucket_exists?(alias_name, name)
|
|
20
|
-
|
|
21
|
-
*command.concat(["mb", "#{alias_name}/#{name}"]),
|
|
22
|
-
out: MinioServerManager.log_file_path,
|
|
23
|
-
)
|
|
26
|
+
run_mc(["mb", "#{alias_name}/#{name}"])
|
|
24
27
|
MinioRunner.logger.debug("Created #{alias_name}/#{name}.")
|
|
25
28
|
else
|
|
26
29
|
MinioRunner.logger.debug("Bucket #{alias_name}/#{name} already exists, doing nothing.")
|
|
@@ -29,18 +32,15 @@ module MinioRunner
|
|
|
29
32
|
|
|
30
33
|
def set_alias(name, url)
|
|
31
34
|
MinioRunner.logger.debug("Setting alias #{name} to #{url}...")
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
],
|
|
42
|
-
),
|
|
43
|
-
out: MinioServerManager.log_file_path,
|
|
35
|
+
run_mc(
|
|
36
|
+
[
|
|
37
|
+
"alias",
|
|
38
|
+
"set",
|
|
39
|
+
name,
|
|
40
|
+
url,
|
|
41
|
+
MinioRunner.config.minio_root_user,
|
|
42
|
+
MinioRunner.config.minio_root_password,
|
|
43
|
+
],
|
|
44
44
|
)
|
|
45
45
|
MinioRunner.logger.debug("Set alias #{name} to #{url}.")
|
|
46
46
|
end
|
|
@@ -49,12 +49,40 @@ module MinioRunner
|
|
|
49
49
|
MinioRunner.logger.debug(
|
|
50
50
|
"Setting anonymous access for #{alias_name}/#{bucket} to policy #{policy}...",
|
|
51
51
|
)
|
|
52
|
-
|
|
53
|
-
*command.concat(["anonymous", "set", policy, "#{alias_name}/#{bucket}"]),
|
|
54
|
-
out: MinioServerManager.log_file_path,
|
|
55
|
-
)
|
|
52
|
+
run_mc(["anonymous", "set", policy, "#{alias_name}/#{bucket}"])
|
|
56
53
|
MinioRunner.logger.debug("Anonymous access set for #{alias_name}/#{bucket}.")
|
|
57
54
|
end
|
|
55
|
+
|
|
56
|
+
# Captures stdout/stderr to the minio log file, retries with backoff
|
|
57
|
+
# on non-zero exit codes (covers errors like "Server not initialized yet"
|
|
58
|
+
# and "connection refused" when minio is still starting) and raises
|
|
59
|
+
# `CommandError` on actual failures. (unless `allow_failure` is set)
|
|
60
|
+
def run_mc(args, allow_failure: false, retries: DEFAULT_RETRIES)
|
|
61
|
+
full_command = command + args
|
|
62
|
+
max_attempts = retries + 1
|
|
63
|
+
attempts = 0
|
|
64
|
+
stdout = stderr = status = nil
|
|
65
|
+
|
|
66
|
+
while attempts < max_attempts
|
|
67
|
+
stdout, stderr, status = Open3.capture3(*full_command)
|
|
68
|
+
File.open(MinioServerManager.log_file_path, "a") { |f| f.write(stdout, stderr) }
|
|
69
|
+
|
|
70
|
+
attempts += 1
|
|
71
|
+
break if status.success? || attempts == max_attempts
|
|
72
|
+
|
|
73
|
+
MinioRunner.logger.warn(
|
|
74
|
+
"mc #{args.join(" ")} failed (attempt #{attempts}/#{max_attempts}, " \
|
|
75
|
+
"exit #{status.exitstatus}); retrying in #{RETRY_DELAY}s: #{stderr.strip}",
|
|
76
|
+
)
|
|
77
|
+
sleep(RETRY_DELAY)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
return stdout, stderr, status if status.success? || allow_failure
|
|
81
|
+
|
|
82
|
+
raise CommandError,
|
|
83
|
+
"mc #{args.join(" ")} failed after #{attempts} attempts " \
|
|
84
|
+
"(exit #{status.exitstatus}): #{stderr.strip}"
|
|
85
|
+
end
|
|
58
86
|
end
|
|
59
87
|
end
|
|
60
88
|
end
|
|
@@ -8,8 +8,10 @@ module MinioRunner
|
|
|
8
8
|
# Also used to check whether /etc/hosts is configured properly; some platforms
|
|
9
9
|
# (read: macOS) have to be configured in a certain way to avoid this.
|
|
10
10
|
class MinioHealthCheck
|
|
11
|
+
DEFAULT_RETRIES = 10
|
|
12
|
+
|
|
11
13
|
class << self
|
|
12
|
-
def call(retries:
|
|
14
|
+
def call(retries: DEFAULT_RETRIES, initial_retries: nil)
|
|
13
15
|
initial_retries ||= retries
|
|
14
16
|
begin
|
|
15
17
|
Network.get("#{MinioRunner.config.minio_server_url}/minio/health/live")
|
|
@@ -48,7 +48,7 @@ module MinioRunner
|
|
|
48
48
|
@process.start
|
|
49
49
|
|
|
50
50
|
# Make sure the minio server is ready to accept requests.
|
|
51
|
-
MinioRunner::MinioHealthCheck.call
|
|
51
|
+
MinioRunner::MinioHealthCheck.call
|
|
52
52
|
|
|
53
53
|
MinioRunner.logger.debug("minio server running at pid #{@process.pid}!")
|
|
54
54
|
end
|
data/lib/minio_runner/version.rb
CHANGED