Remote Development Environments on Fly.io

Remote Development Environments on Fly.io

Fly.io is a platform for deploying applications to the edge. It’s a great fit for Coder because it’s easy to deploy and scale, and it’s easy to manage. In this guide, we’ll walk through deploying Coder on Fly.io and creating workspaces as Fly.io (firecracker) machines.

Deploy Coder

  1. Log in to Fly.io with the CLI:
flyctl auth login
  1. Create a new fly Postgres database:
flyctl postgres create --name <postgres-app-name>
  1. Create a new fly app:
flyctl apps create --name <coder-app-name>
  1. Connect to the database with the coder fly app:
flyctl postgres attach --app <coder-app-name> <postgres-app-name>

Important Copy the connection string that is displayed in the terminal. You’ll need it in the next step.

  1. Create a new secret with the name CODER_PG_CONNECTION_URL and the value as the connection string you copied in the previous step.
flyctl secrets set CODER_PG_CONNECTION_URL=<connection-string> --app <coder-app-name>
  1. Edit the fly.toml file and update as per the example below:
app = "<coder-app-name>" # Replace <coder-app-name> with the name of your app
primary_region = "fra"

[experimental]
  auto_rollback = true

[build]
  image = "ghcr.io/coder/coder:latest"  # you can use a specific tag to pin to a version.

[env]
  CODER_ACCESS_URL = "https://<coder-app-name>.fly.dev" # Replace <coder-app-name> with the name of your app
  CODER_HTTP_ADDRESS = "0.0.0.0:3000"
  CODER_TELEMETRY_INSTALL_SOURCE = "fly.io"
  PRIMARY_REGION = "fra"   # see all regions at https://fly.io/docs/reference/regions/

[http_service]
  internal_port = 3000
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  1. Deploy the app:

Run the following command to deploy the app from the directory where the fly.toml file is located:

flyctl deploy --app <coder-app-name>
  1. Scale the Coder app to 1GB of memory:
flyctl scale memory 1024 --app <coder-app-name>
  1. Congratulations! You’ve deployed Coder on Fly.io!. Go to the URL of your app and create your first user!

If you want to use a custom domain, you can do so by following the instructions here.

Create your first template

A template is a set of instructions that Coder uses to create a workspace. In this section, we’ll create a template that uses a Fly.io machine as the workspace.

  1. Install Coder locally by following the instructions here or if you are on linux/macOS, you can run the following command:
curl -fsSL https://coder.com/get-coder.sh | bash
  1. Login to Coder:
coder login <coder-url>
  1. Create a new template by running the following command and following the prompts:
coder templates init
  1. Choose the fly-docker-image template and cd into the fly-docker-image directory.

  2. Create the new template by running the following command from the fly-docker-image directory:

coder templates push fly-docker-image --variable fly_api_token=$(flyctl auth token)

Alternatively you can create the templates from the dashboard by choosing it from the list of starter templates.

If coder is deployed as a fly.io app, instead of setting variable fly_api_token you can also set a fly.io secret with the name FLY_API_TOKEN

flyctl secrets set FLY_API_TOKEN=$(flyctl auth token)
  1. Go to the Coder UI and create a new workspace using the fly-docker-image template.


  1. This will deploy code-server on a Fly.io machine using the docker image. You can access the code-server instance by clicking on the Code Server button.

Update Coder

To update the Coder version, run flyctl deploy --aap <coder-app-name> again and it will pull the latest version of Coder.

Next Steps

To modify or write your first coder template, check out the template docs.

4 Likes

Awesome work!

1 Like

Hi @ matifali - I know this was posted some time a go, but having an issue setting up templates, there is no fly-docker-image … was it removed? I don’t get any results when trawling Google either.

Yes @undefined86. As Fly.io removed their support for the terraform provider and the last published version is broken when using volumes. We decided removing the official fly.io template.

See this thread for details: [Fresh Produce] Volumes endpoints in Machines API - #7 by matifali