superfly / flyctl

Command line tools for fly.io services
https://fly.io
Apache License 2.0
1.41k stars 235 forks source link

`fly postgres connect` broken #3313

Open owenthereal opened 7 months ago

owenthereal commented 7 months ago

Please only report specific issues with flyctl behavior. Anything like a support request for your application should go to https://community.fly.io. More people watch that space and can help you faster!

Describe the bug Briefly, describe what broke and provide the following details:

fly postgres connect is broken for a postgres-flex image

** Paste your fly.toml

# fly.toml file generated for shaun-flex-stable-3 on 2023-01-24T10:42:59-06:00

kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]
  PRIMARY_REGION = "ord"

[checks]
  [checks.pg]
    grace_period = "30s"
    interval = "15s"
    method = "get"
    path = "/flycheck/pg"
    port = 5500
    timeout = "10s"
    type = "http"

  [checks.vm]
    grace_period = "1s"
    interval = "1m"
    method = "get"
    path = "/flycheck/vm"
    port = 5500
    timeout = "10s"
    type = "http"

  [checks.role]
    grace_period = "30s"
    interval = "15s"
    method = "get"
    path = "/flycheck/role"
    port = 5500
    timeout = "10s"
    type = "http"

[[mounts]]
  destination = "/data"
  source = "pg_data"

[metrics]
  path = "/metrics"
  port = 9187

Command output:

fly postgres connect -a MYAPP --debug --verbose
Error: Malformed version: ustom
Stacktrace:
goroutine 1 [running]:
runtime/debug.Stack()
    runtime/debug/stack.go:24 +0x64
github.com/superfly/flyctl/internal/cli.printError(0x1400051c000, 0x14000c8fb76, 0x14000c00308, {0x106d49318, 0x14000b86a00})
    github.com/superfly/flyctl/internal/cli/cli.go:162 +0x3c8
github.com/superfly/flyctl/internal/cli.Run({0x106d65770?, 0x140002e7e80?}, 0x1400051c000, {0x1400004c240, 0x6, 0x6})
    github.com/superfly/flyctl/internal/cli/cli.go:110 +0x7fc
main.run()
    github.com/superfly/flyctl/main.go:47 +0x174
main.main()
    github.com/superfly/flyctl/main.go:26 +0x20
DoingItNow commented 6 months ago

+1

This has been broken since dec 2023. Exact same error

Operating system: macos and win10 fly version v0.2.25

Maybe related to https://github.com/superfly/flyctl/commit/fe493faeb922ce003eeda76527d599732314c1aa

bhaan commented 3 months ago

I recently ran into this when using a forked image of postgres-flex. To fix it, I had to change my docker build command to assign my local flyctl version to a VERSION arg in the docker image:

SOLUTION
docker build --build-arg VERSION=$(fly version | cut -d' ' -f2) --platform linux/amd64 .
EXPLANATION

If you take a look at the Dockerfile for postgres-flex, you'll notice at the top there is a declared arg ARG VERSION=custom which is later assigned as a docker image label: LABEL fly.version=${VERSION}.

Then notice the error message:

Error: Malformed version: ustom

"ustom" is "custom" without the "c". This looks to me like their version parser is trying to remove a leading "v" from a version number like v0.2.80. You can get a version number like this from the fly version command.

Unfortunately, the fly version command prints a lot of other information in addition to the version number. To get a correct version number value, you can pipe it to cut:

fly verision | cut -d' ' -f2

Or you can get it with jq:

fly version --json | jq -r .Version
WORKAROUND

If, for whatever reason, rebuilding the docker image is not a simple solution, I noticed you can still connect to your postgres app using the fly proxy command, as described in their docs.