datasette-publish-fly


Namedatasette-publish-fly JSON
Version 1.3 PyPI version JSON
download
home_pagehttps://github.com/simonw/datasette-publish-fly
SummaryDatasette plugin for publishing data using Fly
upload_time2023-01-09 02:17:19
maintainer
docs_urlNone
authorSimon Willison
requires_python
licenseApache License, Version 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # datasette-publish-fly

[![PyPI](https://img.shields.io/pypi/v/datasette-publish-fly.svg)](https://pypi.org/project/datasette-publish-fly/)
[![Changelog](https://img.shields.io/github/v/release/simonw/datasette-publish-fly?include_prereleases&label=changelog)](https://github.com/simonw/datasette-publish-fly/releases)
[![Tests](https://github.com/simonw/datasette-publish-fly/workflows/Test/badge.svg)](https://github.com/simonw/datasette-publish-fly/actions?query=workflow%3ATest)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/datasette-publish-fly/blob/main/LICENSE)

[Datasette](https://datasette.io/) plugin for deploying Datasette instances to [Fly.io](https://fly.io/).

Project background: [Using SQLite and Datasette with Fly Volumes](https://simonwillison.net/2022/Feb/15/fly-volumes/)

## Installation

Install this plugin in the same environment as Datasette.

    $ datasette install datasette-publish-fly

## Deploying read-only data

First, install the `flyctl` command-line tool by [following their instructions](https://fly.io/docs/getting-started/installing-flyctl/).

Run `flyctl auth signup` to create an account there, or `flyctl auth login` if you already have one.

You can now use `datasette publish fly` to publish one or more SQLite database files:

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

The argument you pass to `--app` will 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 `--app` option.

Fly have [a free tier](https://fly.io/docs/about/pricing/#free-allowances), beyond which they will charge you monthly for each application you have live.  Details of their pricing can be [found on their site](https://fly.io/docs/pricing/).

Your application will be deployed at `https://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 databases

Fly [Volumes](https://fly.io/docs/reference/volumes/) provide 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 as [datasette-uploads-csvs](https://datasette.io/plugins/datasette-upload-csvs) and [datasette-tiddlywiki](https://datasette.io/plugins/datasette-tiddlywiki) can be deployed to Fly and store their mutable data in a volume.

> :warning: **You should only run a single instance of your application** if your database accepts writes. Fly has excellent support for running multiple instances in different geographical regions, but `datasette-publish-fly` with volumes is not yet compatible with that model. You should probably [use Fly PostgreSQL instead](https://fly.io/blog/globally-distributed-postgres/).

Here's how to deploy `datasette-tiddlywiki` with authentication provided by `datasette-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 the `datasette hash-password` command, or by using [this hosted tool](https://datasette-auth-passwords-demo.datasette.io/-/password-tool).

The hash should look like `pbkdf2_sha256$...` - you'll need this for the next step.

In this example we're also deploying a read-only database called `content.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 the `content.db` read-only database, create a 1GB volume for that application, create a new database in that volume called `tiddlywiki.db`, then install the two plugins and configure the password you specified.

### Updating applications that use a volume

Once you have deployed an application using a volume, you can update that application without needing the `--create-volume` or `--create-db` options. To add the [datasette-graphq](https://datasette.io/plugins/datasette-graphql) plugin 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-volume` or `--create-db` options - 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.db` in this example - otherwise the new deployment will not include them.

### Advanced volume usage

`datasette publish fly` will add a volume called `datasette` to your Fly application. You can customize the name using the `--volume name custom_name` option.

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 the `flyctl` command directly. The `--generate-dir` option, described below, can help with this.

## Generating without deploying

Use the `--generate-dir` option 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-this

You can then manually deploy your generated application using the following:

    cd /tmp/deploy-this
    flyctl apps create my-generated-app
    flyctl deploy

## datasette publish fly --help

<!-- [[[cog
import cog
from datasette import cli
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cli.cli, ["publish", "fly", "--help"])
help = result.output.replace("Usage: cli", "Usage: datasette")
cog.out(
    "```\n{}```".format(help)
)
]]] -->
```
Usage: 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.
```
<!-- [[[end]]] -->

## Development

To 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/activate

Or if you are using `pipenv`:

    pipenv shell

Now install the dependencies and test dependencies:

    pip install -e '.[test]'

To run the tests:

    pytest

### Integration tests

The tests in `tests/test_integration.py` make actual calls to Fly to deploy a test application.

These tests are skipped by default. If you have `flyctl` installed and configured, you can run the integration tests like this:

    pytest --integration -s

The `-s` option 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 prefix `publish-fly-temp-` and then delete them at the end of the run.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/simonw/datasette-publish-fly",
    "name": "datasette-publish-fly",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Simon Willison",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/27/fe/780184ffe5612c263840228f5effc17fad988c54f8a5d81325f0d16b39ae/datasette-publish-fly-1.3.tar.gz",
    "platform": null,
    "description": "# datasette-publish-fly\n\n[![PyPI](https://img.shields.io/pypi/v/datasette-publish-fly.svg)](https://pypi.org/project/datasette-publish-fly/)\n[![Changelog](https://img.shields.io/github/v/release/simonw/datasette-publish-fly?include_prereleases&label=changelog)](https://github.com/simonw/datasette-publish-fly/releases)\n[![Tests](https://github.com/simonw/datasette-publish-fly/workflows/Test/badge.svg)](https://github.com/simonw/datasette-publish-fly/actions?query=workflow%3ATest)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/datasette-publish-fly/blob/main/LICENSE)\n\n[Datasette](https://datasette.io/) plugin for deploying Datasette instances to [Fly.io](https://fly.io/).\n\nProject background: [Using SQLite and Datasette with Fly Volumes](https://simonwillison.net/2022/Feb/15/fly-volumes/)\n\n## Installation\n\nInstall this plugin in the same environment as Datasette.\n\n    $ datasette install datasette-publish-fly\n\n## Deploying read-only data\n\nFirst, install the `flyctl` command-line tool by [following their instructions](https://fly.io/docs/getting-started/installing-flyctl/).\n\nRun `flyctl auth signup` to create an account there, or `flyctl auth login` if you already have one.\n\nYou can now use `datasette publish fly` to publish one or more SQLite database files:\n\n    datasette publish fly my-database.db --app=\"my-data-app\"\n\nThe argument you pass to `--app` will be used for the URL of your application: `my-data-app.fly.dev`.\n\nTo update an application, run the publish command passing the same application name to the `--app` option.\n\nFly have [a free tier](https://fly.io/docs/about/pricing/#free-allowances), beyond which they will charge you monthly for each application you have live.  Details of their pricing can be [found on their site](https://fly.io/docs/pricing/).\n\nYour application will be deployed at `https://your-app-name.fly.io/` - be aware that it may take several minutes to start working the first time you deploy it.\n\n## Using Fly volumes for writable databases\n\nFly [Volumes](https://fly.io/docs/reference/volumes/) provide persistant disk storage for Fly applications. Volumes can be 1GB or more in size and the Fly free tier includes 3GB of volume space.\n\nDatasette plugins such as [datasette-uploads-csvs](https://datasette.io/plugins/datasette-upload-csvs) and [datasette-tiddlywiki](https://datasette.io/plugins/datasette-tiddlywiki) can be deployed to Fly and store their mutable data in a volume.\n\n> :warning: **You should only run a single instance of your application** if your database accepts writes. Fly has excellent support for running multiple instances in different geographical regions, but `datasette-publish-fly` with volumes is not yet compatible with that model. You should probably [use Fly PostgreSQL instead](https://fly.io/blog/globally-distributed-postgres/).\n\nHere's how to deploy `datasette-tiddlywiki` with authentication provided by `datasette-auth-passwords`.\n\nFirst, you'll need to create a root password hash to use to sign into the instance.\n\nYou can do that by installing the plugin and running the `datasette hash-password` command, or by using [this hosted tool](https://datasette-auth-passwords-demo.datasette.io/-/password-tool).\n\nThe hash should look like `pbkdf2_sha256$...` - you'll need this for the next step.\n\nIn this example we're also deploying a read-only database called `content.db`.\n\nPick a name for your new application, then run the following:\n\n    datasette publish fly \\\n    content.db \\\n    --app your-application-name \\\n    --create-volume 1 \\\n    --create-db tiddlywiki \\\n    --install datasette-auth-passwords \\\n    --install datasette-tiddlywiki \\\n    --plugin-secret datasette-auth-passwords root_password_hash 'pbkdf2_sha256$...'\n\nThis will create the new application, deploy the `content.db` read-only database, create a 1GB volume for that application, create a new database in that volume called `tiddlywiki.db`, then install the two plugins and configure the password you specified.\n\n### Updating applications that use a volume\n\nOnce you have deployed an application using a volume, you can update that application without needing the `--create-volume` or `--create-db` options. To add the [datasette-graphq](https://datasette.io/plugins/datasette-graphql) plugin to your deployed application you would run the following:\n\n    datasette publish fly \\\n    content.db \\\n    --app your-application-name \\\n    --install datasette-auth-passwords \\\n    --install datasette-tiddlywiki \\\n    --install datasette-graphql \\\n    --plugin-secret datasette-auth-passwords root_password_hash 'pbkdf2_sha256$...' \\\n\nSince the application name is the same you don't need the `--create-volume` or `--create-db` options - these are persisted automatically between deploys.\n\nYou do need to specify the full list of plugins that you want to have installed, and any plugin secrets.\n\nYou also need to include any read-only database files that are part of the instance - `content.db` in this example - otherwise the new deployment will not include them.\n\n### Advanced volume usage\n\n`datasette publish fly` will add a volume called `datasette` to your Fly application. You can customize the name using the `--volume name custom_name` option.\n\nFly 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.\n\nIf you want to use multiple instances with volumes you will need to switch to using the `flyctl` command directly. The `--generate-dir` option, described below, can help with this.\n\n## Generating without deploying\n\nUse the `--generate-dir` option to generate a directory that can be deployed to Fly rather than deploying directly:\n\n    datasette publish fly my-database.db \\\n      --app=\"my-generated-app\" \\\n      --generate-dir /tmp/deploy-this\n\nYou can then manually deploy your generated application using the following:\n\n    cd /tmp/deploy-this\n    flyctl apps create my-generated-app\n    flyctl deploy\n\n## datasette publish fly --help\n\n<!-- [[[cog\nimport cog\nfrom datasette import cli\nfrom click.testing import CliRunner\nrunner = CliRunner()\nresult = runner.invoke(cli.cli, [\"publish\", \"fly\", \"--help\"])\nhelp = result.output.replace(\"Usage: cli\", \"Usage: datasette\")\ncog.out(\n    \"```\\n{}```\".format(help)\n)\n]]] -->\n```\nUsage: datasette publish fly [OPTIONS] [FILES]...\n\n  Deploy an application to Fly that runs Datasette against the provided database\n  files.\n\n  Usage example:\n\n      datasette publish fly my-database.db --app=\"my-data-app\"\n\n  Full documentation: https://datasette.io/plugins/datasette-publish-fly\n\nOptions:\n  -m, --metadata FILENAME         Path to JSON/YAML file containing metadata to\n                                  publish\n  --extra-options TEXT            Extra options to pass to datasette serve\n  --branch TEXT                   Install datasette from a GitHub branch e.g.\n                                  main\n  --template-dir DIRECTORY        Path to directory containing custom templates\n  --plugins-dir DIRECTORY         Path to directory containing custom plugins\n  --static MOUNT:DIRECTORY        Serve static files from this directory at\n                                  /MOUNT/...\n  --install TEXT                  Additional packages (e.g. plugins) to install\n  --plugin-secret <TEXT TEXT TEXT>...\n                                  Secrets to pass to plugins, e.g. --plugin-\n                                  secret datasette-auth-github client_id xxx\n  --version-note TEXT             Additional note to show on /-/versions\n  --secret TEXT                   Secret used for signing secure values, such as\n                                  signed cookies\n  --title TEXT                    Title for metadata\n  --license TEXT                  License label for metadata\n  --license_url TEXT              License URL for metadata\n  --source TEXT                   Source label for metadata\n  --source_url TEXT               Source URL for metadata\n  --about TEXT                    About label for metadata\n  --about_url TEXT                About URL for metadata\n  --spatialite                    Enable SpatialLite extension\n  --region TEXT                   Fly region to deploy to, e.g sjc - see\n                                  https://fly.io/docs/reference/regions/\n  --create-volume INTEGER RANGE   Create and attach volume of this size in GB\n                                  [x>=1]\n  --create-db TEXT                Names of read-write database files to create\n  --volume-name TEXT              Volume name to use\n  -a, --app TEXT                  Name of Fly app to deploy  [required]\n  -o, --org TEXT                  Name of Fly org to deploy to\n  --generate-dir DIRECTORY        Output generated application files and stop\n                                  without deploying\n  --show-files                    Output the generated Dockerfile, metadata.json\n                                  and fly.toml\n  --setting SETTING...            Setting, see\n                                  docs.datasette.io/en/stable/settings.html\n  --crossdb                       Enable cross-database SQL queries\n  --help                          Show this message and exit.\n```\n<!-- [[[end]]] -->\n\n## Development\n\nTo contribute to this tool, first checkout the code. Then create a new virtual environment:\n\n    cd datasette-publish-fly\n    python -m venv venv\n    source venv/bin/activate\n\nOr if you are using `pipenv`:\n\n    pipenv shell\n\nNow install the dependencies and test dependencies:\n\n    pip install -e '.[test]'\n\nTo run the tests:\n\n    pytest\n\n### Integration tests\n\nThe tests in `tests/test_integration.py` make actual calls to Fly to deploy a test application.\n\nThese tests are skipped by default. If you have `flyctl` installed and configured, you can run the integration tests like this:\n\n    pytest --integration -s\n\nThe `-s` option here ensures that output from the deploys will be visible to you - otherwise it can look like the tests have hung.\n\nThe tests will create applications on Fly that start with the prefix `publish-fly-temp-` and then delete them at the end of the run.\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "Datasette plugin for publishing data using Fly",
    "version": "1.3",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3a291be67764215a369ceced26251c961291a4695e10d8d999694145d72bae41",
                "md5": "701652a2c21e3d1f3c61099e3adda868",
                "sha256": "016760349e0c1bda17abb88b73118b888491c4dff6b64bdfa1d5795e1fde9fb0"
            },
            "downloads": -1,
            "filename": "datasette_publish_fly-1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "701652a2c21e3d1f3c61099e3adda868",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 13459,
            "upload_time": "2023-01-09T02:17:18",
            "upload_time_iso_8601": "2023-01-09T02:17:18.273356Z",
            "url": "https://files.pythonhosted.org/packages/3a/29/1be67764215a369ceced26251c961291a4695e10d8d999694145d72bae41/datasette_publish_fly-1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "27fe780184ffe5612c263840228f5effc17fad988c54f8a5d81325f0d16b39ae",
                "md5": "b54da9ac69419ec22ec88afbef55b8c9",
                "sha256": "ca11b97cbb3849f755577b124337d6eaf387da0f00b06e1854fdb4212250ecbf"
            },
            "downloads": -1,
            "filename": "datasette-publish-fly-1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "b54da9ac69419ec22ec88afbef55b8c9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15620,
            "upload_time": "2023-01-09T02:17:19",
            "upload_time_iso_8601": "2023-01-09T02:17:19.918930Z",
            "url": "https://files.pythonhosted.org/packages/27/fe/780184ffe5612c263840228f5effc17fad988c54f8a5d81325f0d16b39ae/datasette-publish-fly-1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-09 02:17:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "simonw",
    "github_project": "datasette-publish-fly",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "datasette-publish-fly"
}
        
Elapsed time: 0.09808s