build(docker): 添加 BASE_REGISTRY 参数以支持自定义基础镜像仓库

允许通过 BASE_REGISTRY 参数指定基础镜像仓库地址,提高部署灵活性
This commit is contained in:
zhouyonggao 2025-12-02 16:38:35 +08:00
parent 3b1fcb37d7
commit 7aa2a95fac
2 changed files with 6 additions and 2 deletions

View File

@ -1,4 +1,5 @@
FROM golang:1.21-alpine AS build
ARG BASE_REGISTRY=docker.io
FROM ${BASE_REGISTRY}/library/golang:1.21-alpine AS build
ARG ALPINE_MIRROR=mirrors.aliyun.com
RUN sed -i "s/dl-cdn.alpinelinux.org/${ALPINE_MIRROR}/g" /etc/apk/repositories || true
ARG GOPROXY=https://goproxy.cn,direct
@ -10,7 +11,8 @@ COPY web/ ./web/
WORKDIR /app/server
RUN go env -w GOPROXY=$GOPROXY && go build -o /app/bin/marketing-data-server ./cmd/server
FROM alpine:3.19
ARG BASE_REGISTRY=docker.io
FROM ${BASE_REGISTRY}/library/alpine:3.19
ARG ALPINE_MIRROR=mirrors.aliyun.com
RUN sed -i "s/dl-cdn.alpinelinux.org/${ALPINE_MIRROR}/g" /etc/apk/repositories || true
WORKDIR /app

View File

@ -12,6 +12,7 @@ if docker image inspect "$IMAGE:$TAG" >/dev/null 2>&1; then
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg GOPROXY="${GOPROXY:-https://goproxy.cn,direct}" \
--build-arg ALPINE_MIRROR="${ALPINE_MIRROR:-mirrors.aliyun.com}" \
--build-arg BASE_REGISTRY="${BASE_REGISTRY:-docker.io}" \
--cache-from "$IMAGE:$TAG" -t "$IMAGE:$TAG" -f Dockerfile .
else
echo "镜像不存在,开始构建: $IMAGE:$TAG"
@ -19,6 +20,7 @@ else
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg GOPROXY="${GOPROXY:-https://goproxy.cn,direct}" \
--build-arg ALPINE_MIRROR="${ALPINE_MIRROR:-mirrors.aliyun.com}" \
--build-arg BASE_REGISTRY="${BASE_REGISTRY:-docker.io}" \
-t "$IMAGE:$TAG" -f Dockerfile .
fi
mkdir -p log storage/export