Skip to content

bdist/bank-api-app

Repository files navigation

Flask API app

Deploy on Fly.io (Optional)

  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:pgpass@db.tecnico.ulisboa.pt/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/

Deploy on Heroku (Optional)

  1. Signup to Heroku

  2. Install the Heroku CLI

  3. Create App appname from the CLI

    heroku create appname
  4. Heroku wants your app to reside standalone in a Git repository. Create a new private repository to hold your app on Github.com and push your app there. Notice that Heroku wants most files to be at the root of the repository (e.g., Procfile, runtime.txt, etc.)

  5. Add a new git remote to your app repository using the Heroku CLI. This remote heroku is the one you will push to whennever you want to deploy the app to Heroku.

    heroku git:remote -a appname

    If the command is successful you will be able to ommit the -a appname part since heroku uses this information.

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

    heroku config:set FLASK_APP=app
    heroku config:set FLASK_DEBUG=0
    heroku config:set FLASK_ENV=production

    Generate your app's unique secret key

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

    Set the environment variable

    heroku config:set FLASK_SECRET_KEY='your_key_from_the_previous_step'
    heroku config: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.

    heroku config:set DATABASE_URL='postgres://istxxxxxx:pgpass@db.tecnico.ulisboa.pt/istxxxxxx'
  7. Are you ready for our first deploy?

    git push heroku main

    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.herokuapps.com/

Credits

Flavio Martins