Multiple "commands" in a GO application

I have a GO application with roughly the following structure:

/go.mod, etc.
/cmd/portal/main.go
/cmd/sanity/main.go
/pkg/...
/internal/...
etc...

I just recently added the sanity directory and application. I saw in flyctl deploy that it was building both portal and sanity. It knew to run portal as the actual appliction. I can’t see any evidence that sanity ran at all – at least there were no errors in the log.

I can’t see any reference in fly.toml that tells it to run portal. How does it know? I feel like I’ve set something somewhere but I can’t find the configuration. Did sanity run and fail?

Is this using fly launch? The Go buildpack has some magic to “guess” the binary to run, it’s probably just picking the first built binary. You can add a Procfile to control this.

Running two processes in the same app is doable, but a little gross. You can either use something like Overmind or Hivemind, or use s6 as a lightweight service manager.

It’s probably simpler to just run everything you need from one binary if you control the app, though.

It may have used fly launch in the beginning but now I use fly deploy.

It is guessing right so I’m happy :slight_smile: But magic like that makes me nervous. It did run the first binary based on the alphabetical directory name.

I’m not trying to run two applications. One is the actual web service and the second I use to test after deployments. It’s just convenient to keep them in the same repository. So the sanity application will only run locally.

I should have added that I’m not using Docker.

I don’t see any documentation on the Procfile. Is there an example somewhere? I see some docs on Heroku’s site.

flyctl launch configures buildpacks if you don’t have a Dockerfile. In this case it’s using the Paketo go buildpack. There’s a section for configuring multiple targets in the docs https://paketo.io/docs/buildpacks/language-family-buildpacks/go

That is EXACTLY it! Thank you so much. For future reference…

Before, I saw this when it built both targets…

Paketo Go Build Buildpack 0.3.3
  Executing build process
    Running 'go build -o /layers/paketo-buildpacks_go-build/targets/bin -buildmode pie ./cmd/portal ./cmd/sanity'
      Completed in 15.942s

then I added this to my fly.toml

[build.args]
  BP_GO_TARGETS = "./cmd/portal"

and now I see this:

Paketo Go Build Buildpack 0.3.3
  Executing build process
    Running 'go build -o /layers/paketo-buildpacks_go-build/targets/bin -buildmode pie ./cmd/portal'
      Completed in 15.799s

So cool! Thank you.

1 Like