Dockerfile 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # -----------------------------------------------------------------------------
  2. # Node builder: frontend only
  3. # -----------------------------------------------------------------------------
  4. FROM node:22-bookworm-slim AS node-builder
  5. RUN corepack enable && corepack prepare pnpm@latest --activate
  6. WORKDIR /build
  7. COPY frontend/ ./
  8. RUN CI=true pnpm install && pnpm build
  9. # -----------------------------------------------------------------------------
  10. # Go builder: backend only
  11. # -----------------------------------------------------------------------------
  12. FROM golang:1.26.1 AS go-builder
  13. RUN apt-get update && apt-get install -y --no-install-recommends \
  14. git \
  15. && rm -rf /var/lib/apt/lists/*
  16. RUN --mount=type=cache,target=/go/pkg/mod \
  17. --mount=type=cache,target=/root/.cache/go-build \
  18. go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
  19. WORKDIR /build
  20. COPY go.mod go.sum ./
  21. RUN --mount=type=cache,target=/go/pkg/mod \
  22. go mod download
  23. COPY . .
  24. RUN sqlc generate
  25. RUN --mount=type=cache,target=/go/pkg/mod \
  26. --mount=type=cache,target=/root/.cache/go-build \
  27. GOOS=linux go build \
  28. -trimpath \
  29. -ldflags "-s -w" \
  30. -o goflare ./cmd/goflare
  31. # -----------------------------------------------------------------------------
  32. # Final image: copy from both builders
  33. # -----------------------------------------------------------------------------
  34. FROM debian:bookworm-slim
  35. RUN apt-get update && apt-get install -y --no-install-recommends \
  36. ca-certificates \
  37. curl \
  38. && rm -rf /var/lib/apt/lists/*
  39. WORKDIR /app
  40. COPY --from=go-builder /build/goflare /app/goflare
  41. COPY --from=node-builder /build/dist /app/frontend
  42. RUN mkdir -p /app/data
  43. EXPOSE 8080
  44. HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
  45. CMD curl -sf http://localhost:8080/api/setup || exit 1
  46. ENV GOFLARE_PORT=:8080 \
  47. GOFLARE_DB_PATH=/app/data/goflare.db \
  48. GOFLARE_FRONTEND_DIR=/app/frontend
  49. CMD ["/app/goflare"]