Skip to content

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

Railway 2 min read How-to mediumAdept

Using GitLab CI/CD with Railway

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.

Related posts

  • Using Github Actions with Railway

    Railway mediumAdept

    Railway deployments can be driven from GitHub Actions instead of the built-in branch-push trigger by creating a project token, storing it as a repository secret (RAILWAY_TOKEN), and running `railway up --service=<id>` inside the official Railway CLI container. A sample workflow triggers on pushes to main, checks out the code and uploads it to Railway. The token must stay secret, but the service ID can be passed openly. The same token approach also works for tasks like running database migrations before deploy or managing pull requests.

  • 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.

  • Cron Jobs with Django and GitHub Actions

    Railway mediumAdept

    Scheduled Django management commands can run against a Railway project by using a GitHub Actions workflow on a cron schedule. The workflow checks out the repo, installs the Railway CLI via npm, and uses `railway run --service` with a project-scoped RAILWAY_TOKEN secret to install requirements and execute `python manage.py my_command` in the service's environment. An August 2023 update notes that Railway now supports cron jobs natively, which may be the better option.

  • Manually Optimize Deployments on Railway

    Railway mediumAdept

    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.

  • Deploy autoscaling services, AI Workflow automation, and LLM APIs Without Kubernetes

    Railway mediumAdept

    Many teams adopting Kubernetes only need to build containers, expose endpoints, scale and observe services, and a managed container platform like Railway can cover those needs with far less operational overhead. Each Kubernetes building block is mapped to a platform feature: Ingress plus cert-manager becomes automatic TLS and private hostnames, Secrets become reference variables that propagate on rotation, CI/CD plus ArgoCD becomes git-push deploys with PR preview environments, and the HPA metrics stack becomes dashboard-set replicas. The tradeoff is lost control over scheduling, custom readiness probes and custom scaling metrics, which still justifies Kubernetes at larger scale.

The quest for software engineering knowledge.

Look:
Layout: