Skip to content

Deploying to Scalingo ​

Trek apps deploy to Scalingo with the dedicated trek-buildpack, a single buildpack that replaces the usual apt + ruby buildpack pair and knows how a Trek app is built.

What the buildpack does ​

  • installs the APT packages listed in Aptfile (image processing libraries, jemalloc), skipping apt-get update and package resolution entirely when the Aptfile is unchanged
  • installs Ruby with rv — precompiled, in seconds — using the version pinned in .ruby-version
  • installs Node.js pinned by .node-version (generated by rails new), and the exact Yarn release pinned by package.json's packageManager field — no unpinned defaults
  • runs yarn install exactly once, with a persistent cache, before assets:precompile
  • slims the shipped image: node_modules, Yarn caches and Node.js itself are dropped after the build, roughly halving the image size of a typical Trek app — faster deploys, restarts and scaling

Compared with the stock buildpacks, deploys typically go from around 3 minutes to about 1 minute 30 with a warm cache.

Set up the app ​

Generate the Scalingo files (an Aptfile and a Procfile with the web process and post-deploy migrations):

sh
rails g trek:install:scalingo

Then configure the Scalingo app's environment, pinning the buildpack to a release through its archive:

sh
scalingo --app <app> env-set BUILDPACK_URL=https://github.com/etaminstudio/trek-buildpack/archive/refs/tags/v0.1.0.tar.gz
scalingo --app <app> env-set 'DATABASE_URL=$SCALINGO_POSTGRESQL_URL'
scalingo --app <app> env-set RAILS_MASTER_KEY=$(cat config/master.key)

Pin through the archive, not a #tag suffix: Scalingo reads #ref on BUILDPACK_URL as a branch, so …/trek-buildpack#v0.1.0 asks for a branch named v0.1.0, which does not exist, and the build fails with fail to download and extract the custom buildpack: Invalid status code: 404 Not Found. The .tar.gz form above is downloaded as is and stays pinned to the release.

Make sure config/database.yml reads DATABASE_URL in production — the section rails new generates targets a local socket with a password variable instead:

yml
production:
  primary: &primary_production
    <<: *default
    url: <%= ENV["DATABASE_URL"] %>

Provision a PostgreSQL addon (scalingo --app <app> addons-add postgresql <plan>), push, and the app boots with RAILS_ENV, RAILS_LOG_TO_STDOUT and RAILS_SERVE_STATIC_FILES already set by the buildpack.

Options ​

VariableEffect
TREK_BUILDPACK_RUNTIME_NODE=1Ship Node.js in the image (only if the app runs JavaScript at runtime, e.g. execjs)
TREK_BUILDPACK_PRUNE_SOURCEMAPS=1Also remove .map files from the compiled assets

Migrating an existing app ​

Apps deployed with the stock .buildpacks (apt + ruby) migrate in three steps:

  1. delete .buildpacks (re-running rails g trek:install:scalingo does it) and check that .node-version exists — apps generated with rails new -j esbuild have it
  2. set BUILDPACK_URL as above, and map DATABASE_URL if the app doesn't read it yet
  3. deploy — the first build fills the caches, the next ones benefit from them

The buildpack's README details the cache layout and the Aptfile syntax.

Released under the MIT License.