Install flyctl
:
curl -L https://fly.io/install.sh | sh
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;
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
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!
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="..."
flyctl deploy
and
- https://learndjango.com/tutorials/deploy-django-postgresql-flyio
- See #42 for links and issue description around CSRF
Add to tly.toml
:
CSRF_TRUSTED_ORIGINS = "https://optimap.science"
Then flyctl deploy
.
fly proxy 15432:5432 -a optimap-db
Connect to database locally at port 15432
, e.g., with pgAdmin.
- Database backups, see https://www.joseferben.com/posts/django-on-flyio/
- Health check endpoint, see https://www.joseferben.com/posts/django-on-flyio/