minio_runner 0.1.0 → 0.1.1

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: fee26785f28262a4b0f39f5020886edcddd996ca6040e5b1e952a9583199aa36
4
- data.tar.gz: 19ba0e2e0a070b3caf5fbfc1ba04e4a5cca9a285e80b224626e112cbd45c0202
3
+ metadata.gz: 0e893ea1ceae7fd460257c29482f2e3f19b14fa62a16c37b219dba34532ec0eb
4
+ data.tar.gz: 53cbd2ac3e18e3a4812e693d28f2a1d5bf6701c9ab13ee368bdd1a5ca0b43cba
5
5
  SHA512:
6
- metadata.gz: 57fc047cd89912f6ad31b2fc5c349d74182c44fdc9bf6ef2e5cc5beb613eff56d99ff04914761047c0deb944bb433e581e8f0017000fdc8309a0a3af1628f1bd
7
- data.tar.gz: 5a16f8c6d73deec031690b3bdb21d602d6e162ab22a8b56f4ab6abd874bfe0aa039bb4c31a1de79245c0116cabc7118d58ded7d9b499f1f8b018beabdd633aeb
6
+ metadata.gz: 34e6ccaba17c9b6b5e9852068b3eca0ceef4bd57d294b54ebfd0756a688306fbee89f7617f832dce0f464c81a6689b81b03c07c74e30ca42e08175bcbefeceb2
7
+ data.tar.gz: 91f8e7ec4ec0cd9cdc97b8d224074fbd0cf79c1b71a02a27d398ebe4fae2f76a4af06dcb071af15c0b4199ce32fd77ce5d413667d26eae83aba7f5be8b313dc6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- minio_runner (0.1.0)
4
+ minio_runner (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -8,13 +8,19 @@ module MinioRunner
8
8
  end
9
9
 
10
10
  def bucket_exists?(alias_name, name)
11
- system(*command.concat(["ls", "#{alias_name}/#{name}"]))
11
+ system(
12
+ *command.concat(["ls", "#{alias_name}/#{name}"]),
13
+ out: MinioServerManager.log_file_path,
14
+ )
12
15
  end
13
16
 
14
17
  def create_bucket(alias_name, name)
15
18
  MinioRunner.logger.debug("Creating bucket #{alias_name}/#{name}...")
16
19
  if !bucket_exists?(alias_name, name)
17
- system(*command.concat(["mb", "#{alias_name}/#{name}"]))
20
+ system(
21
+ *command.concat(["mb", "#{alias_name}/#{name}"]),
22
+ out: MinioServerManager.log_file_path,
23
+ )
18
24
  MinioRunner.logger.debug("Created #{alias_name}/#{name}.")
19
25
  else
20
26
  MinioRunner.logger.debug("Bucket #{alias_name}/#{name} already exists, doing nothing.")
@@ -34,6 +40,7 @@ module MinioRunner
34
40
  MinioRunner.config.minio_root_password,
35
41
  ],
36
42
  ),
43
+ out: MinioServerManager.log_file_path,
37
44
  )
38
45
  MinioRunner.logger.debug("Set alias #{name} to #{url}.")
39
46
  end
@@ -42,7 +49,10 @@ module MinioRunner
42
49
  MinioRunner.logger.debug(
43
50
  "Setting anonymous access for #{alias_name}/#{bucket} to policy #{policy}...",
44
51
  )
45
- system(*command.concat(["anonymous", "set", policy, "#{alias_name}/#{bucket}"]))
52
+ system(
53
+ *command.concat(["anonymous", "set", policy, "#{alias_name}/#{bucket}"]),
54
+ out: MinioServerManager.log_file_path,
55
+ )
46
56
  MinioRunner.logger.debug("Anonymous access set for #{alias_name}/#{bucket}.")
47
57
  end
48
58
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MinioRunner
4
+ ##
5
+ # Checks that the minio server is running on the configured port using
6
+ # the /minio/health/live endpoint with a limited number of retries.
7
+ #
8
+ # Also used to check whether /etc/hosts is configured properly; some platforms
9
+ # (read: macOS) have to be configured in a certain way to avoid this.
10
+ class MinioHealthCheck
11
+ class << self
12
+ def call(retries: 2, initial_retries: nil)
13
+ initial_retries ||= retries
14
+ begin
15
+ Network.get("#{MinioRunner.config.minio_server_url}/minio/health/live")
16
+ rescue StandardError, MinioRunner::Network::NetworkError
17
+ if retries.positive?
18
+ sleep 1
19
+ call(retries: retries - 1, initial_retries: initial_retries)
20
+ else
21
+ message =
22
+ "Minio server failed to start after #{initial_retries + 1} attempts. Check that /etc/hosts is configured properly."
23
+
24
+ if MinioRunner::System.mac? && MinioRunner.config.minio_domain.end_with?(".local")
25
+ message += "\n\n" + MinioRunner::Network::MAC_OS_LOCAL_DOMAIN_ERROR_MESSAGE
26
+ end
27
+
28
+ raise MinioRunner::Network::NetworkError.new(message)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -18,6 +18,10 @@ module MinioRunner
18
18
  return if @server.nil?
19
19
  @server.stop
20
20
  end
21
+
22
+ def log_file_path
23
+ "#{MinioRunner.config.install_dir}/minio.log"
24
+ end
21
25
  end
22
26
 
23
27
  def start
@@ -38,13 +42,13 @@ module MinioRunner
38
42
  "MINIO_ROOT_PASSWORD" => MinioRunner.config.minio_root_password,
39
43
  "MINIO_DOMAIN" => MinioRunner.config.minio_domain,
40
44
  },
41
- log_file: log_file_path,
45
+ log_file: MinioServerManager.log_file_path,
42
46
  )
