on_container 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 047f95a8b1aa08140e835430767a983ba4f70e98
|
4
|
+
data.tar.gz: 93bee7ffc095b037ebd8abf97ee87ee207643bdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 416751bf09182242b57efad9b7c6224c137cb7e4ca065e69fd614836a1e0f90eef88f9df869484d175d120d232b7cdc332e3f32e54f9b76a16325b2a66f5d86e
|
7
|
+
data.tar.gz: e556def5df06b70d854db1317b6471af52460d7535aa678e836dcda4695ec8028cbb9e884dec104369fe260d3d3fb68179f25ab07a459d6ebd3e45cf958aeb8f
|
@@ -12,4 +12,8 @@ include OnContainer::Dev::SetupOps
|
|
12
12
|
include OnContainer::Dev::BundlerOps
|
13
13
|
include OnContainer::Dev::NodeModulesOps
|
14
14
|
include OnContainer::Dev::ActiveRecordOps
|
15
|
-
include OnContainer::Dev::ContainerCommandOps
|
15
|
+
include OnContainer::Dev::ContainerCommandOps
|
16
|
+
|
17
|
+
require 'on_container/ops/service_connection_checks'
|
18
|
+
|
19
|
+
include OnContainer::Ops::ServiceConnectionChecks
|
@@ -21,12 +21,19 @@ module OnContainer
|
|
21
21
|
puts 'Waiting for app setup to finish...'
|
22
22
|
sleep app_setup_wait
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def on_setup_lock_acquired
|
26
26
|
wait_setup while File.exist?(app_setup_lock_path)
|
27
|
-
|
27
|
+
|
28
28
|
lock_setup
|
29
|
+
|
30
|
+
%w[HUP INT QUIT TERM EXIT].each do |signal_string|
|
31
|
+
Signal.trap(signal_string) { unlock_setup }
|
32
|
+
end
|
33
|
+
|
29
34
|
yield
|
35
|
+
|
36
|
+
ensure
|
30
37
|
unlock_setup
|
31
38
|
end
|
32
39
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Reads the specified secret paths (i.e. Docker Secrets) into environment
|
4
|
+
# variables:
|
5
|
+
|
6
|
+
require 'active_support'
|
7
|
+
require 'active_support/core_ext/object'
|
8
|
+
|
9
|
+
# Process only a known list of env vars that can filled by reading a file (i.e.
|
10
|
+
# a docker secret):
|
11
|
+
Dir["#{ENV.fetch('SECRETS_PATH', '/run/secrets/')}*"].each do |secret_filepath|
|
12
|
+
next unless File.file?(secret_filepath)
|
13
|
+
|
14
|
+
secret_envvarname = File.basename(secret_filepath, '.*').upcase
|
15
|
+
|
16
|
+
# Skip if variable is already set - already-set variables have precedence over
|
17
|
+
# the secret files:
|
18
|
+
next if ENV.key?(secret_envvarname) && ENV[secret_envvarname].present?
|
19
|
+
|
20
|
+
ENV[secret_envvarname] = File.read(secret_filepath).strip
|
21
|
+
end
|
22
|
+
|
23
|
+
# For each *_URL environment variable where there's also a *_(USER|USERNAME) or
|
24
|
+
# *_(PASS|PASSWORD), update the URL environment variable with the given
|
25
|
+
# credentials. For example:
|
26
|
+
#
|
27
|
+
# DATABASE_URL: postgres://postgres:5432/demo_production
|
28
|
+
# DATABASE_USERNAME: lalito
|
29
|
+
# DATABASE_PASSWORD: lepass
|
30
|
+
#
|
31
|
+
# Results in the following updated DATABASE_URL:
|
32
|
+
# DATABASE_URL = postgres://lalito:lepass@postgres:5432/demo_production
|
33
|
+
require 'uri' if (url_keys = ENV.keys.select { |key| key =~ /_URL/ }).any?
|
34
|
+
|
35
|
+
url_keys.each do |url_key|
|
36
|
+
credential_pattern_string = url_key.gsub('_URL', '_(USER(NAME)?|PASS(WORD)?)')
|
37
|
+
credential_pattern = Regexp.new "\\A#{credential_pattern_string}\\z"
|
38
|
+
credential_keys = ENV.keys.select { |key| key =~ credential_pattern }
|
39
|
+
next unless credential_keys.any?
|
40
|
+
|
41
|
+
uri = URI(ENV[url_key])
|
42
|
+
username = URI.encode_www_form_component ENV[credential_keys.detect { |key| key =~ /USER/ }]
|
43
|
+
password = URI.encode_www_form_component ENV[credential_keys.detect { |key| key =~ /PASS/ }]
|
44
|
+
|
45
|
+
uri.user = username if username
|
46
|
+
uri.password = password if password
|
47
|
+
ENV[url_key] = uri.to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
# STDERR.puts ENV.inspect
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
require 'timeout'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
module OnContainer
|
8
|
+
module Ops
|
9
|
+
module ServiceConnectionChecks
|
10
|
+
def service_accepts_connections?(service_uri, seconds_to_wait = 30)
|
11
|
+
uri = URI(service_uri)
|
12
|
+
|
13
|
+
Timeout::timeout(seconds_to_wait) do
|
14
|
+
TCPSocket.new(uri.host, uri.port).close
|
15
|
+
end
|
16
|
+
|
17
|
+
true
|
18
|
+
|
19
|
+
rescue => e
|
20
|
+
puts "Connection to #{uri.to_s} failed: '#{e.inspect}'"
|
21
|
+
end
|
22
|
+
|
23
|
+
def wait_for_service_to_accept_connections(service_uri, seconds_to_wait = 30, exit_on_fail = true)
|
24
|
+
return if service_accepts_connections?(service_uri, seconds_to_wait)
|
25
|
+
|
26
|
+
exit 1 if exit_on_fail
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/on_container/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: on_container
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Quintanilla
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -45,6 +45,8 @@ files:
|
|
45
45
|
- lib/on_container/dev/rails.rb
|
46
46
|
- lib/on_container/dev/rails_ops.rb
|
47
47
|
- lib/on_container/dev/setup_ops.rb
|
48
|
+
- lib/on_container/load_env_secrets.rb
|
49
|
+
- lib/on_container/ops/service_connection_checks.rb
|
48
50
|
- lib/on_container/step_down_from_root.rb
|
49
51
|
- lib/on_container/version.rb
|
50
52
|
- on_container.gemspec
|