GithubHelp home page GithubHelp logo

directus-fly's Introduction

Directus on Fly.io

Install Directus on Fly.io

Important ๐Ÿšง

Fly requires a globally unique name for all the apps, and we've used the directory name and random hash as the app name. Of course, you can change this anytime you want BEFORE launching the app with Fly CLI. But it's not a big deal since you can reassign the internal Fly URL to any custom domain by adding a [CNAME][cname] record to your custom domain pointing to the Fly internal URL. We'll see that later when deploying the app to production.

Fly Setup ๐Ÿ› 

  1. Install Fly

  2. Sign up and log in to Fly

flyctl auth signup

Deployment ๐Ÿš€

Initial setup ๐Ÿ‘€

Before proceeding to deploy our app, we have some steps to take care of:

  • Create a GitHub account GitHub
  • Create a new app on Fly
flyctl launch --name [YOUR-APP-NAME] --copy-config --no-deploy

โš ๏ธ Note: Make sure this name matches the app set in your fly.toml file. Otherwise, you will not be able to deploy.

โš ๏ธ Remember not to deploy since we have some setup steps left to complete!

Environment variables and Secrets ๐Ÿคซ

This template comes with GitHub actions workflows to automatically deploy the app to Fly.io. First, we need to set up our GitHub actions and the Fly app with some secrets. Let's do that now.

To push the build image to the remote Fly registry from GitHub action, we need an access token from Fly. We can generate that using the Fly command line, run:

flyctl auth token

The command will generate an access token. You can then add this token to your GitHub actions secrets by visiting your GitHub repository's settings page https://github.com/:owner/:repo/settings/secrets/actions and then click New repository secret. Next, GitHub will prompt for a key and a value. The key should be FLY_API_TOKEN, and the value will be the token generated by the command line.

We also need to set the Fly app name as a secret, the key should be FLY_APP_NAME, and the value will be the app name specified in fly.toml

Now we need to set up secrets in our Fly app.

We also need a secret to sign our session. We can do that by running the command:

flyctl secrets set KEY=$(openssl rand -hex 32)
flyctl secrets set SECRET=$(openssl rand -hex 32)
flyctl secrets set ADMIN_EMAIL=[[email protected]]
flyctl secrets set ADMIN_PASSWORD=[YOUR-ADMIN-PASSWORD]

The last secret, is your PUBLIC_URL, you can get the initial domain from fly by typing: flyctl info

To get the current app URL and IP address. The app URL will be https://YOUR-APP-NAME.fly.dev.

flyctl secrets set PUBLIC_URL=https://[YOUR-APP-NAME].fly.dev

You can change this by following Fly's DNS docs and then just update the secret anytime

Volumes ๐Ÿ’พ

We also need to create a volume in Fly to persist our app data (SQLite DB) so that Fly can persist the data stored across deployments and container restarts. Again, we can do that using the Fly command line.

flyctl volumes create data --region [REGION] --size 1

Note: REGION should be the region selected when launching the app. You can check the region chosen by running flyctl regions list.

It's important to note that Volumes are bound to an app in a region and cannot be shared between apps in the same region or across multiple regions.

You can learn more about Fly Volumes here

You should also update the region in your fly.toml file to whichever region you selected:

[env]
  FLY_PRIMARY_REGION = "[REGION]"

The other variables you can leave alone.

Deploy ๐Ÿฅณ

We are ready for our first deployment.

You have two ways to deploy:

  • Via npm run deploy: deploy the current folder
  • Via Github actions.

GitHub actions workflows are configured to run on push to the main branch.

So let's push the local branch main to remote, triggering the workflows.

Once all the checks are passed, and the deployment is complete

Logs

You can check the logs using the command flyctl logs from the project directory, containing the fly.toml file in the project's root. You can also check the logs from the console by visiting fly.io/apps.

Console

You can also log in to the remote console using the flyctl ssh console command.

Connecting to your database

The sqlite database lives at /data/database/data.db in your deployed application.

You can connect to the live database by running flyctl ssh console -C database-cli.

Adding extensions ๐Ÿ”Œ

There are two ways to add extensions:

  1. Via package.json like the included directus-extension-wpslug-interface extension or
  2. Installed inside the extensions folder.

This works the same as any other Directus installation

directus-fly's People

Contributors

dependabot[bot] avatar freekrai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.