gitlink-cli/showcase/Dockerfile

35 lines
986 B
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# syntax=docker/dockerfile:1
# Stage 1: Build
FROM golang:1.26-alpine AS builder
ENV GOPROXY=https://goproxy.cn,direct
WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# 合并为一个 RUNshowcase-server 复用 gitlink-cli 已编译的依赖(同一 RUN 层内 Go 编译缓存共享)。
# --mount=type=cacheBuildKit 跨构建保留 Go 编译缓存(/root/.cache/go-build
# 之后只重编改动的包,不再全量重编(需 docker build 时 DOCKER_BUILDKIT=1
RUN --mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=linux go build -buildvcs=false -o gitlink-cli . && \
CGO_ENABLED=0 GOOS=linux go build -buildvcs=false -o showcase-server ./showcase/
# Stage 2: Runtime
FROM alpine:latest
RUN apk add --no-cache ca-certificates git
RUN mkdir -p /root/.config/gitlink-cli
WORKDIR /app
COPY --from=builder /build/gitlink-cli .
COPY --from=builder /build/showcase-server .
EXPOSE 9090
CMD ["./showcase-server"]