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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce1a05760ce2ec7932d48b99d21d94b8a4d9c7e88521b82aa36a1845bd934f96
4
- data.tar.gz: 2e0dc3f55ed0f9a78a93d00f5ad98648e61b32ab470966e9662d76f416ac5f89
3
+ metadata.gz: ce06f5ad735c373c93d962a986aa801275ea6d176793dbe3aa68de4aae4bca9f
4
+ data.tar.gz: dec506832311083518a2a54e07a11e845bf8829ff3384456921652ecde0280ca
5
5
  SHA512:
6
- metadata.gz: 0d778019e25efa46ec83b05f5ca63f59c52f9f5de005363a1feebc1765593fd21191f0ff6f80c767ec785d120e69bb9b0b3a0c7b9be6c56c0f287b1f51d1f1c1
7
- data.tar.gz: a6d5f557141f850dd40435aaf8f664f9361066a24552dd7809c994f2ca9fe9fa879add876f65e5de54b63048385f4d6b861a95b4930d0202882e2aa9812dd0ed
6
+ metadata.gz: 4385d8054248c2870106a0c27796642f2667bf134588ce773714769021d673e328ac2a9bf958de5494918f8036da03316a3c50dac4d8aac2e4ccf92e735b0f1c
7
+ data.tar.gz: a69728fe684c1abf2edd638f38d9bf202de77a9d1d4129523b84d80ea7c42257e8b67d83fff75fbb75b840e8f2e7618995850e87b0033938aab7809defe7ef61
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- minio_runner (1.0.1)
4
+ minio_runner (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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
- system(
12
- *command.concat(["ls", "#{alias_name}/#{name}"]),
13
- out: MinioServerManager.log_file_path,
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
- system(
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
- system(
33
- *command.concat(
34
- [
35
- "alias",
36
- "set",
37
- name,
38
- url,
39
- MinioRunner.config.minio_root_user,
40
- MinioRunner.config.minio_root_password,
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
- system(
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: 2, initial_retries: nil)
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(retries: 2)
51
+ MinioRunner::MinioHealthCheck.call
52
52
 
53
53
  MinioRunner.logger.debug("minio server running at pid #{@process.pid}!")
54
54
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MinioRunner
4
- VERSION = "1.0.1"
4
+ VERSION = "1.1.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minio_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Brennan