Package: datasette-publish-fly
datasette-publish-flyDatasetteplugin for deploying Datasette instances toFly.io.Project background:Using SQLite and Datasette with Fly VolumesInstallationInstall this plugin in the same environment as Datasette.$ datasette install datasette-publish-flyDeploying read-only dataFirst, install theflyctlcommand-line tool byfollowing their instructions.Runflyctl auth signupto create an account there, orflyctl auth loginif you already have one.You can now usedatasette publish flyto publish one or more SQLite database files:datasette publish fly my-database.db --app="my-data-app"The argument you pass to--appwill be used for the URL of your application:my-data-app.fly.dev.To update an application, run the publish command passing the same application name to the--appoption.Fly havea free tier, beyond which they will charge you monthly for each application you have live.  Details of their pricing can befound on their site.Your application will be deployed athttps://your-app-name.fly.io/- be aware that it may take several minutes to start working the first time you deploy it.Using Fly volumes for writable databasesFlyVolumesprovide persistant disk storage for Fly applications. Volumes can be 1GB or more in size and the Fly free tier includes 3GB of volume space.Datasette plugins such asdatasette-uploads-csvsanddatasette-tiddlywikican be deployed to Fly and store their mutable data in a volume.:warning:You should only run a single instance of your applicationif your database accepts writes. Fly has excellent support for running multiple instances in different geographical regions, butdatasette-publish-flywith volumes is not yet compatible with that model. You should probablyuse Fly PostgreSQL instead.Here's how to deploydatasette-tiddlywikiwith authentication provided bydatasette-auth-passwords.First, you'll need to create a root password hash to use to sign into the instance.You can do that by installing the plugin and running thedatasette hash-passwordcommand, or by usingthis hosted tool.The hash should look likepbkdf2_sha256$...- you'll need this for the next step.In this example we're also deploying a read-only database calledcontent.db.Pick a name for your new application, then run the following:datasette publish fly \
content.db \
--app your-application-name \
--create-volume 1 \
--create-db tiddlywiki \
--install datasette-auth-passwords \
--install datasette-tiddlywiki \
--plugin-secret datasette-auth-passwords root_password_hash 'pbkdf2_sha256$...'This will create the new application, deploy thecontent.dbread-only database, create a 1GB volume for that application, create a new database in that volume calledtiddlywiki.db, then install the two plugins and configure the password you specified.Updating applications that use a volumeOnce you have deployed an application using a volume, you can update that application without needing the--create-volumeor--create-dboptions. To add thedatasette-graphqplugin to your deployed application you would run the following:datasette publish fly \
content.db \
--app your-application-name \
--install datasette-auth-passwords \
--install datasette-tiddlywiki \
--install datasette-graphql \
--plugin-secret datasette-auth-passwords root_password_hash 'pbkdf2_sha256$...' \Since the application name is the same you don't need the--create-volumeor--create-dboptions - these are persisted automatically between deploys.You do need to specify the full list of plugins that you want to have installed, and any plugin secrets.You also need to include any read-only database files that are part of the instance -content.dbin this example - otherwise the new deployment will not include them.Advanced volume usagedatasette publish flywill add a volume calleddatasetteto your Fly application. You can customize the name using the--volume name custom_nameoption.Fly can be used to scale applications to run multiple instances in multiple regions around the world. This works well with read-only Datasette but is not currently recommended using Datasette with volumes, since each Fly replica would need its own volume and data stored in one instance would not be visible in others.If you want to use multiple instances with volumes you will need to switch to using theflyctlcommand directly. The--generate-diroption, described below, can help with this.Generating without deployingUse the--generate-diroption to generate a directory that can be deployed to Fly rather than deploying directly:datasette publish fly my-database.db \
  --app="my-generated-app" \
  --generate-dir /tmp/deploy-thisYou can then manually deploy your generated application using the following:cd /tmp/deploy-this
flyctl apps create my-generated-app
flyctl deploydatasette publish fly --helpUsage: datasette publish fly [OPTIONS] [FILES]...

  Deploy an application to Fly that runs Datasette against the provided database
  files.

  Usage example:

      datasette publish fly my-database.db --app="my-data-app"

  Full documentation: https://datasette.io/plugins/datasette-publish-fly

Options:
  -m, --metadata FILENAME         Path to JSON/YAML file containing metadata to
                                  publish
  --extra-options TEXT            Extra options to pass to datasette serve
  --branch TEXT                   Install datasette from a GitHub branch e.g.
                                  main
  --template-dir DIRECTORY        Path to directory containing custom templates
  --plugins-dir DIRECTORY         Path to directory containing custom plugins
  --static MOUNT:DIRECTORY        Serve static files from this directory at
                                  /MOUNT/...
  --install TEXT                  Additional packages (e.g. plugins) to install
  --plugin-secret <TEXT TEXT TEXT>...
                                  Secrets to pass to plugins, e.g. --plugin-
                                  secret datasette-auth-github client_id xxx
  --version-note TEXT             Additional note to show on /-/versions
  --secret TEXT                   Secret used for signing secure values, such as
                                  signed cookies
  --title TEXT                    Title for metadata
  --license TEXT                  License label for metadata
  --license_url TEXT              License URL for metadata
  --source TEXT                   Source label for metadata
  --source_url TEXT               Source URL for metadata
  --about TEXT                    About label for metadata
  --about_url TEXT                About URL for metadata
  --spatialite                    Enable SpatialLite extension
  --region TEXT                   Fly region to deploy to, e.g sjc - see
                                  https://fly.io/docs/reference/regions/
  --create-volume INTEGER RANGE   Create and attach volume of this size in GB
                                  [x>=1]
  --create-db TEXT                Names of read-write database files to create
  --volume-name TEXT              Volume name to use
  -a, --app TEXT                  Name of Fly app to deploy  [required]
  -o, --org TEXT                  Name of Fly org to deploy to
  --generate-dir DIRECTORY        Output generated application files and stop
                                  without deploying
  --show-files                    Output the generated Dockerfile, metadata.json
                                  and fly.toml
  --setting SETTING...            Setting, see
                                  docs.datasette.io/en/stable/settings.html
  --crossdb                       Enable cross-database SQL queries
  --help                          Show this message and exit.DevelopmentTo contribute to this tool, first checkout the code. Then create a new virtual environment:cd datasette-publish-fly
python -m venv venv
source venv/bin/activateOr if you are usingpipenv:pipenv shellNow install the dependencies and test dependencies:pip install -e '.[test]'To run the tests:pytestIntegration testsThe tests intests/test_integration.pymake actual calls to Fly to deploy a test application.These tests are skipped by default. If you haveflyctlinstalled and configured, you can run the integration tests like this:pytest --integration -sThe-soption here ensures that output from the deploys will be visible to you - otherwise it can look like the tests have hung.The tests will create applications on Fly that start with the prefixpublish-fly-temp-and then delete them at the end of the run.