ruby-ship 0.1.0
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 +7 -0
- data/LICENSE.md +21 -0
- data/README.md +175 -0
- data/docs/extensions.md +38 -0
- data/exe/ship +4 -0
- data/lib/ship/application.rb +123 -0
- data/lib/ship/cli.rb +429 -0
- data/lib/ship/compose.rb +288 -0
- data/lib/ship/config.rb +160 -0
- data/lib/ship/docker.rb +123 -0
- data/lib/ship/environment_files.rb +227 -0
- data/lib/ship/extensions.rb +70 -0
- data/lib/ship/project.rb +255 -0
- data/lib/ship/release.rb +332 -0
- data/lib/ship/services.rb +103 -0
- data/lib/ship/setup.rb +318 -0
- data/lib/ship/setup_options.rb +317 -0
- data/lib/ship/terminal.rb +205 -0
- data/lib/ship/version.rb +3 -0
- data/lib/ship.rb +6 -0
- data/schema/service-environment.json +23 -0
- data/schema/ship-release.schema.json +145 -0
- data/schema/ship.schema.json +507 -0
- data/templates/entrypoint.rb +19 -0
- data/templates/garage/Dockerfile +7 -0
- data/templates/garage/garage.toml +15 -0
- data/templates/mongodb/Dockerfile +7 -0
- data/templates/mongodb/app-user.js +4 -0
- data/templates/mongodb/bootstrap.js +28 -0
- data/templates/mongodb/bootstrap.sh +10 -0
- data/templates/mongodb/entrypoint.sh +20 -0
- data/templates/mongodb/health.js +18 -0
- data/templates/services.json +1783 -0
- metadata +70 -0
data/lib/ship/cli.rb
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
require "optparse"
|
|
2
|
+
require_relative "setup"
|
|
3
|
+
require_relative "docker"
|
|
4
|
+
|
|
5
|
+
module Ship
|
|
6
|
+
class CLI
|
|
7
|
+
COMMANDS = {
|
|
8
|
+
"Project setup" => {
|
|
9
|
+
"init" => "Configure a Ruby project and generate its Docker stack",
|
|
10
|
+
"package-manager" => "Select the package manager for JavaScript assets"
|
|
11
|
+
},
|
|
12
|
+
"Development" => {
|
|
13
|
+
"up" => "Build and start the development stack", "down" => "Stop the development stack",
|
|
14
|
+
"ps" => "Show running services", "run" => "Run a command in a disposable container",
|
|
15
|
+
"exec" => "Run a command in a running service", "shell" => "Open a service shell",
|
|
16
|
+
"logs" => "Read or follow service logs", "db" => "Open a database client",
|
|
17
|
+
"bundle" => "Run Bundler inside the app container", "ruby" => "Run Ruby inside the app container",
|
|
18
|
+
"rake" => "Run a Rake task", "npm" => "Run npm inside the Node service",
|
|
19
|
+
"pnpm" => "Run pnpm inside the Node service", "yarn" => "Run Yarn inside the Node service",
|
|
20
|
+
"bun" => "Run Bun inside the Node service", "test" => "Run the project test suite"
|
|
21
|
+
},
|
|
22
|
+
"Troubleshooting" => { "check" => "Validate project settings", "doctor" => "Inspect Docker and the development stack" },
|
|
23
|
+
"Production" => { "build" => "Build the production images", "release" => "Export a portable production release" },
|
|
24
|
+
"Command-line tools" => { "help" => "Show command help", "--version" => "Show the Ruby Ship version" }
|
|
25
|
+
}.freeze
|
|
26
|
+
USAGE = {
|
|
27
|
+
"init" => "[--defaults] [--framework KEY] [--server KEY] [--database KEY] [--add GROUP:KEY:NAME]",
|
|
28
|
+
"package-manager" => "npm|pnpm|yarn|bun [VERSION]",
|
|
29
|
+
"up" => "[--verbose] [--no-build] [--wait-timeout SECONDS]",
|
|
30
|
+
"down" => "[--volumes] [OPTIONS]", "ps" => "[OPTIONS]", "run" => "[--verbose] [-e KEY=VALUE] [--] COMMAND [ARGS…]",
|
|
31
|
+
"exec" => "SERVICE COMMAND [ARGS…]", "shell" => "[SERVICE]", "logs" => "[-f] [--tail N] [SERVICE…]",
|
|
32
|
+
"db" => "[INSTANCE]", "check" => "[--json] [--compose]", "doctor" => "[--json]",
|
|
33
|
+
"build" => "[--verbose] [--platform OS/ARCH]", "release" => "TAG [--verbose] [--no-env] [--force] [--platform OS/ARCH]"
|
|
34
|
+
}.freeze
|
|
35
|
+
|
|
36
|
+
def initialize(terminal: Terminal.new, root: Dir.pwd)
|
|
37
|
+
@terminal, @root = terminal, File.expand_path(root)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def run(arguments)
|
|
41
|
+
args = arguments.dup
|
|
42
|
+
@verbose_builds = false
|
|
43
|
+
while %w[--root -C --verbose -v].include?(args.first)
|
|
44
|
+
if %w[--verbose -v].include?(args.shift)
|
|
45
|
+
@verbose_builds = true
|
|
46
|
+
else
|
|
47
|
+
@root = File.expand_path(args.shift || raise(Error, "--root requires a directory."), @root)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
command = args.shift || "help"
|
|
51
|
+
return version if %w[--version -V version].include?(command)
|
|
52
|
+
return help(args.first) if %w[-h --help help].include?(command)
|
|
53
|
+
return help(command) if USAGE.key?(command) && %w[--help -h].include?(args.first)
|
|
54
|
+
|
|
55
|
+
case command
|
|
56
|
+
when "init" then init(args)
|
|
57
|
+
when "package-manager" then package_manager(args)
|
|
58
|
+
when "check", "doctor" then inspect_project(command, args)
|
|
59
|
+
when "up" then up(args)
|
|
60
|
+
when "build", "release" then production(command, args)
|
|
61
|
+
else development(command, args)
|
|
62
|
+
end
|
|
63
|
+
rescue Terminal::Cancelled
|
|
64
|
+
@terminal.status("Setup cancelled.", :muted)
|
|
65
|
+
130
|
|
66
|
+
rescue Interrupt
|
|
67
|
+
130
|
|
68
|
+
rescue OptionParser::ParseError, Error, Errno::EACCES, Errno::ENOTDIR => error
|
|
69
|
+
@terminal.error.puts("#{@terminal.paint('Error', :error)} #{error.message}")
|
|
70
|
+
1
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
def version
|
|
76
|
+
@terminal.output.puts(Ship::VERSION)
|
|
77
|
+
0
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def help(command = nil)
|
|
81
|
+
descriptions = COMMANDS.values.reduce({}, :merge).merge("rails" => "Run the Rails command line", "hanami" => "Run the Hanami command line")
|
|
82
|
+
@terminal.title("Ruby Ship #{Ship::VERSION}")
|
|
83
|
+
if command
|
|
84
|
+
description = descriptions[command] || raise(Error, "Unknown command #{command.inspect}.")
|
|
85
|
+
@terminal.table([["Usage", "ship #{command} #{USAGE.fetch(command, '[ARGS…]')}".rstrip], ["Purpose", description]])
|
|
86
|
+
if command == "init"
|
|
87
|
+
@terminal.section("Configuration")
|
|
88
|
+
@terminal.table([
|
|
89
|
+
["--defaults", "Use the detected and supplied options without prompting"],
|
|
90
|
+
["--service GROUP=KEY", "Select a provider or use none to clear it"],
|
|
91
|
+
["--add GROUP:KEY:NAME", "Add a named service instance"],
|
|
92
|
+
["--remove NAME", "Remove a named service instance"],
|
|
93
|
+
["--process NAME=COMMAND", "Add a worker, scheduler, or server"],
|
|
94
|
+
["--process-definition NAME=JSON", "Set a process with HTTP or health metadata"],
|
|
95
|
+
["--external-network NAME", "Attach HTTP endpoints to an existing network"],
|
|
96
|
+
["--publish-development SERVICE:PORT", "Select development host ports"],
|
|
97
|
+
["--publish-production SERVICE:PORT", "Select production host ports"],
|
|
98
|
+
["--publish-ports", "Publish the app port in production"]
|
|
99
|
+
])
|
|
100
|
+
end
|
|
101
|
+
else
|
|
102
|
+
@terminal.table([["Usage", "ship [-C DIRECTORY] [--verbose] COMMAND [ARGS…]"],
|
|
103
|
+
["-v, --verbose", "Stream image build output"]])
|
|
104
|
+
commands = COMMANDS.transform_values(&:dup)
|
|
105
|
+
data = Config.read(@root, required: false)
|
|
106
|
+
framework = Application.new(Config.new(@root, data)).framework
|
|
107
|
+
commands["Development"][framework] = descriptions.fetch(framework) if %w[rails hanami].include?(framework)
|
|
108
|
+
commands.each do |section, lines|
|
|
109
|
+
@terminal.section(section)
|
|
110
|
+
@terminal.table(lines.to_a)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
0
|
|
114
|
+
rescue Error => error
|
|
115
|
+
raise if command || !File.exist?(File.join(@root, "ship.json"))
|
|
116
|
+
|
|
117
|
+
COMMANDS.each do |section, lines|
|
|
118
|
+
@terminal.section(section)
|
|
119
|
+
@terminal.table(lines.to_a)
|
|
120
|
+
end
|
|
121
|
+
@terminal.status(error.message, :warning)
|
|
122
|
+
0
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def init(args)
|
|
126
|
+
options = { config: {}, services: {}, additional: [], remove: [], processes: {}, remove_processes: [], publish: {} }
|
|
127
|
+
parser = OptionParser.new do |cli|
|
|
128
|
+
cli.on("-n", "--defaults", "--no-interaction") { options[:defaults] = true }
|
|
129
|
+
cli.on("--force") { options[:force] = true }
|
|
130
|
+
%w[framework server name node].each { |key| cli.on("--#{key} VALUE", String) { |value| options[:config][key] = value } }
|
|
131
|
+
cli.on("--port NUMBER", Integer) { |value| options[:config]["port"] = value }
|
|
132
|
+
cli.on("--[no-]node-assets") { |value| options[:config]["nodeAssets"] = value }
|
|
133
|
+
cli.on("--[no-]host-user") { |value| options[:config]["hostUser"] = value }
|
|
134
|
+
cli.on("--[no-]publish-ports") { |value| options[:config]["publishPorts"] = value }
|
|
135
|
+
%w[development production].each do |environment|
|
|
136
|
+
cli.on("--publish-#{environment} SERVICE:PORT", String) do |value|
|
|
137
|
+
explicit = (options[:publish][environment] ||= [])
|
|
138
|
+
value == "none" ? explicit.clear : explicit.concat(value.split(",").map(&:strip)).uniq!
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
cli.on("--package-manager NAME", String) { |value| options[:config]["packageManager"] = value }
|
|
142
|
+
cli.on("--package-manager-version VERSION", String) { |value| options[:config]["packageManagerVersion"] = value }
|
|
143
|
+
cli.on("--external-network NAMES", Array) { |value| options[:config]["externalNetwork"] = value unless value.empty? }
|
|
144
|
+
cli.on("--no-network") { options[:clear_networks] = true }
|
|
145
|
+
cli.on("--mongodb-mode MODE", String) { |value| options[:config]["mongodbMode"] = value }
|
|
146
|
+
cli.on("--silo-image IMAGE", String) { |value| options[:config]["siloImage"] = value }
|
|
147
|
+
Services::GROUPS.keys.each do |group|
|
|
148
|
+
cli.on("--#{group} PROVIDER", String) { |key| options[:services][group] = key }
|
|
149
|
+
end
|
|
150
|
+
cli.on("--analytics PROVIDER", String) { |key| options[:services]["analytics"] = key }
|
|
151
|
+
cli.on("--service GROUP=KEY", String) do |value|
|
|
152
|
+
group, key = value.split("=", 2)
|
|
153
|
+
raise Error, "--service needs GROUP=KEY." if group.empty? || !key || key.empty?
|
|
154
|
+
|
|
155
|
+
options[:services][group] = key
|
|
156
|
+
end
|
|
157
|
+
cli.on("--add GROUP:KEY:NAME", String) do |value|
|
|
158
|
+
group, key, name = value.split(":", 3)
|
|
159
|
+
options[:additional] << { "group" => group, "service" => key, "name" => name }
|
|
160
|
+
end
|
|
161
|
+
cli.on("--remove INSTANCE", String) { |value| options[:remove] << value }
|
|
162
|
+
cli.on("--process NAME=COMMAND", String) do |value|
|
|
163
|
+
name, command = value.split("=", 2)
|
|
164
|
+
raise Error, "--process needs NAME=COMMAND." unless command
|
|
165
|
+
|
|
166
|
+
options[:processes][name] = command
|
|
167
|
+
end
|
|
168
|
+
cli.on("--process-definition NAME=JSON", String) do |value|
|
|
169
|
+
name, definition = value.split("=", 2)
|
|
170
|
+
raise Error, "--process-definition needs NAME=JSON." unless definition
|
|
171
|
+
|
|
172
|
+
begin
|
|
173
|
+
options[:processes][name] = JSON.parse(definition)
|
|
174
|
+
rescue JSON::ParserError
|
|
175
|
+
raise Error, "Invalid JSON for process #{name.inspect}."
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
cli.on("--remove-process NAME", String) { |value| options[:remove_processes] << value }
|
|
179
|
+
cli.on("--deploy-command COMMAND", String) { |value| (options[:deploy] ||= []) << value }
|
|
180
|
+
cli.on("--no-deploy-commands") { options[:deploy] = [] }
|
|
181
|
+
end
|
|
182
|
+
parser.parse!(args)
|
|
183
|
+
raise Error, "Unexpected setup arguments #{args.join(' ')}." unless args.empty?
|
|
184
|
+
|
|
185
|
+
Setup.new(@root, @terminal, options).run
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def project
|
|
189
|
+
@project ||= Project.new(Config.new(@root, Config.read(@root)))
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def docker = Docker.new(project)
|
|
193
|
+
|
|
194
|
+
def prepare
|
|
195
|
+
project.regenerate
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def up(args)
|
|
199
|
+
build = true
|
|
200
|
+
timeout = 180
|
|
201
|
+
OptionParser.new do |cli|
|
|
202
|
+
cli.on("--no-build") { build = false }
|
|
203
|
+
cli.on("-v", "--verbose") { @verbose_builds = true }
|
|
204
|
+
cli.on("--wait-timeout SECONDS", Integer) { |value| timeout = value }
|
|
205
|
+
end.parse!(args)
|
|
206
|
+
raise Error, "Unexpected arguments to up." unless args.empty? && timeout.positive?
|
|
207
|
+
|
|
208
|
+
prepare
|
|
209
|
+
@terminal.title("Starting #{project.config.name}")
|
|
210
|
+
return start_stack(docker, timeout) unless build
|
|
211
|
+
|
|
212
|
+
with_development_images { |prepared| start_stack(prepared, timeout) }
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def start_stack(prepared, timeout)
|
|
216
|
+
status = prepared.compose("up", "--no-build", "-d", "--wait", "--wait-timeout", timeout.to_s)
|
|
217
|
+
if status.zero?
|
|
218
|
+
@terminal.status("Development stack is ready.")
|
|
219
|
+
@terminal.table(project.development.http.filter_map do |entry|
|
|
220
|
+
host = entry.fetch("service")
|
|
221
|
+
output, _, ok = docker.read_compose("port", host, entry.fetch("port").to_s)
|
|
222
|
+
[host, "http://#{output.strip.lines.first.to_s.strip}"] if ok && !output.strip.empty?
|
|
223
|
+
end)
|
|
224
|
+
else
|
|
225
|
+
@terminal.status("Check startup with ship logs and ship doctor.", :warning)
|
|
226
|
+
end
|
|
227
|
+
status
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def development(command, args)
|
|
231
|
+
supported = COMMANDS["Development"].keys + %w[rails hanami]
|
|
232
|
+
raise Error, "Unknown command #{command.inspect}. Run ship help." unless supported.include?(command)
|
|
233
|
+
|
|
234
|
+
case command
|
|
235
|
+
when "down", "ps"
|
|
236
|
+
prepare unless project.app.file?(project.development.filename)
|
|
237
|
+
docker.compose(command, *args)
|
|
238
|
+
when "logs"
|
|
239
|
+
prepare unless project.app.file?(project.development.filename)
|
|
240
|
+
@terminal.title("#{project.config.name} · Logs") if @terminal.interactive?
|
|
241
|
+
docker.compose("logs", *args)
|
|
242
|
+
when "run"
|
|
243
|
+
flags = []
|
|
244
|
+
while %w[-e --env --verbose -v].include?(args.first) || args.first&.start_with?("--env=")
|
|
245
|
+
flag = args.shift
|
|
246
|
+
if %w[--verbose -v].include?(flag)
|
|
247
|
+
@verbose_builds = true
|
|
248
|
+
next
|
|
249
|
+
end
|
|
250
|
+
flags << flag
|
|
251
|
+
flags << (args.shift || raise(Error, "#{flag} requires a value.")) unless flag.include?("=")
|
|
252
|
+
end
|
|
253
|
+
args.shift if args.first == "--"
|
|
254
|
+
raise Error, "Provide a command to ship run." if args.empty?
|
|
255
|
+
|
|
256
|
+
prepare
|
|
257
|
+
run_once(project.config.app, *args, flags: flags, rebuild: true)
|
|
258
|
+
when "exec"
|
|
259
|
+
service, *argv = args
|
|
260
|
+
raise Error, "Usage: ship exec SERVICE COMMAND [ARGS…]" if argv.empty?
|
|
261
|
+
|
|
262
|
+
prepare unless project.app.file?(project.development.filename)
|
|
263
|
+
exec_service(service, *argv)
|
|
264
|
+
when "shell"
|
|
265
|
+
raise Error, "Usage: ship shell [SERVICE]" if args.length > 1
|
|
266
|
+
|
|
267
|
+
prepare unless project.app.file?(project.development.filename)
|
|
268
|
+
exec_service(args.first || project.config.app, "sh")
|
|
269
|
+
when "db" then database(args)
|
|
270
|
+
when "test" then test_suite(args)
|
|
271
|
+
when "npm", "pnpm", "yarn", "bun" then frontend(command, args)
|
|
272
|
+
else proxy(command, args)
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
def tty = @terminal.interactive? ? [] : ["-T"]
|
|
277
|
+
|
|
278
|
+
def with_development_images(*targets, rebuild: true, &action)
|
|
279
|
+
docker.with_development_images(*targets, terminal: @terminal, verbose: @verbose_builds, rebuild: rebuild, &action)
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def run_once(service, *command, flags: [], rebuild: false)
|
|
283
|
+
with_development_images(service, rebuild: rebuild) do |prepared|
|
|
284
|
+
prepared.compose("run", "--rm", *tty, *flags, service, *command)
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def exec_service(service, *command)
|
|
289
|
+
command = project.app.exec_command(command) if service == project.config.app
|
|
290
|
+
docker.compose("exec", *tty, service, *command)
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
def database(args)
|
|
294
|
+
raise Error, "Usage: ship db [INSTANCE]" if args.length > 1
|
|
295
|
+
|
|
296
|
+
prepare unless project.app.file?(project.development.filename)
|
|
297
|
+
name = args.first
|
|
298
|
+
entry = project.services.database(name)
|
|
299
|
+
entry ||= project.services.instances.find { |service| service.key == name && service.name.nil? } if name
|
|
300
|
+
raise Error, "No matching database. Run ship init to select one." unless entry
|
|
301
|
+
if entry.key == "sqlite"
|
|
302
|
+
return docker.compose("exec", *tty, project.config.app, "sh", "-c", 'exec sqlite3 "$SHIP_SQLITE_PATH"')
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
command = entry.model(false, project.config)["shell"]
|
|
306
|
+
raise Error, "#{entry.label} has no database console." unless command
|
|
307
|
+
|
|
308
|
+
docker.compose("exec", *tty, entry.host, *command)
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
def proxy(command, args)
|
|
312
|
+
prefix = project.app.console[command]
|
|
313
|
+
raise Error, "#{command} is unavailable for this framework." unless prefix
|
|
314
|
+
|
|
315
|
+
prepare unless command == "bundle" && project.app.file?(project.development.filename)
|
|
316
|
+
running, _, ok = docker.read_compose("ps", "--status", "running", "-q", project.config.app)
|
|
317
|
+
if ok && !running.strip.empty?
|
|
318
|
+
exec_service(project.config.app, *prefix, *args)
|
|
319
|
+
else
|
|
320
|
+
run_once(project.config.app, *prefix, *args)
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
def frontend(command, args)
|
|
325
|
+
entry = project.services.instances.find { |service| service.key == "node" }
|
|
326
|
+
raise Error, "Select Node.js with ship init --frontend node." unless entry || project.app.node?
|
|
327
|
+
|
|
328
|
+
prepare
|
|
329
|
+
service = entry ? entry.host : project.config.app
|
|
330
|
+
running, _, ok = docker.read_compose("ps", "--status", "running", "-q", service)
|
|
331
|
+
if ok && !running.strip.empty?
|
|
332
|
+
exec_service(service, command, *args)
|
|
333
|
+
else
|
|
334
|
+
run_once(service, command, *args)
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
def package_manager(args)
|
|
339
|
+
manager, version, extra = args
|
|
340
|
+
raise Error, "Usage: ship package-manager npm|pnpm|yarn|bun [VERSION]" unless %w[npm pnpm yarn bun].include?(manager) && !extra
|
|
341
|
+
|
|
342
|
+
data = project.config.data.merge("packageManager" => manager)
|
|
343
|
+
version ? data["packageManagerVersion"] = version : data.delete("packageManagerVersion")
|
|
344
|
+
changed = Project.new(Config.new(project.root, data)).regenerate(write_config: true)
|
|
345
|
+
@terminal.title("Frontend package manager")
|
|
346
|
+
@terminal.table([["Manager", manager], *changed.map { |file, action| [file, action, :warning] }])
|
|
347
|
+
0
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
def test_suite(args)
|
|
351
|
+
prepare
|
|
352
|
+
browser = project.services.instances.find { |entry| entry.key == "cypress" }
|
|
353
|
+
if browser
|
|
354
|
+
status = with_development_images(project.config.app, rebuild: false) do |prepared|
|
|
355
|
+
prepared.compose("up", "--no-build", "-d", "--wait", project.config.app)
|
|
356
|
+
end
|
|
357
|
+
return status unless status.zero?
|
|
358
|
+
|
|
359
|
+
run_once(browser.host, "run", *args, flags: ["--entrypoint", "cypress"])
|
|
360
|
+
elsif project.app.framework == "rails"
|
|
361
|
+
run_once(project.config.app, *project.app.console.fetch("rails"), "test", *args, flags: ["-e", "RAILS_ENV=test"])
|
|
362
|
+
else
|
|
363
|
+
run_once(project.config.app, "bundle", "exec", "rake", "test", *args, flags: ["-e", "#{project.app.env_name}=test"])
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
def inspect_project(command, args)
|
|
368
|
+
options = {}
|
|
369
|
+
OptionParser.new do |cli|
|
|
370
|
+
cli.on("--json") { options[:json] = true }
|
|
371
|
+
cli.on("--compose") { options[:compose] = true } if command == "check"
|
|
372
|
+
end.parse!(args)
|
|
373
|
+
raise Error, "Unexpected diagnostic arguments." unless args.empty?
|
|
374
|
+
|
|
375
|
+
rows = diagnostics(command, options)
|
|
376
|
+
if options[:json]
|
|
377
|
+
@terminal.output.puts(JSON.pretty_generate({ "ok" => rows.none? { |_, _, kind| kind == :error },
|
|
378
|
+
"checks" => rows.map { |name, message, kind| { "name" => name, "message" => message, "status" => kind.to_s } } }))
|
|
379
|
+
else
|
|
380
|
+
@terminal.title(command == "doctor" ? "Ruby Ship Doctor" : "Ruby Ship Check")
|
|
381
|
+
@terminal.table(rows)
|
|
382
|
+
if rows.any? { |_, _, kind| kind == :error }
|
|
383
|
+
@terminal.status("Resolve the issues above.", :error)
|
|
384
|
+
else
|
|
385
|
+
@terminal.status(command == "doctor" ? "Diagnostics complete." : "Configuration is valid.")
|
|
386
|
+
end
|
|
387
|
+
end
|
|
388
|
+
rows.any? { |_, _, kind| kind == :error } ? 1 : 0
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
def diagnostics(command, options)
|
|
392
|
+
issues = project.check
|
|
393
|
+
rows = issues.empty? ? [["Configuration", "Valid", :ok]] : issues.map { |message| ["Configuration", message, :error] }
|
|
394
|
+
return rows unless command == "doctor" || options[:compose]
|
|
395
|
+
|
|
396
|
+
version, error, ok = docker.capture("docker", "compose", "version", "--short")
|
|
397
|
+
rows << ["Docker Compose", ok ? version.strip : error.strip, ok ? :ok : :error]
|
|
398
|
+
if command == "doctor" && ok
|
|
399
|
+
version, error, available = docker.capture("docker", "info", "--format", "{{.ServerVersion}}")
|
|
400
|
+
rows << ["Docker daemon", available ? version.strip : error.strip, available ? :ok : :error]
|
|
401
|
+
end
|
|
402
|
+
if project.app.file?(project.development.filename) && ok
|
|
403
|
+
_, error, valid = docker.read_compose("config", "--quiet")
|
|
404
|
+
rows << ["Development stack", valid ? "Valid" : error.strip, valid ? :ok : :error]
|
|
405
|
+
if command == "doctor" && valid && available
|
|
406
|
+
services, error, running = docker.read_compose("ps", "--format", "json")
|
|
407
|
+
statuses = services.lines.filter_map do |line|
|
|
408
|
+
value = JSON.parse(line)
|
|
409
|
+
[value].flatten
|
|
410
|
+
rescue JSON::ParserError
|
|
411
|
+
nil
|
|
412
|
+
end.flatten
|
|
413
|
+
rows << ["Services", running ? (statuses.empty? ? "Stopped" : "#{statuses.length} listed") : error.strip, running ? :muted : :warning]
|
|
414
|
+
statuses.each { |value| rows << [value.fetch("Service"), [value["State"], value["Health"]].reject { |field| field.to_s.empty? }.join(" · "), value["Health"] == "unhealthy" ? :error : :ok] }
|
|
415
|
+
end
|
|
416
|
+
elsif ok
|
|
417
|
+
rows << ["Development stack", "Run ship init to generate the stack.", :warning]
|
|
418
|
+
end
|
|
419
|
+
rows
|
|
420
|
+
rescue Error => error
|
|
421
|
+
error.message.lines.map { |line| ["Configuration", line.strip, :error] }
|
|
422
|
+
end
|
|
423
|
+
|
|
424
|
+
def production(command, args)
|
|
425
|
+
require_relative "release"
|
|
426
|
+
Release.new(project, @terminal).run(command, args, verbose: @verbose_builds)
|
|
427
|
+
end
|
|
428
|
+
end
|
|
429
|
+
end
|