simonw / datasette-publish-fly

Datasette plugin for publishing data using Fly
Apache License 2.0
20 stars 7 forks source link

Tool now asks interactive questions, it did not before #7

Closed simonw closed 3 years ago

simonw commented 3 years ago
% datasette publish fly fixtures.db -a datasette-fly-test-december-2020

Selected App Name: datasette-fly-test-december-2020

Automatically selected personal organization: Simon Willison

? Select builder:  [Use arrows to move, type to filter]
> Dockerfile
    (Do not set a builder and use the existing Dockerfile)
simonw commented 3 years ago

Here's the problem: https://github.com/simonw/datasette-publish-fly/blob/be161ee1b7481407feeddd25f312191718b0fe8d/datasette_publish_fly/__init__.py#L108-L113

It looks like the design of flyctl apps create changed at some point - it now creates the fly.toml file for you, previously it didn't do that.

% flyctl apps create --help
The APPS CREATE command will both register a new application 
with the Fly platform and create the fly.toml file which controls how 
the application will be deployed. The --builder flag allows a cloud native 
buildpack to be specified which will be used instead of a Dockerfile to 
create the application image when it is deployed.

Usage:
  flyctl apps create [APPNAME] [flags]

Flags:
      --builder string   The Cloud Native Buildpacks builder to use when deploying the app
  -h, --help             help for create
      --name string      The app name to use
      --org string       The organization that will own the app
  -p, --port string      Internal port on application to connect to external services

Global Flags:
  -t, --access-token string   Fly API Access Token
  -j, --json                  json output
  -v, --verbose               verbose output
simonw commented 3 years ago

Urgh. I don't want it to create a fly.toml file.

simonw commented 3 years ago

It looks like this sequence avoids the interactive prompts:

% flyctl apps create --name fly-no-fly-toml2 --builder 'Docker' --port 8080

Selected App Name: fly-no-fly-toml2

Automatically selected personal organization: Simon Willison

New app created
  Name         = fly-no-fly-toml2  
  Organization = personal          
  Version      = 0                 
  Status       =                   
  Hostname     = <empty>           

App will initially deploy to sjc (Sunnyvale, California (US)) region

Wrote config file fly.toml
(datasette-publish-fly) datasette-publish-fly % cat fly.toml 
# fly.toml file generated for fly-no-fly-toml2 on 2020-12-12T11:21:57-08:00

app = "fly-no-fly-toml2"

[build]
  builder = "Docker"

[[services]]
  internal_port = 8080
  protocol = "tcp"

  [services.concurrency]
    hard_limit = 25
    soft_limit = 20

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

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

  [[services.tcp_checks]]
    interval = 10000
    timeout = 2000
simonw commented 3 years ago

I'm going to run fly apps create against a temporary directory so that the fly.toml file doesn't get written to the current directory the user is in when they run datasette publish fly.

simonw commented 3 years ago

Tried that, now I'm getting a new error in the Fly logs:

[2020-12-12T19:31:57+00:00] printenv
[2020-12-12T19:31:57+00:00] Deploying datasette-publish-fly-december-2020
[2020-12-12T19:31:57+00:00] ==> Validating App Configuration
[2020-12-12T19:32:00+00:00] Error App configuration is not valid
simonw commented 3 years ago

Here's what fly.toml looks like:

app = "datasette-publish-fly-december-2020"

[[services]]
  internal_port = 8080
  protocol = "tcp"

  [services.concurrency]
    hard_limit = 25
    soft_limit = 20

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

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

  [[services.tcp_checks]]
    interval = 10000
    timeout = 2000
simonw commented 3 years ago

That looks OK to me - it's similar to the example here https://community.fly.io/t/not-possible-to-validate-configuration-server-returned-500/172

simonw commented 3 years ago

Maybe they changed flyctl deploy too?

https://github.com/simonw/datasette-publish-fly/blob/be161ee1b7481407feeddd25f312191718b0fe8d/datasette_publish_fly/__init__.py#L116-L117

% flyctl deploy --help
Deploy an application to the Fly platform. The application can be a local 
image, remote image, defined in a Dockerfile or use a CNB Buildpack.

Use the --config/-c flag to select a specific toml configuration file.

Use the --image/-i flag to specify a local or remote image to deploy.

Use the --detach flag to return immediately from starting the deployment rather
than monitoring the deployment progress.

Use flyctl monitor to restart monitoring deployment progress

Usage:
  flyctl deploy [<workingdirectory>] [flags]

Flags:
  -a, --app string           App name to operate on
      --build-arg strings    Set of build time variables in the form of NAME=VALUE pairs. Can be specified multiple times.
  -c, --config string        Path to an app config file or directory containing one (default "./fly.toml")
      --detach               Return immediately instead of monitoring deployment progress
      --dockerfile string    Path to a Dockerfile. Defaults to the Dockerfile in the working directory.
  -h, --help                 help for deploy
  -i, --image string         Image tag or id to deploy
      --image-label string   Image label to use when tagging and pushing to the fly registry. Defaults to "deployment-{timestamp}".
      --local-only           Only perform builds locally using the local docker daemon
      --remote-only          Perform builds remotely without using the local docker daemon
      --strategy string      The strategy for replacing running instances. Options are canary, rolling, or immediate. Default is canary

Global Flags:
  -t, --access-token string   Fly API Access Token
  -j, --json                  json output
  -v, --verbose               verbose output
simonw commented 3 years ago

I'm going to try using the --config and --app arguments.

simonw commented 3 years ago

Maybe I need to add . - I found this example in the Fly app dashboard:

flyctl --app datasette-publish-fly-december-2020 deploy .
simonw commented 3 years ago

OK that's an interesting error:

[2020-12-12T19:52:25+00:00]     return fn(conn)
[2020-12-12T19:52:25+00:00]   File "/usr/local/lib/python3.8/site-packages/datasette/database.py", line 145, in sql_operation_in_thread
[2020-12-12T19:52:25+00:00]     cursor.execute(sql, params if params is not None else {})
[2020-12-12T19:52:25+00:00] sqlite3.DatabaseError: malformed database schema (generated_columns) - near "AS": syntax error

Looks like the version of Datasette that gets deployed doesn't support generated columns yet! I should treat that as a separate, core Datasette bug.

simonw commented 3 years ago

OK, got it working again.