Migrating Vapor app from Heroku to Fly

With Heroku free tier dying, I sought Fly for an alternative. Migration appeared easy from the start, but I found the below errors and being new at dev ops stuff, it’s a bit tricky for me to understand. I am hoping someone can help guide me here…

2022-08-31T02:31:28.213 app[67249936] ewr [info] Preparing to run: `./Run Run serve --env production --hostname 0.0.0.0 --port $PORT` as vapor
2022-08-31T02:31:28.229 app[67249936] ewr [info] 2022/08/31 02:31:28 listening on [fdaa:0:9128:a7b:ab2:6724:9936:2]:22 (DNS: [fdaa::3]:53)
2022-08-31T02:31:28.318 app[67249936] ewr [info] [ WARNING ] Unknown command `Run`
2022-08-31T02:31:28.322 app[67249936] ewr [info] Swift/ErrorType.swift:200: Fatal error: Error raised at top level: .unknownCommand("Run", available: ["boot", "routes", "migrate", "serve"])

My Procfile looks as follows, so I’m not sure where it’s getting the extra ./Run?
web: Run serve --env production --hostname 0.0.0.0 --port $PORT

Secondly, I am getting the following backtrace error that I’m not sure what to do with?

2022-08-31T02:31:28.331 app[67249936] ewr [info] Received signal 4. Backtrace:
2022-08-31T02:31:28.476 app[67249936] ewr [info] 0x5650ff60a3d2, Backtrace.(printBacktrace in _B82A8C0ED7C904841114FDF244F9E58E)(signal: Swift.Int32) -> () at /build/.build/checkouts/swift-backtrace/Sources/Backtrace/Backtrace.swift:66
2022-08-31T02:31:28.476 app[67249936] ewr [info] 0x5650ff60a667, closure #1 (Swift.Int32) -> () in static Backtrace.Backtrace.install(signals: Swift.Array<Swift.Int32>) -> () at /build/.build/checkouts/swift-backtrace/Sources/Backtrace/Backtrace.swift:80
2022-08-31T02:31:28.476 app[67249936] ewr [info] 0x5650ff60a667, @objc closure #1 (Swift.Int32) -> () in static Backtrace.Backtrace.install(signals: Swift.Array<Swift.Int32>) -> () at /build/<compiler-generated>:79

In an effort to determine if Heroku migration was causing some issues… I deleted the original project referenced above and created a new one. Upon attempting to deploy… I get the same backtrace errors however, the Preparing to run: has been fixed, but now I’m getting the following…

2022-09-01T00:15:05Z app[5505547d] ewr [info][ WARNING ] Could not convert option for `port` to Int
2022-09-01T00:15:05Z app[5505547d] ewr [info]Swift/ErrorType.swift:200: Fatal error: Error raised at top level: .invalidOptionType("port", type: Int)

If I echo $PORT, it returns the assigned port.

I haven’t built a Vapor app before, so those errors aren’t easy to read!

If I were doing this, I’d try and write a Dockerfile and then run fly launch against my app directory. It sounds like there’s a problem with Vapor apps + our Heroku importer

This looks like a reasonable set of instructions for creating a Dockerfile: https://www.raywenderlich.com/books/server-side-swift-with-vapor/v3.0.ea1/chapters/32-deploying-with-docker

Hi @kurt, this is using a Dockerfile. I did attempt to do the fly launch while within my app directory. Unfortunately I am continously getting this error…
--> v1 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v2

2022-09-01T00:36:14Z app[05765095] ewr [info]Preparing to run: `./Run serve --env production --hostname 0.0.0.0 --port $PORT` as vapor
2022-09-01T00:36:14Z app[05765095] ewr [info]2022/09/01 00:36:14 listening on [fdaa:0:9128:a7b:ab3:576:5095:2]:22 (DNS: [fdaa::3]:53)
2022-09-01T00:36:14Z app[05765095] ewr [info][ WARNING ] Could not convert option for `port` to Int
2022-09-01T00:36:14Z app[05765095] ewr [info]Swift/ErrorType.swift:200: Fatal error: Error raised at top level: .invalidOptionType("port", type: Int)

Oh I see! $PORT may not be getting set. Can you try hardcoding that to the internal_port in fly.toml? I think it’s 8080.

You can also try adding ENV PORT=8080 to your Dockerfile.

Both were done, still the same result.

Hardcoding the port in the below line worked within the Dockerfile.

CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]

1 Like

Oh! Great catch. The Procfile won’t get used by a Docker app, I should have noticed that.