43
47
 
44
48
  @process.start
45
49
 
46
50
  # Make sure the minio server is ready to accept requests.
47
- health_check(retries: 3)
51
+ MinioRunner::MinioHealthCheck.call(retries: 2)
48
52
 
49
53
  MinioRunner.logger.debug("minio server running at pid #{@process.pid}!")
50
54
  end
@@ -80,22 +84,5 @@ module MinioRunner
80
84
 
81
85
  command
82
86
  end
83
-
84
- def log_file_path
85
- "#{MinioRunner.config.install_dir}/minio.log"
86
- end
87
-
88
- def health_check(retries:)
89
- begin
90
- Network.get("#{MinioRunner.config.minio_server_url}/minio/health/live")
91
- rescue StandardError
92
- if retries.positive?
93
- sleep 1
94
- health_check(retries: retries - 1)
95
- else
96
- raise "Minio server failed to start."
97
- end
98
- end
99
- end
100
87
  end
101
88
  end
@@ -5,23 +5,55 @@ require "tempfile"
5
5
 
6
6
  module MinioRunner
7
7
  class Network
8
+ class NetworkError < StandardError
9
+ end
10
+
11
+ LONG_RESPONSE_TIME_SECONDS = 3
12
+ MAC_OS_LOCAL_DOMAIN_ERROR_MESSAGE = <<~END
13
+ For macOS, there are some issues which cause large delays for .local domain names. See
14
+ https://superuser.com/a/1297335/245469 and https://stackoverflow.com/a/17982964/875941. To
15
+ resolve this, you need to add IPV6 lookup addresses to the hosts file, and it helps to put
16
+ all the entries on one line.
17
+
18
+ ::1 minio.local testbucket.minio.local
19
+ fe80::1%lo0 minio.local testbucket.minio.local
20
+ 127.0.0.1 minio.local testbucket.minio.local
21
+ END
22
+
8
23
  class << self
9
24
  def get(url)
10
25
  MinioRunner.logger.debug("Making network call to #{url}")
26
+ uri = URI(url)
27
+ response = nil
28
+ request_start_time = Time.now
11
29
 
12
30
  begin
13
- response = Net::HTTP.get_response(URI(url))
14
- rescue SocketError
15
- raise "Can not reach #{url}"
31
+ Net::HTTP.start(
32
+ uri.host,
33
+ uri.port,
34
+ use_ssl: uri.scheme == "https",
35
+ open_timeout: MinioRunner::System.mac? ? 10 : 3,
36
+ ) { |http| response = http.get(uri.path) }
37
+ rescue SocketError, Net::OpenTimeout => err
38
+ MinioRunner.logger.debug(
39
+ "Connection error when checking minio server health: #{err.message}",
40
+ )
41
+ log_time_error(request_start_time)
42
+ raise MinioRunner::Network::NetworkError.new(
43
+ "Connection error, cannot reach URL: #{url} (#{err.class})",
44
+ )
16
45
  end
17
46
 
18
47
  MinioRunner.logger.debug("Get response: #{response.inspect}")
19
48
 
20
49
  case response
21
50
  when Net::HTTPSuccess
51
+ log_time_error(request_start_time)
22
52
  response.body
23
53
  else
24
- raise "#{response.class::EXCEPTION_TYPE}: #{response.code} \"#{response.message}\" with #{url}"
54
+ raise MinioRunner::Network::NetworkError.new(
55
+ "#{response.class::EXCEPTION_TYPE}: #{response.code} \"#{response.message}\" with #{url}",
56
+ )
25
57
  end
26
58
  end
27
59
 
@@ -41,6 +73,13 @@ module MinioRunner
41
73
  ensure
42
74
  tempfile&.close!
43
75
  end
76
+
77
+ def log_time_error(request_start_time)
78
+ if (Time.now - request_start_time) > Network::LONG_RESPONSE_TIME_SECONDS &&
79
+ MinioRunner.config.minio_domain.end_with?(".local") && MinioRunner::System.mac?
80
+ MinioRunner.logger.warn(MAC_OS_LOCAL_DOMAIN_ERROR_MESSAGE)
81
+ end
82
+ end
44
83
  end
45
84
  end
46
85
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MinioRunner
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/minio_runner.rb CHANGED
@@ -7,6 +7,7 @@ require_relative "minio_runner/config"
7
7
  require_relative "minio_runner/minio_binary"
8
8
  require_relative "minio_runner/mc_binary"
9
9
  require_relative "minio_runner/binary_manager"
10
+ require_relative "minio_runner/minio_health_check"
10
11
  require_relative "minio_runner/minio_server_manager"
11
12
  require_relative "minio_runner/mc_manager"
12
13
 
@@ -38,12 +39,7 @@ module MinioRunner
38
39
  original_formatter = logger.formatter || Logger::Formatter.new
39
40
  logger.formatter =
40
41
  proc do |severity, time, progname, msg|
41
- original_formatter.call(
42
- severity,
43
- time,
44
- progname,
45
- "[MinioRunner]: #{msg.strip.dump}",
46
- )
42
+ original_formatter.call(severity, time, progname, "[MinioRunner]: #{msg.strip}")
47
43
  end
48
44
  end
49
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minio_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Brennan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-15 00:00:00.000000000 Z
11
+ date: 2023-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: syntax_tree
@@ -156,6 +156,7 @@ files:
156
156
  - lib/minio_runner/mc_binary.rb
157
157
  - lib/minio_runner/mc_manager.rb
158
158
  - lib/minio_runner/minio_binary.rb
159
+ - lib/minio_runner/minio_health_check.rb
159
160
  - lib/minio_runner/minio_server_manager.rb
160
161
  - lib/minio_runner/network.rb
161
162
  - lib/minio_runner/system.rb