Fly.io is a convenient and easy to use deployment platform with a generous free allowance. They were also a sponsor of the Gleam project, thank you Fly!

Prepare your application

Ensure your application is listening on 0.0.0.0. If you’re using Mist or Wisp you can do this with the mist.bind function, as shown here.

  let assert Ok(_) =
    wisp_mist.handler(handle_request, secret_key_base)
    |> mist.new
    |> mist.bind("0.0.0.0") // <- add this line
    |> mist.port(8000)
    |> mist.start_http

Take note of what port your application is starting on. We will be using port 8000 for the rest of this guide.

Add a Dockerfile

We can use Fly’s support for containers to build the application and prepare it for deployment.

Add a file named Dockerfile with these contents:

FROM erlang:27.1.1.0-alpine AS build
COPY --from=ghcr.io/gleam-lang/gleam:v1.8.0-erlang-alpine /bin/gleam /bin/gleam
COPY . /app/
RUN cd /app && gleam export erlang-shipment

FROM erlang:27.1.1.0-alpine
RUN \
  addgroup --system webapp && \
  adduser --system webapp -g webapp
COPY --from=build /app/build/erlang-shipment /app
WORKDIR /app
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["run"]

Set up the Fly.io CLI

Follow the instructions here to install Flyctl, the command-line interface for the Fly.io platform.

Once installed use the CLI to sign up (or log in if you already have a Fly.io account).

fly auth signup
# OR
fly auth login

Fly’s free allowance is enough to run the Gleam application but new accounts need a payment card to be added, to prevent people from abusing Fly’s free service.

Deploy the application

From within the project use the Fly CLI to create and run your application on their platform.

flyctl launch

The CLI will ask you a series of questions:

Once you have answered these it will build the application using the docker file. Once deployed you can open it in a web browser by running flyctl open.

To deploy future versions of the application run flyctl deploy after saving any changes to the source code.