skylight 3.1.5 → 4.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -9
- data/bin/skylight +1 -1
- data/ext/extconf.rb +74 -76
- data/ext/libskylight.yml +7 -6
- data/lib/skylight.rb +15 -13
- data/lib/skylight/api.rb +40 -37
- data/lib/skylight/cli.rb +55 -60
- data/lib/skylight/cli/doctor.rb +13 -14
- data/lib/skylight/cli/helpers.rb +20 -22
- data/lib/skylight/cli/merger.rb +119 -116
- data/lib/skylight/config.rb +110 -96
- data/lib/skylight/errors.rb +8 -10
- data/lib/skylight/helpers.rb +35 -37
- data/lib/skylight/native.rb +13 -13
- data/lib/skylight/native_ext_fetcher.rb +30 -37
- data/lib/skylight/probes/sinatra_add_middleware.rb +2 -2
- data/lib/skylight/railtie.rb +32 -8
- data/lib/skylight/sinatra.rb +1 -1
- data/lib/skylight/trace.rb +4 -5
- data/lib/skylight/util/component.rb +76 -11
- data/lib/skylight/util/deploy.rb +10 -21
- data/lib/skylight/util/hostname.rb +4 -4
- data/lib/skylight/util/http.rb +134 -136
- data/lib/skylight/util/ssl.rb +6 -6
- data/lib/skylight/version.rb +1 -1
- metadata +51 -50
data/lib/skylight/cli.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.unshift File.expand_path("vendor/cli", __dir__)
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require "skylight"
|
4
|
+
require "thor"
|
5
|
+
require "yaml"
|
6
|
+
require "highline"
|
7
|
+
require "active_support/inflector"
|
8
8
|
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
9
|
+
require "skylight/cli/helpers"
|
10
|
+
require "skylight/cli/doctor"
|
11
|
+
require "skylight/cli/merger"
|
12
12
|
|
13
13
|
module Skylight
|
14
14
|
module CLI
|
@@ -33,8 +33,8 @@ to set it up as a new app in Skylight.
|
|
33
33
|
|
34
34
|
res = api.create_app(app_name, token)
|
35
35
|
|
36
|
-
config[:application] = res.get(
|
37
|
-
config[:authentication] = res.get(
|
36
|
+
config[:application] = res.get("app.id")
|
37
|
+
config[:authentication] = res.get("app.token")
|
38
38
|
config.write(config_path)
|
39
39
|
|
40
40
|
say "Congratulations. Your application is on Skylight! https://www.skylight.io", :green
|
@@ -79,64 +79,59 @@ you should set the `SKYLIGHT_AUTHENTICATION` variable to:
|
|
79
79
|
say "Environment warning disabled", :green
|
80
80
|
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
82
|
+
private
|
83
|
+
|
84
|
+
def app_name
|
85
|
+
@app_name ||=
|
86
|
+
begin
|
87
|
+
name = nil
|
88
|
+
|
89
|
+
if rails?
|
90
|
+
# Get the name in a process so that we don't pollute our environment here
|
91
|
+
# This is especially important since users may have things like WebMock that
|
92
|
+
# will prevent us from communicating with the Skylight API
|
93
|
+
begin
|
94
|
+
namefile = Tempfile.new("skylight-app-name")
|
95
|
+
# Windows appears to need double quotes for `rails runner`
|
96
|
+
`rails runner "File.open('#{namefile.path}', 'w') {|f| f.write(Rails.application.class.name) rescue '' }"`
|
97
|
+
name = namefile.read.split("::").first.underscore.titleize
|
98
|
+
name = nil if name.empty?
|
99
|
+
rescue => e
|
100
|
+
if ENV["DEBUG"]
|
101
|
+
puts e.class.name
|
102
|
+
puts e.to_s
|
103
|
+
puts e.backtrace.join("\n")
|
104
|
+
end
|
105
|
+
ensure
|
106
|
+
namefile.close
|
107
|
+
namefile.unlink
|
104
108
|
end
|
105
|
-
ensure
|
106
|
-
namefile.close
|
107
|
-
namefile.unlink
|
108
|
-
end
|
109
109
|
|
110
|
-
|
111
|
-
|
110
|
+
unless name
|
111
|
+
warn "Unable to determine Rails application name. Using directory name."
|
112
|
+
end
|
112
113
|
end
|
113
|
-
end
|
114
114
|
|
115
|
-
|
116
|
-
name = File.basename(File.expand_path('.')).titleize
|
115
|
+
name || File.basename(File.expand_path(".")).titleize
|
117
116
|
end
|
117
|
+
end
|
118
118
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
# Is this duplicated?
|
124
|
-
def relative_config_path
|
125
|
-
'config/skylight.yml'
|
126
|
-
end
|
127
|
-
|
128
|
-
def config_path
|
129
|
-
File.expand_path(relative_config_path)
|
130
|
-
end
|
119
|
+
# Is this duplicated?
|
120
|
+
def relative_config_path
|
121
|
+
"config/skylight.yml"
|
122
|
+
end
|
131
123
|
|
132
|
-
|
133
|
-
|
134
|
-
|
124
|
+
def config_path
|
125
|
+
File.expand_path(relative_config_path)
|
126
|
+
end
|
135
127
|
|
136
|
-
|
137
|
-
|
138
|
-
|
128
|
+
def api
|
129
|
+
@api ||= Api.new(config)
|
130
|
+
end
|
139
131
|
|
132
|
+
def user_config
|
133
|
+
config.user_config
|
134
|
+
end
|
140
135
|
end
|
141
136
|
end
|
142
137
|
end
|
data/lib/skylight/cli/doctor.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "skylight/util/http"
|
2
2
|
|
3
3
|
module Skylight
|
4
4
|
module CLI
|
@@ -20,7 +20,7 @@ module Skylight
|
|
20
20
|
say "Failed to verify SSL certificate.", :red
|
21
21
|
if Util::SSL.ca_cert_file?
|
22
22
|
say "Certificates located at #{Util::SSL.ca_cert_file_or_default} may be out of date.", :yellow
|
23
|
-
if
|
23
|
+
if mac? && rvm_present?
|
24
24
|
say "Please update your certificates with RVM by running `rvm osx-ssl-certs update all`.", :yellow
|
25
25
|
say "Alternatively, try setting `SKYLIGHT_FORCE_OWN_CERTS=1` in your environment.", :yellow
|
26
26
|
else
|
@@ -39,7 +39,7 @@ module Skylight
|
|
39
39
|
say "Checking for Rails"
|
40
40
|
|
41
41
|
indent do
|
42
|
-
if
|
42
|
+
if rails?
|
43
43
|
say "Rails application detected", :green
|
44
44
|
else
|
45
45
|
say "No Rails application detected", :yellow
|
@@ -63,7 +63,7 @@ module Skylight
|
|
63
63
|
say "Unable to load native extension", :yellow
|
64
64
|
|
65
65
|
indent do
|
66
|
-
install_log = File.expand_path("
|
66
|
+
install_log = File.expand_path("../../ext/install.log", __dir__)
|
67
67
|
if File.exist?(install_log)
|
68
68
|
File.readlines(install_log).each do |line|
|
69
69
|
say line, :red
|
@@ -112,8 +112,8 @@ module Skylight
|
|
112
112
|
# Log everything
|
113
113
|
logger.level = Logger::DEBUG
|
114
114
|
# Remove excess formatting
|
115
|
-
logger.formatter = proc { |severity,
|
116
|
-
msg = msg.sub("[SKYLIGHT] [#{Skylight::VERSION}] ",
|
115
|
+
logger.formatter = proc { |severity, _datetime, _progname, msg|
|
116
|
+
msg = msg.sub("[SKYLIGHT] [#{Skylight::VERSION}] ", "")
|
117
117
|
say "#{severity} - #{msg}" # Definitely non-standard
|
118
118
|
}
|
119
119
|
config.logger = logger
|
@@ -139,7 +139,7 @@ module Skylight
|
|
139
139
|
daemon_running = false
|
140
140
|
while tries < 5
|
141
141
|
`ps cax | grep skylightd`
|
142
|
-
if
|
142
|
+
if $CHILD_STATUS.success?
|
143
143
|
daemon_running = true
|
144
144
|
break
|
145
145
|
end
|
@@ -171,9 +171,9 @@ module Skylight
|
|
171
171
|
return @config if @config
|
172
172
|
|
173
173
|
# MEGAHAX
|
174
|
-
if
|
174
|
+
if rails?
|
175
175
|
# Normally auto-loaded, but we haven't loaded Rails by the time Skylight is loaded
|
176
|
-
require
|
176
|
+
require "skylight/railtie"
|
177
177
|
require rails_rb
|
178
178
|
|
179
179
|
railtie = Skylight::Railtie.send(:new)
|
@@ -183,14 +183,14 @@ module Skylight
|
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
186
|
-
def
|
187
|
-
Core::Util::Platform::OS ==
|
186
|
+
def mac?
|
187
|
+
Core::Util::Platform::OS == "darwin"
|
188
188
|
end
|
189
189
|
|
190
190
|
# NOTE: This check won't work correctly on Windows
|
191
|
-
def
|
191
|
+
def rvm_present?
|
192
192
|
if @has_rvm.nil?
|
193
|
-
@has_rvm = system("which rvm > /dev/null")
|
193
|
+
@has_rvm = system("which rvm > /dev/null")
|
194
194
|
end
|
195
195
|
@has_rvm
|
196
196
|
end
|
@@ -217,7 +217,6 @@ module Skylight
|
|
217
217
|
exit 0
|
218
218
|
end
|
219
219
|
end
|
220
|
-
|
221
220
|
end
|
222
221
|
end
|
223
222
|
end
|
data/lib/skylight/cli/helpers.rb
CHANGED
@@ -1,32 +1,30 @@
|
|
1
1
|
module Skylight
|
2
2
|
module CLI
|
3
3
|
module Helpers
|
4
|
-
|
5
4
|
private
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def is_rails?
|
13
|
-
File.exist?(rails_rb)
|
14
|
-
end
|
6
|
+
# Duplicated below
|
7
|
+
def rails_rb
|
8
|
+
File.expand_path("config/application.rb")
|
9
|
+
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
11
|
+
def rails?
|
12
|
+
File.exist?(rails_rb)
|
13
|
+
end
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
shell.padding += count
|
26
|
-
yield
|
27
|
-
shell.padding = orig_padding
|
28
|
-
end
|
15
|
+
def config
|
16
|
+
# Calling .load checks ENV variables
|
17
|
+
@config ||= Config.load
|
18
|
+
end
|
29
19
|
|
20
|
+
# Sets the output padding while executing a block and resets it.
|
21
|
+
#
|
22
|
+
def indent(count = 1)
|
23
|
+
orig_padding = shell.padding
|
24
|
+
shell.padding += count
|
25
|
+
yield
|
26
|
+
shell.padding = orig_padding
|
27
|
+
end
|
30
28
|
end
|
31
29
|
end
|
32
|
-
end
|
30
|
+
end
|
data/lib/skylight/cli/merger.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "ostruct"
|
2
|
+
require "skylight/util/http"
|
3
|
+
require "thor"
|
4
|
+
require "highline"
|
5
5
|
|
6
6
|
module Skylight
|
7
7
|
module CLI
|
@@ -13,9 +13,9 @@ module Skylight
|
|
13
13
|
end
|
14
14
|
|
15
15
|
STRINGS = {
|
16
|
-
get_token:
|
16
|
+
get_token: "get your merge token from `https://www.skylight.io/merging`",
|
17
17
|
unlisted: "My app isn't listed here :("
|
18
|
-
}
|
18
|
+
}.freeze
|
19
19
|
|
20
20
|
argument :merge_token, type: :string, desc: STRINGS[:get_token]
|
21
21
|
|
@@ -86,8 +86,8 @@ module Skylight
|
|
86
86
|
i = ask("\nWhich number?").chomp.to_i
|
87
87
|
|
88
88
|
@child_env = case i
|
89
|
-
when 1 then
|
90
|
-
when 2 then
|
89
|
+
when 1 then "development"
|
90
|
+
when 2 then "staging"
|
91
91
|
when 3
|
92
92
|
specify_child_env
|
93
93
|
else
|
@@ -130,15 +130,15 @@ module Skylight
|
|
130
130
|
say "IMPORTANT!\n" \
|
131
131
|
"If you use a config/skylight.yml file to configure Skylight:\n", :yellow
|
132
132
|
|
133
|
-
say "The
|
133
|
+
say "The #{@child_env} environment for the #{@parent_app.name} app\n" \
|
134
134
|
"will now connect using the default authentication token for the app.\n" \
|
135
135
|
"Remove any environment-specific `authentication` configs from the\n" \
|
136
|
-
"#{@parent_app.name}
|
136
|
+
"#{@parent_app.name} #{@child_env} environment.\n", :yellow
|
137
137
|
|
138
|
-
say "If you're running in Rails and your Rails environment exactly matches
|
138
|
+
say "If you're running in Rails and your Rails environment exactly matches `#{@child_env}`,\n" \
|
139
139
|
"we will automatically detect and report that environment when your agent connects.\n" \
|
140
|
-
"Otherwise, you should set `env: '
|
141
|
-
"
|
140
|
+
"Otherwise, you should set `env: '#{@child_env}'` as environment-specific configuration for\n" \
|
141
|
+
"#{@child_env}'s Rails environment. For example:\n" \
|
142
142
|
"```yml\n" \
|
143
143
|
"staging:\n" \
|
144
144
|
" env: staging-42\n" \
|
@@ -151,14 +151,14 @@ module Skylight
|
|
151
151
|
|
152
152
|
say "Deploy the latest agent before updating your environment variables.\n", :yellow
|
153
153
|
|
154
|
-
say "The
|
154
|
+
say "The #{@child_env} environment for the #{@parent_app.name} app\n" \
|
155
155
|
"will now connect using the default authentication token for the app.\n" \
|
156
|
-
"Set `SKYLIGHT_AUTHENTICATION` in the
|
156
|
+
"Set `SKYLIGHT_AUTHENTICATION` in the #{@child_env} environment to the\n" \
|
157
157
|
"#{@parent_app.name} app's authentication token.\n", :yellow
|
158
158
|
|
159
|
-
say "If you're running in Rails and your Rails environment exactly matches
|
159
|
+
say "If you're running in Rails and your Rails environment exactly matches `#{@child_env}`,\n" \
|
160
160
|
"we will automatically detect and report that environment when your agent connects.\n" \
|
161
|
-
"Otherwise, you should set `SKYLIGHT_ENV
|
161
|
+
"Otherwise, you should set `SKYLIGHT_ENV=#{@child_env}` when running in this environment.\n", :yellow
|
162
162
|
|
163
163
|
say "=======================================================", :yellow
|
164
164
|
|
@@ -167,131 +167,134 @@ module Skylight
|
|
167
167
|
|
168
168
|
private
|
169
169
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
api.merge_apps!(@merge_token,
|
174
|
-
app_guid: @parent_app.guid,
|
175
|
-
component_guid: @child_app.guid,
|
176
|
-
environment: @child_env
|
177
|
-
)
|
178
|
-
rescue => e
|
179
|
-
say("Something went wrong. Please contact support@skylight.io for more information.", :red)
|
180
|
-
done!(message: e.message, success: false)
|
181
|
-
end
|
182
|
-
|
183
|
-
def done!(message: nil, success: true)
|
184
|
-
shell.padding = 0
|
185
|
-
say "\n"
|
170
|
+
def do_merge
|
171
|
+
say "Merging..."
|
186
172
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
say
|
193
|
-
|
194
|
-
exit 1
|
173
|
+
api.merge_apps!(@merge_token,
|
174
|
+
app_guid: @parent_app.guid,
|
175
|
+
component_guid: @child_app.guid,
|
176
|
+
environment: @child_env)
|
177
|
+
rescue => e
|
178
|
+
say("Something went wrong. Please contact support@skylight.io for more information.", :red)
|
179
|
+
done!(message: e.message, success: false)
|
195
180
|
end
|
196
|
-
end
|
197
181
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
182
|
+
def done!(message: nil, success: true)
|
183
|
+
shell.padding = 0
|
184
|
+
say "\n"
|
185
|
+
|
186
|
+
if success
|
187
|
+
say(message, :green) if message
|
188
|
+
say "If you have any questions, please contact support@skylight.io.", :green
|
189
|
+
exit 0
|
190
|
+
else
|
191
|
+
say message || "Skylight wasn't able to merge your apps.", :red
|
192
|
+
say "If you have any questions, please contact support@skylight.io.", :yellow
|
193
|
+
exit 1
|
194
|
+
end
|
202
195
|
end
|
203
196
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
elsif app_list[n].unlisted
|
210
|
-
done!(
|
211
|
-
success: false,
|
212
|
-
message: "Sorry, `skylight merge` is only able to merge apps that you own."
|
213
|
-
)
|
214
|
-
else
|
215
|
-
app_list[n]
|
216
|
-
end
|
217
|
-
end
|
197
|
+
def ask_for_app(app_list, &formatter)
|
198
|
+
formatter ||= :name.to_proc
|
199
|
+
app_list.each do |index, app|
|
200
|
+
say("\t#{index}. #{formatter.call(app)}")
|
201
|
+
end
|
218
202
|
|
219
|
-
|
220
|
-
@api ||= Skylight::Api.new(config)
|
221
|
-
end
|
203
|
+
n = ask("\nWhich number?").chomp.to_i
|
222
204
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
205
|
+
if !app_list.key?(n)
|
206
|
+
say "\nHmm?"
|
207
|
+
ask_for_app(app_list, &formatter)
|
208
|
+
elsif app_list[n].unlisted
|
209
|
+
done!(
|
210
|
+
success: false,
|
211
|
+
message: "Sorry, `skylight merge` is only able to merge apps that you own."
|
212
|
+
)
|
213
|
+
else
|
214
|
+
app_list[n]
|
215
|
+
end
|
227
216
|
end
|
228
217
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
str
|
233
|
-
end
|
218
|
+
def api
|
219
|
+
@api ||= Skylight::Api.new(config)
|
220
|
+
end
|
234
221
|
|
235
|
-
|
236
|
-
|
222
|
+
def format_component(component)
|
223
|
+
parts = [].tap do |ary|
|
224
|
+
ary << component.name unless component.name == "web"
|
225
|
+
ary << component.environment unless component.environment == "production"
|
226
|
+
end
|
237
227
|
|
238
|
-
|
239
|
-
|
228
|
+
str = ""
|
229
|
+
str << component.app_name
|
230
|
+
str << Thor::Shell::Color.new.set_color(" (#{parts.join(':')})", :yellow) if parts.any?
|
231
|
+
str
|
240
232
|
end
|
241
233
|
|
242
|
-
|
243
|
-
errors
|
244
|
-
"component that conflicts with this merge request. Please choose a new environment."
|
245
|
-
end
|
234
|
+
def validate_mergeability(child_app, child_env)
|
235
|
+
errors = []
|
246
236
|
|
247
|
-
|
237
|
+
unless valid_component?(child_app.name, child_env)
|
238
|
+
errors << "Environment can only contain letters, numbers, and hyphens."
|
239
|
+
end
|
248
240
|
|
249
|
-
|
241
|
+
if @parent_app && parent_component_fingerprints.include?([child_app.name, child_env])
|
242
|
+
errors << "Sorry, `#{@parent_app.name}` already has a `#{child_env}` " \
|
243
|
+
"component that conflicts with this merge request. Please choose a new environment."
|
244
|
+
end
|
250
245
|
|
251
|
-
|
252
|
-
end
|
246
|
+
return child_env unless errors.any?
|
253
247
|
|
254
|
-
|
255
|
-
return false unless env
|
256
|
-
Skylight::Util::Component.new(env, component_name) && true
|
257
|
-
rescue ArgumentError
|
258
|
-
false
|
259
|
-
end
|
248
|
+
say errors.join("\n"), :red
|
260
249
|
|
261
|
-
|
262
|
-
|
263
|
-
|
250
|
+
yield
|
251
|
+
end
|
252
|
+
|
253
|
+
def valid_component?(component_name, env)
|
254
|
+
return false unless env
|
255
|
+
Skylight::Util::Component.new(env, component_name) && true
|
256
|
+
rescue ArgumentError
|
257
|
+
false
|
258
|
+
end
|
259
|
+
|
260
|
+
def parent_component_fingerprints
|
261
|
+
@parent_app.components.map { |x| x.values_at("name", "environment") }
|
262
|
+
end
|
264
263
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
264
|
+
def children
|
265
|
+
ret = Enumerator.new do |yielder|
|
266
|
+
@parents.each do |_, app|
|
267
|
+
next if app == @parent_app
|
268
|
+
app.components.each do |component|
|
269
|
+
yielder << OpenStruct.new({ app_name: app.name }.merge(component))
|
270
|
+
end
|
271
271
|
end
|
272
|
+
|
273
|
+
yielder << OpenStruct.new(app_name: STRINGS[:unlisted], unlisted: true)
|
272
274
|
end
|
273
275
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
276
|
+
ret = ret.each_with_object({}).with_index do |(c, r), i|
|
277
|
+
r[i + 1] = c
|
278
|
+
end
|
279
|
+
|
280
|
+
ret.tap do |result|
|
281
|
+
if result.values.all?(&:unlisted)
|
282
|
+
done!(
|
283
|
+
success: false,
|
284
|
+
message: "Sorry, you do not have any apps that can be merged into `#{@parent_app.name}`"
|
285
|
+
)
|
286
|
+
end
|
283
287
|
end
|
284
288
|
end
|
285
|
-
end
|
286
289
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
290
|
+
def specify_child_env
|
291
|
+
validate_mergeability(
|
292
|
+
@child_app,
|
293
|
+
ask("Please enter your environment name (only lowercase letters, numbers, or hyphens): ", :green).chomp
|
294
|
+
) do
|
295
|
+
specify_child_env
|
296
|
+
end
|
293
297
|
end
|
294
|
-
end
|
295
298
|
end
|
296
299
|
end
|
297
300
|
end
|