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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4a2ccb7e42208811438168c7a94266dd04820dc05f88273c05eae6fa36a20e4b
4
+ data.tar.gz: a8db02fc5ec19ade7fc332e1e4a3c15ada5bc6097c9ed6d91d984ac87e5d3c17
5
+ SHA512:
6
+ metadata.gz: 73488032f015a306ff580b54b8e8b73806833bd032e7784aa817c960de3722719619f42ee28ded72b5be527fe9692cae3dd43897a7d05639cf5acd6bd4a35a09
7
+ data.tar.gz: bbb540f5e2660a49fe74f2f16095d6358c11eb051d1a21cbccfd384d340ea77bea6cc27b335f4d60811fc30a74ddc22f2d3c79d9991fbca0db90cc3baea548ea
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ship contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # Ruby Ship
2
+
3
+ [![Ruby Ship CI](https://github.com/ship-ecosystem/ruby-ship/actions/workflows/ci.yml/badge.svg?branch=main&event=push)](https://github.com/ship-ecosystem/ruby-ship/actions/workflows/ci.yml)
4
+
5
+ Set up a Docker development environment for a Ruby app and export production
6
+ releases that follow the shared [Ship specification](https://github.com/ship-ecosystem/spec).
7
+
8
+ ## Quick start
9
+
10
+ Ruby Ship requires Ruby 3.3 or later on the host and Docker Engine with the
11
+ Compose plugin. The app needs a `Gemfile`, a `Gemfile.lock`, and a `config.ru`.
12
+
13
+ Build and install the gem from this repository:
14
+
15
+ ```sh
16
+ git clone https://github.com/ship-ecosystem/ruby-ship.git
17
+ cd ruby-ship
18
+ gem build ruby-ship.gemspec
19
+ gem install --user-install ruby-ship-0.1.0.gem
20
+ export PATH="$(ruby -rrubygems -e 'print Gem.user_dir')/bin:$PATH"
21
+ ```
22
+
23
+ Then, from your app directory:
24
+
25
+ ```sh
26
+ ship init
27
+ ship up
28
+ ship logs --follow
29
+ ```
30
+
31
+ All Ship packages use the `ship` executable name. If you have another Ship
32
+ package installed, run `ruby /path/to/ruby-ship/exe/ship init` from your app
33
+ directory to select Ruby Ship explicitly.
34
+
35
+ Use the arrow keys and Enter in the setup dialog. Press Space to toggle service
36
+ categories and published ports, Ctrl+U to go back, or Ctrl+C to cancel.
37
+ Optional text fields can be left blank. `ship init --defaults` uses the app's
38
+ detected settings and any flags you provide.
39
+
40
+ Use **Processes to run** to enable a suggested worker or add a custom worker,
41
+ scheduler, or HTTP service. An HTTP process can declare a container port,
42
+ health check, and public URL setting. Use **Deploy commands** for jobs that
43
+ run once per release, such as database migrations.
44
+
45
+ Choose host ports separately for development and production. Development
46
+ binds to localhost. Production ports may be public, so leave them clear
47
+ when a reverse proxy reaches the app over the Docker network. Enter `0` for
48
+ an automatically assigned host port. Ship saves the selections in
49
+ `ship.json` and the chosen host port numbers in the matching environment file.
50
+
51
+ Image builds show a brief progress display and print the full log on failure.
52
+ Use `ship --verbose up` or `ship --verbose run ...` to stream the build log.
53
+
54
+ ## Ruby frameworks and runtimes
55
+
56
+ | Framework | Development entry point | Production |
57
+ | --- | --- | --- |
58
+ | Ruby on Rails | `bin/rails server` with Puma | Puma or Puma with Thruster |
59
+ | Hanami | `hanami server` | Puma with `config.ru` |
60
+ | Sinatra, Roda, Generic Rack | Puma with `config.ru` | Puma with `config.ru` |
61
+
62
+ Falcon is available for Rack apps that have `falcon` in their bundle. Ship keeps
63
+ an exact Ruby version from `.ruby-version` or the lockfile. Without an exact
64
+ version, it uses the package's patched release for the selected branch. It
65
+ installs the Bundler version recorded in `Gemfile.lock`. Include the deployment
66
+ platform in the lockfile if it's absent, for example
67
+ `bundle lock --add-platform x86_64-linux aarch64-linux`.
68
+
69
+ `ship bundle`, `ship ruby`, `ship rake`, `ship rails`, and `ship hanami` run
70
+ commands under the app's bundle. Run `ship rails db:prepare` to initialize a Rails
71
+ database in development. For production, use
72
+ `ship init --deploy-command 'bundle exec rails db:prepare'` to attach the
73
+ database preparation to each deploy.
74
+
75
+ ## Services
76
+
77
+ | Group | Providers |
78
+ | --- | --- |
79
+ | Database | PostgreSQL, MySQL, MariaDB, MongoDB, SQL Server, SQLite, ClickHouse |
80
+ | Cache | Redis, Valkey, Memcached |
81
+ | Message broker | RabbitMQ |
82
+ | Local mail | Mailpit |
83
+ | Search | Meilisearch, Elasticsearch, Typesense |
84
+ | Object storage | Garage, SeaweedFS, RustFS, Silo |
85
+ | Real-time messaging | Centrifugo, Mercure, AnyCable for Rails |
86
+ | Browser testing | Selenium, Playwright, Cypress |
87
+ | Frontend tooling | Node.js with npm, pnpm, Yarn, or Bun |
88
+
89
+ SQLite uses a named volume at `/app/storage`. Rails apps generated with
90
+ SQLite already use that directory. For other apps, set the database path from
91
+ `SHIP_SQLITE_PATH`. For supported relational providers, Rails receives a
92
+ `DATABASE_URL` assembled from the shared `DB_*` settings when the project has
93
+ not set its own URL. Keep your application's own connection and storage config
94
+ for other providers.
95
+ Bundle the adapter for your primary Rails database before starting the stack.
96
+ For PostgreSQL, run `bundle add pg` and use `ship rails db:prepare`.
97
+
98
+ Choose ClickHouse in the Database picker. To use it alongside another
99
+ database, add it through **Other named services** or the command line.
100
+
101
+ ```sh
102
+ ship init --defaults --database postgres --add database:clickhouse:warehouse
103
+ ship up
104
+ ship db warehouse
105
+ ```
106
+
107
+ The Ruby service receives `CLICKHOUSE_HTTP_URL`, `CLICKHOUSE_HOST`,
108
+ `CLICKHOUSE_PORT`, `CLICKHOUSE_DB`, `CLICKHOUSE_USER`, and
109
+ `CLICKHOUSE_PASSWORD`. The HTTP and native ports are 8123 and 9000, respectively.
110
+ ClickHouse stays on the Compose network unless you include
111
+ `clickhouse:8123` or `clickhouse:9000` in `portPublishing` for that environment.
112
+ Use `clickhouse-warehouse` as the service name for the example above. That
113
+ instance has separate storage and uses variables prefixed with `WAREHOUSE_`.
114
+ Set its `WAREHOUSE_CLICKHOUSE_PASSWORD` in `.env.production` before exporting
115
+ settings.
116
+
117
+ Ship detects the Solid Queue, GoodJob, and Sidekiq gems and can add their
118
+ worker processes to the stack. Rails owns the Solid Queue, Solid Cache, and
119
+ Solid Cable configuration and migrations. For a Solid Queue worker in
120
+ development, enable the adapter in Rails, configure its queue database, and
121
+ run `ship rails db:prepare` before starting the worker. A Redis or Valkey instance named
122
+ `sidekiq` supplies `SIDEKIQ_REDIS_URL`, which the app can use in its Sidekiq
123
+ client and server configuration. AnyCable uses Rails HTTP RPC at
124
+ `/_anycable`. Configure the Rails Action Cable adapter and client to use AnyCable
125
+ and set the production secret, public URL, and allowed origins.
126
+
127
+ Select `ship init --frontend node` to use the development Node service. Use
128
+ `ship npm`, `ship pnpm`, `ship yarn`, or `ship bun` for the installed manager.
129
+ For production assets, use `ship init --node-assets`. Ship detects Rails asset
130
+ pipelines, and the lockfile selects the package manager unless you configure it
131
+ explicitly.
132
+
133
+ ## Files and customization
134
+
135
+ - `ship.json` describes the stack in the shared format. Use `additionalServices`
136
+ for named instances, `processes` for additional commands from the app image,
137
+ and `deployCommands` for one-off production commands.
138
+ - Ship regenerates the Compose files and `docker/ship/` templates. Add changes
139
+ in `docker-compose.override.yml` for development or
140
+ `docker-compose.production.override.yml` for production.
141
+ - `ship init` lists changes in `.env`, `.env.example`, `.env.production`, and
142
+ `.env.production.example`. It preserves custom settings and credentials,
143
+ refreshes generated service connections, and removes unused generated
144
+ defaults. The example files use blank placeholders for private values.
145
+ Use `build.publicEnv` for public build
146
+ inputs and `.ship-secrets/NAME` with `build.secrets` for temporary BuildKit
147
+ secrets. When enabled, `build.npmrc` uses `.ship-secrets/npmrc`.
148
+ - `ship check` validates configuration offline. Add `--compose` to validate
149
+ the generated development stack. `ship doctor` checks Docker and shows the
150
+ state of running services. Both accept `--json` for scripting.
151
+ - An explicit `extensions` entry can load a trusted local Ruby service
152
+ definition. See [the extension format](docs/extensions.md).
153
+
154
+ ## Production
155
+
156
+ ```sh
157
+ ship build
158
+ ship release --tag 1.0.0
159
+ ```
160
+
161
+ The release lands in `dist/ship/1.0.0`. It contains the Compose configuration,
162
+ built image archives and their checksums, digest-pinned registry references,
163
+ and a release manifest. Use `--no-env` to supply settings on the destination.
164
+ The release README includes image loading, deployment commands, and startup.
165
+
166
+ ## Verify changes
167
+
168
+ Run `ruby test/contract.rb` and `ruby test/terminal.rb` from this checkout.
169
+ With Docker and the sibling spec's Node dependencies installed, run
170
+ `test/docker-smoke.sh ../com.ship.spec` for an end-to-end Rack and ClickHouse
171
+ test that checks the config and the exported release against the spec.
172
+
173
+ Run `test/framework-smoke.sh rails` to scaffold and boot a disposable Rails
174
+ project, or substitute `hanami`, `sinatra`, or `roda`. This test uses Bundler
175
+ and RubyGems on the host to prepare the throwaway application.
@@ -0,0 +1,38 @@
1
+ # Service extensions
2
+
3
+ Add a project-relative Ruby file to `extensions` in `ship.json`. Ruby Ship
4
+ evaluates the selected file as trusted Ruby code on the host. The file returns
5
+ a hash with a `services` entry keyed by provider name. Existing provider names
6
+ are reserved for the built-in catalog.
7
+
8
+ ```ruby
9
+ {
10
+ "services" => {
11
+ "proxy-cache" => {
12
+ "group" => "proxy",
13
+ "label" => "Proxy cache",
14
+ "named" => true,
15
+ "development" => {
16
+ "compose" => {
17
+ "image" => "nginx:alpine",
18
+ "expose" => [80],
19
+ "volumes" => ["proxy-cache-shipseed_data:/var/cache/nginx"]
20
+ },
21
+ "environment" => { "SHIPSEED_PROXY_CACHE_URL" => "http://shiphostname" }
22
+ }
23
+ }
24
+ }
25
+ }
26
+ ```
27
+
28
+ Select it with `ship init --defaults --service proxy=proxy-cache`.
29
+ Provide a `production` entry with the same structure to include the provider
30
+ in production. A mode can also declare an argv `shell` and an `http` array
31
+ whose items contain `port`, `role`, `health`, and `urlSetting`. HTTP endpoints
32
+ are listed in releases and connected to configured external networks.
33
+
34
+ In service values, Ruby Ship substitutes `shiphostname` with the effective
35
+ Compose name, including renames. A resource name ending in `-shipseed`
36
+ receives the instance suffix and keeps that suffix across Compose renames.
37
+ Use `SHIPSEED_` at the start of an environment variable to prefix keys for
38
+ named instances. For the primary instance the prefix is empty.
data/exe/ship ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
3
+ require "ship"
4
+ exit Ship::CLI.new.run(ARGV)
@@ -0,0 +1,123 @@
1
+ require "rubygems"
2
+ require_relative "config"
3
+
4
+ module Ship
5
+ class Application
6
+ RUBY_PATCHES = { "3.3" => "3.3.14", "3.4" => "3.4.13", "4.0" => "4.0.10" }.freeze
7
+ FRAMEWORKS = { "rails" => "Ruby on Rails", "hanami" => "Hanami", "sinatra" => "Sinatra",
8
+ "roda" => "Roda", "rack" => "Generic Rack" }.freeze
9
+ SERVERS = { "puma" => "Puma", "thruster" => "Puma with Thruster", "falcon" => "Falcon" }.freeze
10
+ ENTRYPOINT = ["ruby", "/usr/local/bin/ship-entrypoint"].freeze
11
+ RAILS_DATABASE_GEMS = { "postgres" => "pg", "mysql" => "mysql2", "mariadb" => "mysql2",
12
+ "sqlserver" => "activerecord-sqlserver-adapter" }.freeze
13
+
14
+ attr_reader :config, :lockfile, :gems, :bundler, :ruby
15
+
16
+ def initialize(config)
17
+ @config = config
18
+ @lockfile = read("Gemfile.lock")
19
+ @gems = lockfile.scan(/^ {4}([a-zA-Z0-9_-]+) \([^)\n]+\)\r?$/).flatten.uniq
20
+ @bundler = lockfile[/^BUNDLED WITH\r?\n\s+(\d+\.\d+\.\d+)\r?$/, 1]
21
+ declared = read(".ruby-version").strip.delete_prefix("ruby-")
22
+ locked = lockfile[/^RUBY VERSION\r?\n\s+ruby (\d+\.\d+\.\d+)(?:p-?\d+)?/, 1]
23
+ requested = declared.empty? ? locked || "3.4" : declared
24
+ branch = requested[/\A\d+\.\d+/]
25
+ @ruby = RUBY_PATCHES[branch]
26
+ @ruby = requested if @ruby && /\A\d+\.\d+\.\d+\z/.match?(requested)
27
+ end
28
+
29
+ def framework
30
+ config.framework || detect_framework
31
+ end
32
+
33
+ def detect_framework
34
+ return "rails" if file?("bin/rails") && file?("config/application.rb")
35
+ return "hanami" if file?("config/app.rb") && gem?("hanami")
36
+ %w[sinatra roda].find { |name| gem?(name) } || "rack"
37
+ end
38
+
39
+ def gem?(name) = gems.include?(name)
40
+ def sqlite? = config.services["database"] == "sqlite"
41
+ def anycable_available? = framework == "rails" && (gem?("anycable-rails") || gem?("anycable-rails-core"))
42
+ def assets? = framework == "rails" && (gem?("propshaft") || gem?("sprockets-rails"))
43
+ def node? = config.data.fetch("nodeAssets", file?("package.json") && (gem?("jsbundling-rails") || gem?("cssbundling-rails") || gem?("vite_rails")))
44
+ def health_path
45
+ return unless framework == "rails"
46
+
47
+ route = read("config/routes.rb")[/^\s*get\s+["'](\/?[a-zA-Z0-9_\/-]+)["']\s*(?:,\s*to:|=>)\s*["']rails\/health#show["']/, 1]
48
+ "/#{route.delete_prefix('/')}" if route
49
+ end
50
+ def env_name = framework == "rails" ? "RAILS_ENV" : framework == "hanami" ? "HANAMI_ENV" : "RACK_ENV"
51
+
52
+ def missing_database_gem(provider)
53
+ return unless framework == "rails" && gem?("activerecord") && file?("config/database.yml")
54
+
55
+ adapter = RAILS_DATABASE_GEMS[provider]
56
+ adapter if adapter && !gem?(adapter)
57
+ end
58
+
59
+ def exec_command(command)
60
+ framework == "rails" ? [*ENTRYPOINT, *command] : command
61
+ end
62
+
63
+ def problems
64
+ issues = []
65
+ issues << "Gemfile is missing. Run Ship in the Ruby application directory." unless file?("Gemfile")
66
+ issues << "Gemfile.lock must record a stable BUNDLED WITH version. Run bundle lock first." unless bundler
67
+ issues << "Use a supported MRI Ruby branch: #{RUBY_PATCHES.keys.join(', ')}." unless ruby
68
+ issues << "Unknown framework #{framework}." unless FRAMEWORKS.key?(framework)
69
+ issues << "Unknown server #{config.server}." unless SERVERS.key?(config.server)
70
+ issues << "Set up a config.ru Rack entry point." unless file?("config.ru")
71
+ issues << "The Rails adapter requires bin/rails and config/application.rb." if framework == "rails" && !(file?("bin/rails") && file?("config/application.rb"))
72
+ %w[hanami sinatra roda].each do |name|
73
+ issues << "Check that the #{name} gem is in Gemfile.lock." if framework == name && !gem?(name)
74
+ end
75
+ needed = config.server == "falcon" ? ["falcon"] : ["puma"]
76
+ needed << "thruster" if config.server == "thruster"
77
+ needed.each { |name| issues << "Add #{name} to the application bundle and update Gemfile.lock." unless gem?(name) }
78
+ issues << "Thruster is a Rails production server profile." if config.server == "thruster" && framework != "rails"
79
+ issues
80
+ end
81
+
82
+ def command(production)
83
+ port = config.port.to_s
84
+ return ["bundle", "exec", "falcon", "serve", "--bind", "http://0.0.0.0:#{port}"] if config.server == "falcon"
85
+
86
+ puma = ["bundle", "exec", "puma", "-b", "tcp://0.0.0.0:#{port}", "config.ru"]
87
+ if production && config.server == "thruster"
88
+ return ["bundle", "exec", "thrust", "bundle", "exec", "puma", "-b", "tcp://127.0.0.1:#{thruster_target}", "config.ru"]
89
+ end
90
+ return ["bundle", "exec", "ruby", "bin/rails", "server", "-b", "0.0.0.0", "-p", port] if !production && framework == "rails"
91
+ if !production && framework == "hanami"
92
+ flags = file?("Guardfile") && gem?("hanami-reloader") ? [] : ["--no-code-reloading"]
93
+ return ["bundle", "exec", "hanami", "server", "--host", "0.0.0.0", "--port", port, *flags]
94
+ end
95
+
96
+ puma
97
+ end
98
+
99
+ def thruster_target = config.port == 3001 ? 3002 : 3001
100
+
101
+ def console
102
+ commands = { "bundle" => ["bundle"], "ruby" => ["bundle", "exec", "ruby"],
103
+ "rake" => ["bundle", "exec", "rake"] }
104
+ commands["rails"] = ["bundle", "exec", "ruby", "bin/rails"] if framework == "rails"
105
+ commands["hanami"] = ["bundle", "exec", "hanami"] if framework == "hanami"
106
+ commands
107
+ end
108
+
109
+ def workers
110
+ choices = {}
111
+ choices["solid-queue"] = ["bundle", "exec", "ruby", "bin/jobs", "start"] if gem?("solid_queue") && file?("bin/jobs")
112
+ choices["sidekiq"] = ["bundle", "exec", "sidekiq"] if gem?("sidekiq")
113
+ choices["good-job"] = ["bundle", "exec", "good_job", "start"] if gem?("good_job")
114
+ choices
115
+ end
116
+
117
+ def file?(path) = File.file?(File.join(config.root, path))
118
+
119
+ private
120
+
121
+ def read(path) = file?(path) ? File.read(File.join(config.root, path)) : ""
122
+ end
123
+ end