Railpack Build Integration#
Overview#
Railpack is one of six build strategies supported by Dokploy (alongside nixpacks, dockerfile, heroku_buildpacks, paketo_buildpacks, and static). It is selected via the application's buildType field and dispatched by getBuildCommand() in packages/server/src/utils/builders/index.ts. The entire Railpack workflow is encapsulated in a single bash script returned by getRailpackCommand() in packages/server/src/utils/builders/railpack.ts.
Configuration#
Two application fields drive Railpack behavior:
railpackVersion— defaults to"0.15.4"in both the database schema and frontend Zod validation . The UI offers a predefined version dropdown (RAILPACK_VERSIONS) plus a free-text input for custom versions.cleanCache— whentrue, injects ananoid(10)value as thecache-keybuild arg to force Docker layer cache invalidation .
Build Workflow#
getRailpackCommand() generates a self-contained bash script executed in the deployment pipeline. The script runs three phases in sequence:
1. Install & Prepare#
export RAILPACK_VERSION=<version>
bash -c "$(curl -fsSL https://railpack.com/install.sh)"
docker buildx create --name <builderName> --driver docker-container || true
railpack prepare <buildDir> --plan-out <buildDir>/railpack-plan.json --info-out <buildDir>/railpack-info.json [--env KEY=VALUE ...]
- Railpack is installed fresh from
railpack.com/install.shusing the pinnedrailpackVersion. - A dedicated
docker buildxbuilder instance namedrailpack-<appName>-<nanoid(6)>is created per build — this prevents race conditions across concurrent deployments . railpack prepareanalyzes the source directory and outputsrailpack-plan.jsonandrailpack-info.jsonto the build directory . Environment variables are passed via--envflags .
2. Build#
docker buildx build --builder <builderName> \
--build-arg secrets-hash=<sha256> \
[--build-arg cache-key=<nanoid>] \
--build-arg BUILDKIT_SYNTAX=ghcr.io/railwayapp/railpack-frontend:v<version> \
-f <buildDir>/railpack-plan.json \
--output type=docker,name=<appName> \
[--secret id=KEY,env=KEY ...] \
<buildDir>
Key details:
BUILDKIT_SYNTAX— specifies the Railpack BuildKit frontend image fromghcr.io/railwayapp/railpack-frontendat the pinned version, allowingrailpack-plan.jsonto be used directly as a Dockerfile .secrets-hash— a SHA-256 hash of all sorted environment variable strings, used for deterministic layer cache invalidation when secrets change .- Secrets injection — each env var is passed as
--secret id=KEY,env=KEY(BuildKit secrets) and pre-exported viaexport KEY=<shell-quoted-value>before thedocker buildx buildcall . Values are shell-quoted usingshell-quoteto prevent injection. - Output — the built image is loaded directly into the local Docker daemon as
type=docker,name=<appName>.
3. Cleanup#
Regardless of success or failure, docker buildx rm <builderName> removes the isolated builder instance . This prevents builder accumulation across repeated deployments.
Environment Variable Resolution#
Environment variables are resolved through a three-layer merge (service → project → environment) by prepareEnvironmentVariables and prepareEnvironmentVariablesForShell in packages/server/src/utils/docker/utils.ts. The shell-safe variant is used for --env flags in railpack prepare; the raw variant is parsed for BuildKit --secret args.
Call Sites#
getBuildCommand() is invoked from packages/server/src/services/application.ts in four contexts :
- Standard deploy (line 225)
- Rebuild (line 318)
- Preview deployments (line 443)
- Rollback (line 558)
If a registry is configured, getBuildCommand() appends an uploadImageRemoteCommand() after the build step.
Key Files#
| File | Purpose |
|---|---|
packages/server/src/utils/builders/railpack.ts | Bash script generation — the core logic |
packages/server/src/utils/builders/index.ts | Build strategy dispatcher (getBuildCommand) |
packages/server/src/db/schema/application.ts | Schema: railpackVersion and cleanCache field definitions |
packages/server/src/utils/docker/utils.ts | Environment variable resolution utilities |
apps/dokploy/components/dashboard/application/build/show.tsx | Frontend: RAILPACK_VERSIONS constant and UI version picker |
apps/dokploy/__test__/deploy/railpack.command.test.ts | Unit tests for command generation |