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.

If you publish your template to the marketplace, you can even collect a kickback from the usage of it!

How to Create a Template

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

Starting from Scratch

To create a template from scratch, head over to the template composer then add and configure your services:

  • Add a service by clicking the Add New button in the top right-hand corner, or through the command palette (CMD + K -> + New Service)

  • Select the service source (GitHub repo or Docker Image)

  • Configure the service variables and settings

    Template Editor
  • Once you've added your services, click Create Template

  • You will be taken to your templates page where you can copy the template URL to share with others

Note that your template will not be available on the template marketplace, nor will be eligible for a kickback, until you publish it.

Private Repo Support

It's now possible to specify a private GitHub repo when creating a template.

This feature is intended for use among Teams and Organizations. Users supporting a subscriber base may also find this feature helpful to distribute closed-source code.

To deploy a template that includes a private repo, look for the GitHub panel in the Account Integrations section of General Settings. Then select the Edit Scope option to grant Railway access to the desired private repos.

Create a template from a private GitHub repositories

If you do not see the Edit Scope option, you may still need to connect GitHub to your Railway account.

Convert a Project Into a Template

You can also convert an existing project into a ready-made Template for other users.

  • From your project page, click Settings in the right-hand corner of the canvas
  • Scroll down until you see Generate Template from Project
  • Click Create Template
Generate template from project
  • You will be taken to the template composer page, where you should confirm the settings and finalize the template creation

Configuring Services

Configuring services using the template composer is very similar to building a live project in the canvas.

Once you add a new service and select the source, you can configure the following to enable successful deploys for template users:

Specifying a Branch

To specify a particular GitHub branch to deploy, simply enter the full URL to the desired branch in the Source Repo configuration. For example -

  • This will deploy the main branch: https://github.com/railwayapp-templates/postgres-ssl
  • This will deploy the new branch: https://github.com/railwayapp-templates/postgres-ssl/tree/new

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 template variable functions are executed and the result replaces the ${{ ... }} in the variable.

Use template variables to generate a random password for a database, or to generate a random string for a secret.

The current template variable functions are:

  1. secret(length?: number, alphabet?: string): Generates a random secret (32 chars by default).

    **Tip:**You can generate Hex or Base64 secrets by constructing the appropriate alphabet and length.

    • openssl rand -base64 16${{secret(22, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/")}}==
    • openssl rand -base64 32${{secret(43, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/")}}=
    • openssl rand -base64 64${{secret(86, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/")}}==
    • openssl rand -hex 16${{secret(32, "abcdef0123456789")}}
    • openssl rand -hex 32${{secret(64, "abcdef0123456789")}}
    • openssl rand -hex 64${{secret(128, "abcdef0123456789")}}
  2. 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.

Account templates page

Edit this file on GitHub