Files
Mycontent/soul-api/deploy/Dockerfile
2026-04-13 14:32:32 +08:00

87 lines
2.8 KiB
Docker
Raw Permalink 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.

# 以下由「部署管理器」根据项目配置在保存时自动生成/更新
# 根据「构建命令」解析编译目标;可在项目表单中修改 buildCmd
# 打入镜像的目录 / 单文件 / 构建期必需文件:由 docker-compose build.args 或 docker build --build-arg 配置(见部署管理器「镜像打包」)
FROM golang:1.25 AS builder
ARG DOCKER_BUNDLE_PATHS=certs
ARG DOCKER_BUNDLE_REQUIRED_FILES=
ARG DOCKER_BUNDLE_FILES=
# 构建容器内常无法访问 proxy.golang.org默认 goproxy.cn可用 --build-arg GOPROXY= 覆盖
ARG GOPROXY=https://goproxy.cn,direct
ENV GOPROXY=${GOPROXY}
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
ARG DOCKER_BUNDLE_PATHS
ARG DOCKER_BUNDLE_REQUIRED_FILES
ARG DOCKER_BUNDLE_FILES
RUN set -e; mkdir -p /bundle-out; \
if [ -n "$DOCKER_BUNDLE_REQUIRED_FILES" ]; then \
rem="$DOCKER_BUNDLE_REQUIRED_FILES"; \
while [ -n "$rem" ]; do \
case "$rem" in \
*:*) f="${rem%%:*}"; rem="${rem#*:}";; \
*) f="$rem"; rem="";; \
esac; \
[ -z "$f" ] && continue; \
case "$f" in *..*|/*) echo "illegal required file: $f" >&2; exit 1;; esac; \
test -f "/src/$f" || (echo "missing required file: $f" >&2; exit 1); \
done; \
fi; \
if [ -n "$DOCKER_BUNDLE_PATHS" ]; then \
for d in $DOCKER_BUNDLE_PATHS; do \
[ -z "$d" ] && continue; \
case "$d" in *..*|/*) echo "illegal bundle dir: $d" >&2; exit 1;; esac; \
test -d "/src/$d" || (echo "missing bundle dir: $d" >&2; exit 1); \
mkdir -p "/bundle-out/$d" && cp -a "/src/$d/." "/bundle-out/$d/"; \
done; \
fi; \
if [ -n "$DOCKER_BUNDLE_FILES" ]; then \
rem="$DOCKER_BUNDLE_FILES"; \
while [ -n "$rem" ]; do \
case "$rem" in \
*:*) f="${rem%%:*}"; rem="${rem#*:}";; \
*) f="$rem"; rem="";; \
esac; \
[ -z "$f" ] && continue; \
case "$f" in *..*|/*) echo "illegal bundle file: $f" >&2; exit 1;; esac; \
test -f "/src/$f" || (echo "missing bundle file: $f" >&2; exit 1); \
df="$(dirname "$f")"; \
mkdir -p "/bundle-out/$df"; \
cp "/src/$f" "/bundle-out/$f"; \
done; \
fi; \
touch /bundle-out/.bundle-stamp
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o /out/soul-api ./cmd/server
FROM alpine:3.19
WORKDIR /app
RUN apk add --no-cache ca-certificates tzdata wget && \
addgroup -S app && adduser -S -G app app
COPY --from=builder /out/soul-api /app/soul-api
COPY --from=builder /bundle-out/ /app/
RUN rm -f /app/.bundle-stamp
RUN mkdir -p /app/uploads /app/log && chown -R app:app /app
ENV APP_ENV=production
ENV GIN_MODE=release
ENV PORT=8080
ENV UPLOAD_DIR=/app/uploads
EXPOSE 8080
USER app
CMD ["/app/soul-api"]