diff --git a/Dockerfile b/Dockerfile index 786e40b..806c2b5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,12 @@ -ARG BASE_REGISTRY=docker.mirrors.ustc.edu.cn -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 +FROM golang:1.21-alpine AS build 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 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 -ARG ALPINE_MIRROR=mirrors.ustc.edu.cn -RUN sed -i "s/dl-cdn.alpinelinux.org/${ALPINE_MIRROR}/g" /etc/apk/repositories || true +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 diff --git a/scripts/deploy_docker.sh b/scripts/deploy_docker.sh index d8dc693..7187162 100644 --- a/scripts/deploy_docker.sh +++ b/scripts/deploy_docker.sh @@ -10,15 +10,11 @@ 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 \ - --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 . else echo "镜像不存在,开始构建: $IMAGE:$TAG" DOCKER_BUILDKIT=1 docker build \ --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 . fi mkdir -p log storage/export