nezhahq-nezha
SUCCESS
13m 02s
History Source
SummaryIterations1Transcript17Dockerfile
Dockerfile48 lines · 1487 chars
# syntax=docker/dockerfile:1

# Multi-stage build: build from source for the target OS/ARCH and run on a lightweight runtime
FROM golang:1.26 AS builder
ARG TARGETOS
ARG TARGETARCH
ENV CGO_ENABLED=0
ENV PATH=$PATH:/go/bin
WORKDIR /src

# Prepare dist directories with embeddable files to satisfy go:embed
RUN mkdir -p cmd/dashboard/admin-dist cmd/dashboard/user-dist \
  && printf '<html><body>admin-dist placeholder</body></html>' > cmd/dashboard/admin-dist/index.html \
  && printf '<html><body>user-dist placeholder</body></html>' > cmd/dashboard/user-dist/index.html

# Cache Go modules
COPY go.mod go.sum ./
RUN go mod download

# Copy source
COPY . .

# Install swag tool and generate docs for embedding
RUN go install github.com/swaggo/swag/cmd/swag@latest
RUN swag init --pd -d cmd/dashboard -g main.go -o cmd/dashboard/docs

# Build the dashboard binary for the target OS/ARCH
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} \
    go build -trimpath -o /dashboard/app ./cmd/dashboard

FROM busybox:stable-musl
ARG TARGETOS
ARG TARGETARCH
ENV TZ=Asia/Shanghai
WORKDIR /dashboard

# Copy the built binary and necessary resources from the builder
COPY --from=builder /dashboard/app /dashboard/app
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY ./script/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

EXPOSE 8008
VOLUME ["/dashboard/data"]
ENV TZ=$TZ
ENTRYPOINT ["/entrypoint.sh"]