Create a Template

Creating a template allows you to capture your infrastructure in a reusable and distributable format. By defining services, environment configuration, network settings, etc., you lay the foundation for others to deploy the same software stack with the click of a button.

How to Create a Template

You can either create a template from scratch or base it off of an existing project.

Starting from Scratch

The Railway button page. allows you to create templates to offer a 1-click deploy on Railway experience.

Services within a template can be deployed from any public Github repository, or directly from a Docker image in Docker Hub or Github Container Registry.

Template Editor

Simply name the template, add and configure the services and click Create Template.

Convert a Project into a Template

You can also convert an existing project into a template by heading over to your project settings page. We will automatically identify and add all the required services.

Generate template from project

Within the Project Settings, you can convert your project into a ready-made Template for other users by pressing the Create Template button.

Once the template has been generated, you will be taken to the template creation page to confirm the settings and finalize the template creation.

Configuring Services

Whether you are building from scratch or have started from an existing project, once you are on the template creation page, you will see various configuration options for each service added to your template.

In addition to the Source, you can configure the following fields to enable successful deploys for template users:

Specifying a Branch

When adding services to a template, you can enter a url to a GitHub repo's branch to have a user clone that instead of the main branch.

Template Variable Functions

Template variable functions allow you to dynamically generate variables (or parts of a variable) on demand when the template is deployed.

Template Variable Functions

When a template is deployed, all functions are executed and the result replaces the ${{ ... }} in the variable. For example, you can use them to generate a random password for a database, or to generate a random string for a secret. You can see an example of what the variable will look like after all the functions execute when creating the template.

The current template variable functions are:

  • secret(length?: number, alphabet?: string): Generates a random secret (32 chars by default). You can generate random Hex or Base64 secrets by passing the appropriate alphabet.

    • Base64: secret(32, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/')
    • Hex: secret(32, '0123456789ABCDEF')
  • randomInt(min?: number, max?: number): Generates a random integer between min and max (defaults to 0 and 100)

Managing your Templates

You can see all of your templates on your Account's Template page. Templates are separated into Personal and Published templates. You can edit, publish/unpublish and delete templates whenever you'd like!

Account templates page

Edit this file on GitHub