MarketingSystemDataExportTool/Dockerfile

30 lines
1.1 KiB
Docker
Raw 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.

FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS build
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
ENV CGO_ENABLED=0
ARG GOPROXY=https://goproxy.cn,direct
ENV GOPROXY=$GOPROXY
WORKDIR /app
RUN apk add --no-cache git
COPY server/ ./server/
COPY web/ ./web/
WORKDIR /app/server
# 解析平台并执行交叉编译arm 平台根据 variant 设置 GOARM
RUN OS=${TARGETOS:-$(echo $TARGETPLATFORM | cut -d/ -f1)} \
&& ARCH=${TARGETARCH:-$(echo $TARGETPLATFORM | cut -d/ -f2)} \
&& VARIANT=${TARGETVARIANT:-$(echo $TARGETPLATFORM | cut -d/ -f3)} \
&& if [ "$ARCH" = "arm" ]; then export GOARM=$(echo "$VARIANT" | sed 's/^v//;s/[^0-9]//g'); else export GOARM=; fi \
&& go env -w GOPROXY=$GOPROXY \
&& GOOS=$OS GOARCH=$ARCH go build -trimpath -ldflags="-s -w" -o /app/bin/marketing-data-server ./cmd/server
FROM alpine:3.19
WORKDIR /app
COPY --from=build /app/bin/marketing-data-server /app/bin/marketing-data-server
COPY --from=build /app/web /app/web
RUN mkdir -p /app/storage/export
EXPOSE 8077
ENTRYPOINT ["/app/bin/marketing-data-server"]