minio_runner 0.1.0 → 0.1.2
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 +13 -3
- data/lib/minio_runner/minio_health_check.rb +34 -0
- data/lib/minio_runner/minio_server_manager.rb +6 -19
- data/lib/minio_runner/network.rb +43 -4
- data/lib/minio_runner/version.rb +1 -1
- data/lib/minio_runner.rb +12 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05673a80f366bbb670c2ceb4cce28d3d8d27b7b25c4418482d15d6030b6a5fe1
|
4
|
+
data.tar.gz: 6ecaa3cefbd2962e8eaf7fb7262c479ca5e6383bbe2e711d9f459c9987d492e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9427c0521263fc9cf1ab467acc3af4aaf759802134b88a59f8105d0d14dd6a1c496d83b5a26744923666ec8a8688ececb62fc79670db63142450d2449cf6b141
|
7
|
+
data.tar.gz: ccc978d672db68a3b59b4feaa723581e8aa445fd4535770c2d6767c81a7255aac8ae6110b9af3e3a4f37c66854661b418eda627c732cd8aabd8dd679de757775
|
data/Gemfile.lock
CHANGED
@@ -8,13 +8,19 @@ module MinioRunner
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def bucket_exists?(alias_name, name)
|
11
|
-
system(
|
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(
|
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(
|
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
|
-
|
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
|
data/lib/minio_runner/network.rb
CHANGED
@@ -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
|
-
|
14
|
-
|
15
|
-
|
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
|
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
|
data/lib/minio_runner/version.rb
CHANGED
data/lib/minio_runner.rb
CHANGED
@@ -7,11 +7,14 @@ 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
|
|
13
14
|
module MinioRunner
|
14
15
|
class << self
|
16
|
+
@@started = false
|
17
|
+
|
15
18
|
def config(&block)
|
16
19
|
@config ||= MinioRunner::Config.new
|
17
20
|
if block_given?
|
@@ -38,12 +41,7 @@ module MinioRunner
|
|
38
41
|
original_formatter = logger.formatter || Logger::Formatter.new
|
39
42
|
logger.formatter =
|
40
43
|
proc do |severity, time, progname, msg|
|
41
|
-
original_formatter.call(
|
42
|
-
severity,
|
43
|
-
time,
|
44
|
-
progname,
|
45
|
-
"[MinioRunner]: #{msg.strip.dump}",
|
46
|
-
)
|
44
|
+
original_formatter.call(severity, time, progname, "[MinioRunner]: #{msg.strip}")
|
47
45
|
end
|
48
46
|
end
|
49
47
|
end
|
@@ -57,6 +55,12 @@ module MinioRunner
|
|
57
55
|
setup_buckets
|
58
56
|
|
59
57
|
logger.debug("Started minio_runner.")
|
58
|
+
|
59
|
+
@@started = true
|
60
|
+
end
|
61
|
+
|
62
|
+
def started?
|
63
|
+
@@started
|
60
64
|
end
|
61
65
|
|
62
66
|
def install_binaries
|
@@ -84,9 +88,11 @@ module MinioRunner
|
|
84
88
|
end
|
85
89
|
|
86
90
|
def stop
|
91
|
+
return if !started?
|
87
92
|
logger.debug("Stopping minio_runner...")
|
88
93
|
MinioRunner::MinioServerManager.stop
|
89
94
|
logger.debug("Stopped minio_runner.")
|
95
|
+
@@started = false
|
90
96
|
end
|
91
97
|
|
92
98
|
def reset_config!
|
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.
|
4
|
+
version: 0.1.2
|
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-
|
11
|
+
date: 2023-10-24 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
|