DocsGo

Go

Deploy a Go app on Ruust: detected from go.mod, compiled with go build, served on HTTPS as a tiny static binary.

Ruust detects a Go app from a go.mod file at the repo root. Nixpacks reads your module and Go version, runs go build to produce a single static binary, and hatches it as an Egg. Go compiles to one self-contained executable with no runtime to ship, so images are small and the Egg starts fast.

Deploy it

  1. Commit go.mod (and go.sum) at the repo root and push to a Git repo.
  2. In the dashboard, choose New Egg and connect the repo.
  3. Pick a size and a region (London or Virginia), then lay the Egg.
  4. Ruust runs go build and hatches the resulting binary.

The port

Ruust sets a PORT environment variable. Your server must read it and bind to 0.0.0.0, not localhost. Binding to the wrong address is the top reason an Egg builds but never hatches: the process is up, but nothing outside the container can reach it.

go
package main

import (
	"net/http"
	"os"
)

func main() {
	port := os.Getenv("PORT")
	if port == "" {
		port = "3000"
	}
	http.ListenAndServe("0.0.0.0:"+port, nil)
}
Read PORT and bind to 0.0.0.0.

The start command

Nixpacks runs the compiled binary for you. To pin the start command yourself, add a Procfile at the repo root with a web: line. Nixpacks builds to a binary named after your module by default.

text
web: ./app
Procfile at the repo root pins the start command.

Environment variables

Set env vars on the Egg. They are available at both build and run time, encrypted at rest, and never printed in logs. Read them with os.Getenv at run time. Go has no client bundle, so there is no public prefix to worry about: everything stays server-side.

A Dockerfile instead (optional)

If you prefer full control, add a Dockerfile at the repo root and Ruust builds that instead of using Nixpacks. A multi-stage build that compiles a static binary and copies it into a scratch or distroless final stage keeps the image tiny.

dockerfile
FROM golang:1.22 AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /app .

FROM gcr.io/distroless/static-debian12
COPY --from=build /app /app
ENV PORT=3000
EXPOSE 3000
ENTRYPOINT ["/app"]
Multi-stage build with a distroless final stage.