Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Latest commit

 

History

History
169 lines (109 loc) · 3.83 KB

fly.io.md

File metadata and controls

169 lines (109 loc) · 3.83 KB

Fly.io

Prerequisites

Install flyctl:

curl -L https://fly.io/install.sh | sh

Create PostGIS

flyctl postgres create 
# follow the instructions, use name optimap-db, region Frankfurt

flyctl image show --app optimap-db

Note the username, password, connection string etc. in a secure place and manually set DATABASE_URL for the other app. Note that you need to change connection type to postgis, i.e., start with postgis://.

Create database and enable PostGIS

flyctl postgres connect -a optimap-db

# in postgres=# 
CREATE DATABASE optimap;

Deploy app via Dockerfile

Use Dockerfile instead of Django on Fly because of GIS dependencies.

fly launch --dockerfile Dockerfile
# on first run, overwrite Dockerfile and then roll back needed changes, otherwise error

Now say YES when asked if you want to create a Postgres DB.

We recommend using the database_url (pip install dj-database-url) to parse the DATABASE_URL from os.environ['DATABASE_URL']

For detailed documentation, see https://fly.dev/docs/django/

Why not - changed configuration style to use dj-database-uri.

THIS DOES STILL NOT WORK because the database connection is not available when the migrations are run.

Cannot set database connection because the app does not exist at this point...

Trying:

flyctl launch --dockerfile Dockerfile -e DATABASE_URL=postgis://...:5432/optimap?sslmode=disable

Does not work.

Trying to put the DATABASE_URL without encryption into fly.toml at least for the first start...

Seems to work, https://optimap.fly.dev/ shows the app!

Now removing the env from the fly.toml file and adding the secret:

flyctl secrets set DATABASE_URL=postgis://postgres:[email protected]:5432?sslmode=disable

flyctl secrets list

Get IPs and certificate

fly ips allocate-v4
fly ips allocate-v6
$ fly ips list

VERSION IP                      TYPE    REGION  CREATED AT 
v4      37.16.20.137            public  global  36m11s ago
v6      2a09:8280:1::a:acfd     public  global  36m4s ago

Configure A and AAAA records at domain provider. Then continue with

flyctl certs create optimap.science
flyctl certs create www.optimap.science

Check IP config:

traceroute optimap.fly.dev
traceroute optimap.science

Looks good!

Secrets and passwords

Check that SECRET_KEY environment variable is set, otherwise set it to something... secret:

flyctl secrets list
flyctl secrets set SECRET_KEY="..."

Configure login email password (other values are set in fly.toml):

flyctl secrets set OPTIMAP_EMAIL_HOST_PASSWORD="..."

Configure the superusers' email (users registering with this emailaddress will become Django superusers):

flyctl secrets set OPTIMAP_SUPERUSER_EMAILS="..."

Deploy

flyctl deploy

https://optimap.fly.dev/

and

https://optimap.science/

Update allowed hosts and configure CSRF

Add to tly.toml:

  CSRF_TRUSTED_ORIGINS = "https://optimap.science"

Then flyctl deploy.

Connect to database

fly proxy 15432:5432 -a optimap-db

Connect to database locally at port 15432, e.g., with pgAdmin.

Future