Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fly.io example #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ Kubernetes
----------

See more in the [kubernetes/ directory](kubernetes/)

Takahē on Fly.io
----------------

See the [tutorial](fly.io/README.md) and the example [config file](fly.io/fly.toml) in [fly.io/](fly.io/).
66 changes: 66 additions & 0 deletions fly.io/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# takahē on Fly.io

Here's a short tutorial to get [Takahē](https://jointakahe.org) running on [Fly.io](https://fly.io).
It's intentionally a very basic setup both in terms of the Fly.io configuration as well as the Takahē installation, but should get things going.

As far as I understand Fly.io pricing, the minimal version of this should even run within the free tier.

The following assumes a working Fly.io account, the installed Fly commandline tool, [`flyctl`](https://fly.io/docs/flyctl/), and a previous authentication via `flyctl auth`.

## Fly.io app name

Let's set up a name for the Fly.io app:

APP_NAME=<YOUR APP NAME>

## Create a Postgres database

First, let's create a [Fly Postgres](https://fly.io/docs/postgres/) instance. (Example for the smallest instance in Frankfurt, adjust according to your needs.)

flyctl postgres create --name $APP_NAME-postgres --region fra --initial-cluster-size 1 --vm-size shared-cpu-1x --volume-size 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably good to make the region a variable as well :)


## Create an application

Next, we create the (empty) Fly.io app.

flyctl apps create --name $APP_NAME

## Attach database to application

Now, we can attach the Postgres instance to the app and set the correct environment variable for the connection URL for Takahē. This also creates the database and the database user.

flyctl postgres attach $APP_NAME-postgres -a $APP_NAME --database-name takahe --database-user takahe --variable-name TAKAHE_DATABASE_SERVER

## Setup secrets

Next, we need to generate a `SECRET_KEY` for Takahē and want to set up a few encrypted environment variables for our Takahē installation. (See [Media Configuration](https://docs.jointakahe.org/en/latest/installation/#media-configuration) and [Email Configuration](https://docs.jointakahe.org/en/latest/installation/#email-configuration).)
There's no need to set `TAKAHE_DATABASE_SERVER` as that is already done by Fly in the database attachment step above.

flyctl secrets set -a $APP_NAME TAKAHE_SECRET_KEY=<SECRET KEY>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since no one needs to know the value, this can be something like flyctl secrets set -a $APP_NAME TAKAHE_SECRET_KEY=$(uuidgen) so it auto populates a random value.

flyctl secrets set -a $APP_NAME TAKAHE_MEDIA_BACKEND=s3://access-key:secret-key@endpoint-url/bucket-name
flyctl secrets set -a $APP_NAME TAKAHE_EMAIL_SERVER=sendgrid://apikey

## Setup fly.toml

The main configuration for our Fly.io app lives in [`fly.toml`](fly.toml). Feel free to adjust the example base config file in this repository, especially considering the [Environment Variables](https://docs.jointakahe.org/en/latest/installation/#environment-variables) for configuring Takahē further.

## Deploy

Now, from the directory of the `fly.toml` file, we can deploy our app.

flyctl deploy

Takahē should now be running at \<YOUR APP DOMAIN>.

## Create admin user

To log into Takahē, first create a admin user by logging into the Fly.io instance:

flyctl ssh console
/takahe/manage.py createsuperuser

## Login, Takahē setup

Now, go to \<YOUR APP DOMAIN> to login and complete the setup of the Takahē instance.

flyctl open
40 changes: 40 additions & 0 deletions fly.io/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
app = "<YOUR APP NAME>"

kill_signal = "SIGINT"
kill_timeout = 5

[build]
image = "jointakahe/takahe-dev:edge"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Takahē is still moving pretty quick, might be reasonable to pin this example to the version it was tested against. Otherwise the user will hit weird issues until 1.0


[env]
# TAKAHE_ENVIRONMENT = "development"
TAKAHE_MAIN_DOMAIN = "<YOUR APP DOMAIN>"
TAKAHE_EMAIL_FROM = "<YOUR APP EMAIL>"
TAKAHE_USE_PROXY_HEADERS = true
GUNICORN_CMD_ARGS = "--workers 2"

[processes]
web = "bash /takahe/docker/run.sh"
stator = "/takahe/manage.py runstator"

[deploy]
release_command = "/takahe/manage.py migrate"

[[services]]
processes = ["web"]
internal_port = 8000
protocol = "tcp"

[services.concurrency]
type = "connections"
hard_limit = 25
soft_limit = 20

[[services.ports]]
handlers = ["http"]
port = 80
force_https = true

[[services.ports]]
handlers = ["tls", "http"]
port = 443