Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Railway 9 min read How-to mediumAdept

Manually Optimize Deployments on Railway

Deploying a FastAPI app on Railway three ways shows large speed differences: the default Nixpacks builder took 1m27s, a slim-based custom Dockerfile took 15 seconds, and pulling a pre-built image from Docker Hub took 6 seconds. Dockerfile size tips include slim/alpine base images, multi-stage builds, fewer layers and .dockerignore. The setup is then automated with two GitHub Actions workflows: one builds and pushes the image to Docker Hub on push to main, and a second triggers a Railway CLI redeploy when the first completes.

Assumes: DockerfilesGitHub Actions basics

Related posts

  • Why We’re Moving on From Nix

    Railway mediumAdept

    Railway replaced its Nix-based builder Nixpacks with Railpack, a Go rewrite that generates BuildKit LLB graphs directly instead of linear Dockerfiles. Nix's commit-pinned versioning made patch-level versions hard to support and turned default bumps into surprise build failures. A single /nix/store layer bloated images, and an injected deployment ID env var invalidated caches. Railpack uses Mise for exact version resolution, locks dependencies from successful builds, and runs an analyze → JSON plan → BuildKit graph pipeline. It also hashes only the env vars each step uses so layers cache correctly, and uses BuildKit secrets, cutting base image sizes by 38% (Node) to 77% (Python).

  • Implement a GitHub Actions Testing Suite

    Railway mediumAdept

    Walkthrough of building a CI test suite with GitHub Actions for a TypeScript Fastify API deployed on Railway. A /weekday route is added and covered with Vitest integration tests. A workflow runs on PRs and pushes to main, building the app, starting it in the background, then running the tests. Branch rulesets make the passing check required before merge, and Railway's 'wait for CI' setting stops failing commits from auto-deploying. Closing notes point to concurrency, matrix builds and caching as ways to scale the pipeline.

  • Working with NX, Railway and CI/CD

    Railway mediumAdept

    A GitHub Actions workflow can deploy only the NX monorepo apps affected by a push to Railway, replacing Railway's built-in GitHub trigger. The setup sets NIXPACKS_NX_APP_NAME, creates one Railway environment and project token per branch, and stores the tokens as GitHub secrets named RAILWAY_TOKEN__<project>_<environment>. On each push the workflow works out a base commit that survives force pushes, then lints and builds the affected projects. A bash script uses `nx print-affected` to find the affected apps, looks up each app's token from a dumped secrets JSON file, and runs `railway up --detach`. Dumping the secrets to a file is flagged as risky in public repos, and `--detach` keeps long container builds from using up GitHub Actions minutes.

  • How to Deploy and Scale Docker Containers on Railway in 2026

    Railway mediumAdept

    Docker containers on Railway can be deployed either by having Railway build from a Dockerfile (via BuildKit with cache mounts, configurable with RAILWAY_DOCKERFILE_PATH) or by pulling a pre-built image from a registry such as Docker Hub, GHCR or ECR Public. Services must bind to 0.0.0.0 (or :: for the IPv6 private network) and honor the PORT variable. Layer ordering, .dockerignore and multi-stage builds keep rebuilds cheap. Scaling is vertical via resource limits or horizontal via replicas across regions, but services with Volumes cannot use replicas, so state belongs in databases or object storage. Billing is usage-based ($10/GB RAM, $20/vCPU per month), and a small always-on API works out to roughly $6.50/month.

  • Using GitLab CI/CD with Railway

    Railway mediumAdept

    Deploying to Railway from GitLab CI/CD comes down to a project token plus a small job that runs the Railway CLI. Create a project token in the Railway project settings and store it as a secret GitLab CI/CD variable (RAILWAY_TOKEN). A minimal .gitlab-ci.yml then uses the ghcr.io/railwayapp/cli image to run `railway up --service=$SVC_ID` on pushes to the default branch, while Railway's own infrastructure does the build. Teams can instead build artifacts in GitLab CI and deploy them with the CLI. The token must stay secret, but the service ID can be exposed safely.

The quest for software engineering knowledge.

Look:
Layout: