Fly.io is a platform for deploying applications to the edge. It's a great fit for Coder because it's easy to deploy, scale, and manage. In this guide, we'll walk through deploying Coder on Fly.io and creating remote workspaces as Fly.io (firecracker) machines.
Log in to Fly.io with the CLI:
flyctl auth login
Create a new fly postgres database:
flyctl postgres create --name <postgres-app-name>
Create a new fly app:
flyctl apps create --name <coder-app-name>
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.
Create a new secret with the nameCODER_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>
Edit thefly.toml
file and update as per the example below:
app = "<coder-app-name>" # Replace <coder-app-name> with the name of your appkill_signal = "SIGINT"kill_timeout = 5primary_region = "ams" # See a list of regions here: https://fly.io/docs/reference/regions/[experimental] auto_rollback = true private_network = true # Allows Coder to connect to the database[build] image = "ghcr.io/coder/coder:latest"[env] CODER_ACCESS_URL = "https://<coder-app-name>.fly.dev" # Replace <app-name> with the name of your app CODER_HTTP_ADDRESS = "0.0.0.0:3000" #CODER_VERBOSE = "true" # Uncomment this if you want to see more logs CODER_TELEMETRY_INSTALL_SOURCE = "fly.io"[[services]] protocol = "tcp" internal_port = 3000 processes = ["app"] [[services.ports]] port = 80 handlers = ["http"] force_https = true [[services.ports]] port = 443 handlers = ["tls", "http"] [services.concurrency] type = "connections" hard_limit = 25
Deploy the app:
Run the following command to deploy the app from the directory where thefly.toml
file is located:
flyctl deploy --app <coder-app-name>
Scale the Coder app to 1GB of memory:
flyctl scale memory 1024 --app <coder-app-name>
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 instructionshere.
Warning: The following steps may not work as expected becasue Fly.io has deprecated and ended support of their terraform provider. Seehttps://github.com/fly-apps/terraform-provider-fly for more details.
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.
Install Coder locally by following the instructionshere or if you are on linux/macOS, you can run the following command:
curl -fsSL https://coder.com/install.sh | bash
Login to Coder:
coder login <coder-url>
Create a new template by running the following command and following the prompts:
coder templates init
Choose thefly-docker-image
template and cd into thefly-docker-image
directory.bashcd fly-docker-image && coder templates create
Create the new template by running the following command from thefly-docker-image
directory:
coder templates push fly-docker-image --variable fly_api_token=$(flyctl auth token)
If Coder is deployed as a fly.io app, instead of setting variablefly_api_token
you can also set a fly.io secret with the nameFLY_API_TOKEN
Go to the Coder UI and create a new workspace using thefly-docker-image
template.
This will deploy code-server on a Fly.io machine using the docker image. You can access the code-server instance by clicking on theCode Server
button.
To update the Coder version, runflyctl deploy --aap <coder-app-name>
again and it will pull the latest version of Coder.
To modify or write your first coder template, check out thetemplate docs.
Have questions?Contact us orjoin us on Discord
Want to stay up to date on all things Coder? Subscribe to our monthly newsletter and be the first to know when we release new things!