refactor(docker): 移除构建参数和镜像源配置以简化配置

移除不再需要的 GOPROXY 和 BASE_REGISTRY 构建参数
简化 Dockerfile 中的镜像源配置
This commit is contained in:
zhouyonggao 2025-12-02 16:49:58 +08:00
parent 31f288bb1e
commit 396346db8b
2 changed files with 3 additions and 14 deletions

View File

@ -1,19 +1,12 @@
ARG BASE_REGISTRY=docker.mirrors.ustc.edu.cn FROM golang:1.21-alpine AS build
FROM ${BASE_REGISTRY}/library/golang:1.21-alpine AS build
ARG ALPINE_MIRROR=mirrors.ustc.edu.cn
RUN sed -i "s/dl-cdn.alpinelinux.org/${ALPINE_MIRROR}/g" /etc/apk/repositories || true
ARG GOPROXY=https://goproxy.cn,direct
ENV GOPROXY=$GOPROXY
WORKDIR /app WORKDIR /app
RUN --mount=type=cache,target=/var/cache/apk apk add build-base RUN --mount=type=cache,target=/var/cache/apk apk add build-base
COPY server/ ./server/ COPY server/ ./server/
COPY web/ ./web/ COPY web/ ./web/
WORKDIR /app/server WORKDIR /app/server
RUN go env -w GOPROXY=$GOPROXY && go build -o /app/bin/marketing-data-server ./cmd/server RUN go build -o /app/bin/marketing-data-server ./cmd/server
FROM ${BASE_REGISTRY}/library/alpine:3.19 FROM alpine:3.19
ARG ALPINE_MIRROR=mirrors.ustc.edu.cn
RUN sed -i "s/dl-cdn.alpinelinux.org/${ALPINE_MIRROR}/g" /etc/apk/repositories || true
WORKDIR /app WORKDIR /app
COPY --from=build /app/bin/marketing-data-server /app/bin/marketing-data-server COPY --from=build /app/bin/marketing-data-server /app/bin/marketing-data-server
COPY --from=build /app/web /app/web COPY --from=build /app/web /app/web

View File

@ -10,15 +10,11 @@ if docker image inspect "$IMAGE:$TAG" >/dev/null 2>&1; then
echo "使用已有镜像作为缓存: $IMAGE:$TAG" echo "使用已有镜像作为缓存: $IMAGE:$TAG"
DOCKER_BUILDKIT=1 docker build \ DOCKER_BUILDKIT=1 docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \ --build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg GOPROXY="${GOPROXY:-https://goproxy.cn,direct}" \
--build-arg BASE_REGISTRY="${BASE_REGISTRY:-repo.huaweicloud.com}" \
--cache-from "$IMAGE:$TAG" -t "$IMAGE:$TAG" -f Dockerfile . --cache-from "$IMAGE:$TAG" -t "$IMAGE:$TAG" -f Dockerfile .
else else
echo "镜像不存在,开始构建: $IMAGE:$TAG" echo "镜像不存在,开始构建: $IMAGE:$TAG"
DOCKER_BUILDKIT=1 docker build \ DOCKER_BUILDKIT=1 docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \ --build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg GOPROXY="${GOPROXY:-https://goproxy.cn,direct}" \
--build-arg BASE_REGISTRY="${BASE_REGISTRY:-repo.huaweicloud.com}" \
-t "$IMAGE:$TAG" -f Dockerfile . -t "$IMAGE:$TAG" -f Dockerfile .
fi fi
mkdir -p log storage/export mkdir -p log storage/export