DocsGuides

Deploying your code

Deploy from a GitHub repository on every push, from your own machine with the flatlined CLI, or from an image, and describe your services in flatlined.yaml.

Ways to deploy

  • From GitHub: connect a repository to a project, and every push to its branch builds and deploys. Pull requests can get previews of their own.
  • From your machine: flatlined deploy uploads a folder, builds it and deploys it.
  • From an image: create a server from a Docker Hub image, or from one of your team's images, in the dashboard.

The first two read a flatlined.yaml at the root of your code to know what to build and run. Without one, a Dockerfile at the root builds a single service named app.

Deploy from GitHub

  1. Open the project's Settings and find Git.
  2. Connect GitHub and install the Flatlined app on the account or organization that owns the repository. You can give it access to only the repositories you choose.
  3. Pick the repository and the branch to deploy.

From then on, each push to that branch is fetched, built and deployed, one server per service in flatlined.yaml. If several pushes arrive close together, only the newest is deployed. Each commit gets a status on GitHub for each service, flatlined/<service>, linking to the server, so you can follow a deploy from the commit or the pull request.

A server deployed from a push shows the commit on its card in the project.

Deploy only what changed

In a repository with several services, list the paths each one depends on under deploy.watch. A push then rebuilds a service only when a changed file matches one of its globs:

flatlined.yaml
version: 1services:  api:    build:      context: api    deploy:      watch:        - "api/**"        - "shared/**"

A service that has no server yet, and any push that changes flatlined.yaml, deploys every service regardless.

Pull request previews

Turn on Preview pull requests under Git in the project's settings. Each pull request opened into the branch from the same repository then deploys to a project of its own, named <project>-pr-<number>, and is removed once the pull request closes. Pull requests from forks aren't previewed, and a project has at most 3 open previews at a time.

A preview runs code nobody has reviewed yet, so it never reads the project's secrets. Give previews their own under Preview secrets in the project's settings.

Deploy from your machine

Install the CLI:

Terminal
curl -fsSL https://api.flatlined.gg/cli/install.sh | sh

Create an API token in your team's settings with the Deploy preset and Manage images turned on, then deploy the current folder:

Terminal
export FLATLINED_TOKEN=flt_pat_...flatlined deploy -team your-team -project your-project

The CLI uploads the folder, waits for each build, and creates or updates one server per service. .git and anything listed in .flatlinedignore (written like a .dockerignore) stay behind. -build-only stops after the builds, and flatlined validate checks your flatlined.yaml without deploying.

Good to know:

Images must be built for linux/amd64. To deploy an image you build yourself, flatlined push sends it to your team's registry, and a service can then name it with image:.

flatlined.yaml

The file lists your services. Each one becomes a server in the project, named after the service, and either builds from a Dockerfile or runs an image:

flatlined.yaml
version: 1services:  web:    build:      context: .      dockerfile: Dockerfile    run:      port: 3000      expose: web      vcpu: 1024      env:        NODE_ENV: production      secrets:        - DATABASE_URL      health:        http: /healthz  cache:    image: redis:7    run:      port: 6379
  • expose: web serves HTTPS at the server's own address, tcp publishes ports for protocols that aren't HTTP (UDP included), and internal, the default, keeps the service reachable only by the project's other servers, at <service>:<port>.
  • vcpu and memory: the server's size. 1024 is one vCPU.
  • env and secrets: plain variables go in env. Anything sensitive goes in secrets, which names variables whose values you set in the dashboard or as project secrets, so they never appear in the file.
  • health: when the server counts as ready. Without it, a web or tcp service is ready once its port accepts connections.
  • volumes: storage that survives restarts and deploys, such as a database's data.

Each deploy makes the servers match the file. Servers the file doesn't name are left running, and a volume is never shrunk or removed by a deploy.

Your editor can check the file as you type: point it at the schema at https://api.flatlined.gg/schemas/flatlined.json.