ci(docker): 添加GOPROXY配置以加速依赖下载
在Dockerfile和部署脚本中添加GOPROXY配置,使用国内镜像源加速Go模块下载
This commit is contained in:
parent
113a8ffa0a
commit
27cdc9744f
|
|
@ -1,10 +1,12 @@
|
|||
FROM golang:1.21-alpine AS build
|
||||
ARG GOPROXY=https://goproxy.cn,direct
|
||||
ENV GOPROXY=$GOPROXY
|
||||
WORKDIR /app
|
||||
RUN --mount=type=cache,target=/var/cache/apk apk add build-base
|
||||
COPY server/ ./server/
|
||||
COPY web/ ./web/
|
||||
WORKDIR /app/server
|
||||
RUN go build -o /app/bin/marketing-data-server ./cmd/server
|
||||
RUN go env -w GOPROXY=$GOPROXY && go build -o /app/bin/marketing-data-server ./cmd/server
|
||||
|
||||
FROM alpine:3.19
|
||||
WORKDIR /app
|
||||
|
|
|
|||
|
|
@ -8,10 +8,16 @@ PORT="${PORT:-8077}"
|
|||
cd "$ROOT_DIR"
|
||||
if docker image inspect "$IMAGE:$TAG" >/dev/null 2>&1; then
|
||||
echo "使用已有镜像作为缓存: $IMAGE:$TAG"
|
||||
DOCKER_BUILDKIT=1 docker build --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from "$IMAGE:$TAG" -t "$IMAGE:$TAG" -f Dockerfile .
|
||||
DOCKER_BUILDKIT=1 docker build \
|
||||
--build-arg BUILDKIT_INLINE_CACHE=1 \
|
||||
--build-arg GOPROXY="${GOPROXY:-https://goproxy.cn,direct}" \
|
||||
--cache-from "$IMAGE:$TAG" -t "$IMAGE:$TAG" -f Dockerfile .
|
||||
else
|
||||
echo "镜像不存在,开始构建: $IMAGE:$TAG"
|
||||
DOCKER_BUILDKIT=1 docker build --build-arg BUILDKIT_INLINE_CACHE=1 -t "$IMAGE:$TAG" -f Dockerfile .
|
||||
DOCKER_BUILDKIT=1 docker build \
|
||||
--build-arg BUILDKIT_INLINE_CACHE=1 \
|
||||
--build-arg GOPROXY="${GOPROXY:-https://goproxy.cn,direct}" \
|
||||
-t "$IMAGE:$TAG" -f Dockerfile .
|
||||
fi
|
||||
mkdir -p log storage/export
|
||||
CID_NAME="marketing-data-$ENV_NAME"
|
||||
|
|
|
|||
Loading…
Reference in New Issue