Skip to content

Deploying app on Fly.io

Flavio Martins edited this page Jan 5, 2024 · 5 revisions

Free allowances

Resources included for free on all plans:

  • Up to 3 shared-cpu-1x 256mb VMs
  • 3GB persistent volume storage (total)
  • 160GB outbound data transfer

Additional resources are billed at the usage-based pricing detailed here.

What we need

  • 1 shared-cpu-1x 256mb VM
  • <1GB persistent volume storage (total)
  • <20GB outbound data transfer

Our app can easily be supported using only free allowances.

What is missing

Deploy steps

  1. Signup to Fly.io

  2. Install the Fly.io CLI

  3. Create App appname from the CLI

    flyctl apps create appname
  4. Notice that Fly.io wants most files to be at the root of the repository (e.g., fly.toml, Dockerfile, etc.)

  5. Before our first deploy we need to set a couple of standard environment variables:

    flyctl secrets set FLASK_APP=app
    flyctl secrets set FLASK_DEBUG=0
    flyctl secrets set FLASK_ENV=production

    Generate your app's unique secret key

    python3 -c 'import secrets; print(secrets.token_hex())'

    Set the environment variable

    flyctl secrets set FLASK_SECRET_KEY='your_key_from_the_previous_step'
    flyctl secrets set WEB_CONCURRENCY=2
  6. We will set the DATABASE_URL to use the database from Tecnico. Note that you need to replace istxxxxxx and pgpass using your information.

    flyctl secrets set DATABASE_URL='postgres://istxxxxxx:[email protected]/istxxxxxx'
  7. Are you ready for our first deploy?

    flyctl deploy

    Take notice of the output of the previous command. It should tell you whether the app was sucessfuly deployed or not. Congratulations!

  8. Open the appname index page at https://appname.fly.dev/