platform_sh 0.2.6.pre → 0.2.6
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/lib/platform_sh.rb +53 -120
- data/lib/platform_sh/version.rb +1 -1
- data/platform.gemspec +2 -2
- metadata +7 -10
- data/bin/platform_local_tunnel_env +0 -6
- data/lib/tasks/local_development.rake +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7eaa8d84c009896dfc9bc3e68cd2f98c85045fe
|
4
|
+
data.tar.gz: 952d74292f13f8b8db7eadea39f0d6631780c2eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 518bb82a01b507509380df30ec02b722ea60f755b82cb6429805f0fd395dcf8a6b3afb741b51ea790692d0022a611b2494705e710112e9d9af5c0f6ee0dea4f9
|
7
|
+
data.tar.gz: cb118a34499833de5245f6aebb1d2cdc7fbac85949d6827346035306c928469ebc34e4b837b03c1ad4b7a876a541fb54ecb894c789be870247c8c3cbd719070d
|
data/lib/platform_sh.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
require "platform_sh/version"
|
2
2
|
require "base64"
|
3
3
|
require 'json'
|
4
|
-
require '
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
$logger = Logger.new(STDOUT)
|
7
|
+
$logger.level = Logger::WARN
|
5
8
|
|
6
9
|
class PlatformSH
|
7
10
|
'use strict'
|
8
11
|
# Reads Platform.sh configuration from environment and returns a single object
|
9
12
|
def self.config
|
10
|
-
conf = {}
|
11
|
-
if platform_local_development?
|
12
|
-
conf["relationships"] = JSON.parse(Base64.decode64(tunnel_info))
|
13
|
-
return conf
|
14
|
-
end
|
15
13
|
if on_platform?
|
14
|
+
conf = {}
|
16
15
|
conf["application"] = read_base64_json('PLATFORM_APPLICATION')
|
17
16
|
conf["application_name"] =ENV["PLATFORM_APPLICATION_NAME"] || nil
|
18
17
|
conf["app_dir"] =ENV["PLATFORM_APP_DIR"] || nil
|
@@ -27,12 +26,12 @@ class PlatformSH
|
|
27
26
|
conf["variables"] = read_base64_json('PLATFORM_VARIABLES')
|
28
27
|
end
|
29
28
|
else
|
30
|
-
$
|
29
|
+
$logger.warn "This is not running on platform.sh"
|
31
30
|
return nil
|
32
31
|
end
|
33
32
|
conf
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
def self.on_platform?
|
37
36
|
ENV.has_key? 'PLATFORM_PROJECT'
|
38
37
|
end
|
@@ -40,7 +39,7 @@ class PlatformSH
|
|
40
39
|
def self.is_build_environment?
|
41
40
|
(!ENV.has_key?('PLATFORM_ENVIRONMENT') && ENV.has_key?('PLATFORM_PROJECT'))
|
42
41
|
end
|
43
|
-
|
42
|
+
|
44
43
|
def self.relationship rel_name, attr
|
45
44
|
on_platform? ? config["relationships"][rel_name].first[attr] : nil
|
46
45
|
end
|
@@ -50,63 +49,64 @@ class PlatformSH
|
|
50
49
|
begin
|
51
50
|
return JSON.parse(Base64.decode64(ENV[var_name]))
|
52
51
|
rescue
|
53
|
-
$
|
52
|
+
$logger.error "no " + var_name + " environment variable"
|
54
53
|
return nil
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
57
|
|
59
58
|
def self.read_app_config
|
59
|
+
#FIXME we should be able to get
|
60
60
|
JSON.parse(File.read('/run/config.json'))
|
61
61
|
end
|
62
|
-
|
63
|
-
|
62
|
+
|
63
|
+
|
64
64
|
#Tries to guess relational database url
|
65
65
|
def self.guess_database_url
|
66
66
|
postgresql_url = self.guess_postgresql_url
|
67
67
|
mysql_url = self.guess_mysql_url
|
68
68
|
if !mysql_url.nil? && !postgresql_url.nil?
|
69
|
-
$
|
69
|
+
$logger.info "More than one relational database, giving up, set configuration by hand"
|
70
70
|
return nil
|
71
71
|
end
|
72
72
|
if (mysql_url.nil? && postgresql_url.nil?)
|
73
|
-
$
|
73
|
+
$logger.info "Could not find a relational database"
|
74
74
|
return nil
|
75
75
|
end
|
76
76
|
return mysql_url || postgresql_url
|
77
77
|
end
|
78
78
|
|
79
|
-
def self.guess_url(
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
79
|
+
def self.guess_url(platform_service, url_template)
|
80
|
+
services = PlatformSH::config["relationships"].select {|k,v| v[0]["service"]==platform_service}
|
81
|
+
case services.length
|
82
|
+
when 0
|
83
|
+
$logger.info "Could not find an #{platform_service}"
|
84
|
+
return nil
|
85
|
+
when 1
|
86
|
+
service = services.first[1][0]
|
87
|
+
service = service.each_with_object({}){|(k,v), h| h[k.to_sym] = v} #keys need to be symbols
|
88
|
+
return url_template % service
|
89
|
+
else
|
90
|
+
$logger.warn "More than one #{platform_service}, giving up, set configuration by hand"
|
91
|
+
end
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
def self.guess_elasticsearch_url
|
95
|
-
self.guess_url("elasticsearch", "http
|
95
|
+
self.guess_url("elasticsearch", "http://%{host}:%{port}")
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
def self.guess_redis_url
|
99
|
-
self.guess_url("redis", "redis
|
99
|
+
self.guess_url("redis", "redis://%{host}:%{port}")
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def self.guess_mongodb_url
|
103
|
-
self.guess_url("mongodb", "mongodb
|
103
|
+
self.guess_url("mongodb", "mongodb://%{username}:%{password}@%{host}:%{port}/%{path}")
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
def self.guess_solr_url
|
107
|
-
self.guess_url(
|
107
|
+
self.guess_url( "solr", "http://%{host}:%{port}/%{path}")
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
def self.guess_mysql_url
|
111
111
|
#fallback to mysql url if mysql2 gem is not loaded
|
112
112
|
if Gem::Specification::find_all_by_name("mysql2").empty?
|
@@ -114,96 +114,29 @@ class PlatformSH
|
|
114
114
|
else
|
115
115
|
template = "mysql2://%{username}:%{password}@%{host}:%{port}/%{path}"
|
116
116
|
end
|
117
|
-
self.guess_url("mysql",
|
117
|
+
self.guess_url("mysql", template)
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
def self.guess_rabbitmq_url
|
121
|
-
self.guess_url("rabbitmq",
|
121
|
+
self.guess_url("rabbitmq","amqp://%{username}:%{password}@%{host}:%{port}")
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
def self.guess_postgresql_url
|
125
|
-
self.guess_url("postgresql",
|
126
|
-
end
|
127
|
-
|
128
|
-
def self.export_services_urls
|
129
|
-
if (on_platform? || platform_local_development?) && !is_build_environment?
|
130
|
-
ENV['DATABASE_URL']=PlatformSH::guess_database_url
|
131
|
-
ENV['MONGODB_URL']=PlatformSH::guess_mongodb_url
|
132
|
-
ENV['REDIS_URL']=PlatformSH::guess_redis_url
|
133
|
-
ENV['ELASTICSEARCH_URL']=PlatformSH::guess_elasticsearch_url
|
134
|
-
ENV['RABBITMQ_URL']=PlatformSH::guess_rabbitmq_url
|
135
|
-
ENV['SOLR_URL']=PlatformSH::guess_solr_url
|
136
|
-
else
|
137
|
-
$stderr.puts "Can not guess URLS when not on platform"
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def self.platform_local_development?
|
142
|
-
dev_environment = ENV["RACK_ENV"] != "production" && ENV["RAILS_ENV"] != "production"
|
143
|
-
dev_environment && cli_installed? && !on_platform?
|
144
|
-
end
|
145
|
-
|
146
|
-
def self.cli_installed?
|
147
|
-
begin
|
148
|
-
Open3.popen3("platform --version --yes") do |stdin, stdout, stderr, wait_thr|
|
149
|
-
err = stdout.gets
|
150
|
-
return (err.nil? && err.start_with?("Platform.sh CLI"))
|
151
|
-
end
|
152
|
-
rescue
|
153
|
-
$stderr.puts "WHATTT"
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def self.tunnel_open?
|
158
|
-
Open3.popen3("platform --yes tunnel:info") do |stdin, stdout, stderr, wait_thr|
|
159
|
-
err = stderr.gets
|
160
|
-
return !(!err.nil? && err.start_with?("No tunnels found"))
|
161
|
-
end
|
125
|
+
self.guess_url("postgresql","postgresql://%{username}:%{password}@%{host}:%{port}")
|
162
126
|
end
|
163
|
-
|
164
|
-
def self.
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
|
-
def self.tunnel_open
|
169
|
-
%x(platform tunnel:open --yes)
|
170
|
-
end
|
171
|
-
|
172
|
-
def self.tunnel_close
|
173
|
-
%x(platform tunnel:close --yes)
|
127
|
+
|
128
|
+
def self.guess_influxdb_url
|
129
|
+
self.guess_url("influxdb","http://%{host}:%{port}")
|
174
130
|
end
|
175
131
|
|
176
|
-
def self.
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
puts "Signal #{sig} not supported"
|
185
|
-
end
|
186
|
-
end
|
187
|
-
def self.shut_down
|
188
|
-
puts "\nShutting down gracefully..."
|
189
|
-
puts tunnel_close
|
190
|
-
exit
|
191
|
-
end
|
192
|
-
|
193
|
-
command = ARGV[1]
|
194
|
-
if command.nil?
|
195
|
-
$stderr.puts "You must supply an executable to run"
|
196
|
-
return nil
|
197
|
-
end
|
198
|
-
if !tunnel_open?
|
199
|
-
puts tunnel_open
|
200
|
-
else
|
201
|
-
puts tunnel_info
|
202
|
-
end
|
203
|
-
export_services_urls
|
204
|
-
Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
|
205
|
-
puts "stdout is:" + stdout.read
|
206
|
-
$stderr.puts "stderr is:" + stderr.read
|
207
|
-
end
|
132
|
+
def self.export_services_urls
|
133
|
+
ENV['DATABASE_URL']=PlatformSH::guess_database_url
|
134
|
+
ENV['MONGODB_URL']=PlatformSH::guess_mongodb_url
|
135
|
+
ENV['REDIS_URL']=PlatformSH::guess_redis_url
|
136
|
+
ENV['ELASTICSEARCH_URL']=PlatformSH::guess_elasticsearch_url
|
137
|
+
ENV['RABBITMQ_URL']=PlatformSH::guess_rabbitmq_url
|
138
|
+
ENV['SOLR_URL']=PlatformSH::guess_solr_url
|
139
|
+
ENV['INFLUXDB_URL']=PlatformSH::guess_influxdb_url
|
208
140
|
end
|
141
|
+
|
209
142
|
end
|
data/lib/platform_sh/version.rb
CHANGED
data/platform.gemspec
CHANGED
@@ -15,8 +15,8 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir = "
|
19
|
-
spec.executables = spec.files.grep(%r{^
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.12"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: platform_sh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.6
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ori Pekelman
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,8 +69,7 @@ dependencies:
|
|
69
69
|
description: Platform.sh helper gem to ease interacting with the environment
|
70
70
|
email:
|
71
71
|
- ori@platform.sh
|
72
|
-
executables:
|
73
|
-
- platform_local_tunnel_env
|
72
|
+
executables: []
|
74
73
|
extensions: []
|
75
74
|
extra_rdoc_files: []
|
76
75
|
files:
|
@@ -82,11 +81,9 @@ files:
|
|
82
81
|
- README.md
|
83
82
|
- Rakefile
|
84
83
|
- bin/console
|
85
|
-
- bin/platform_local_tunnel_env
|
86
84
|
- bin/setup
|
87
85
|
- lib/platform_sh.rb
|
88
86
|
- lib/platform_sh/version.rb
|
89
|
-
- lib/tasks/local_development.rake
|
90
87
|
- platform.gemspec
|
91
88
|
homepage: https://platform.sh
|
92
89
|
licenses:
|
@@ -103,12 +100,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
100
|
version: '0'
|
104
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
102
|
requirements:
|
106
|
-
- - "
|
103
|
+
- - ">="
|
107
104
|
- !ruby/object:Gem::Version
|
108
|
-
version:
|
105
|
+
version: '0'
|
109
106
|
requirements: []
|
110
107
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
108
|
+
rubygems_version: 2.6.13
|
112
109
|
signing_key:
|
113
110
|
specification_version: 4
|
114
111
|
summary: Platform.sh helper gem to ease interacting with the environment
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require "platform_sh"
|
3
|
-
|
4
|
-
task :default => [:local_tunnel_env]
|
5
|
-
|
6
|
-
namespace :platform_sh do
|
7
|
-
desc 'Open Tunnels, set services env variables to remote Platform.sh services and runs a command with the env'
|
8
|
-
task :local_tunnel_env do
|
9
|
-
PlatformSH::local_tunnel_env
|
10
|
-
end
|
11
|
-
end
|