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), skippingapt-get updateand package resolution entirely when theAptfileis unchanged - installs Ruby with rv — precompiled, in seconds — using the version pinned in
.ruby-version - installs Node.js pinned by
.node-version(generated byrails new), and the exact Yarn release pinned bypackage.json'spackageManagerfield — no unpinned defaults - runs
yarn installexactly once, with a persistent cache, beforeassets: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):
rails g trek:install:scalingoThen configure the Scalingo app's environment, pinning the buildpack to a release through its archive:
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
#tagsuffix: Scalingo reads#refonBUILDPACK_URLas a branch, so…/trek-buildpack#v0.1.0asks for a branch namedv0.1.0, which does not exist, and the build fails withfail to download and extract the custom buildpack: Invalid status code: 404 Not Found. The.tar.gzform 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:
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
| Variable | Effect |
|---|---|
TREK_BUILDPACK_RUNTIME_NODE=1 | Ship Node.js in the image (only if the app runs JavaScript at runtime, e.g. execjs) |
TREK_BUILDPACK_PRUNE_SOURCEMAPS=1 | Also remove .map files from the compiled assets |
Migrating an existing app
Apps deployed with the stock .buildpacks (apt + ruby) migrate in three steps:
- delete
.buildpacks(re-runningrails g trek:install:scalingodoes it) and check that.node-versionexists — apps generated withrails new -j esbuildhave it - set
BUILDPACK_URLas above, and mapDATABASE_URLif the app doesn't read it yet - 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.