# ----------- Builder Stage ----------- FROM golang:1.26-alpine AS builder WORKDIR /app RUN apk add --no-cache build-base # Install tooling early so it stays cached across source changes RUN go install github.com/air-verse/air@latest \ && go install github.com/a-h/templ/cmd/templ@latest # Leverage module cache COPY go.mod go.sum ./ RUN --mount=type=cache,target=/go/pkg/mod \ go mod download # Copy the rest of the sources COPY . . # Build once (helps verify builds and speeds CI with cache) RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg/mod \ go build -ldflags="-s -w" -o rentease main.go # ----------- Dev Stage ----------- FROM golang:1.26-alpine AS dev WORKDIR /app # Install runtime dependencies RUN apk add --no-cache ca-certificates && apk add --no-cache golangci-lint # Copy only necessary files from builder COPY --from=builder /app/rentease ./rentease COPY --from=builder /app/assets ./assets COPY --from=builder /go/bin/air /go/bin/templ /go/bin/ COPY . . EXPOSE 8000 CMD ["air", "-c", ".air.toml"]