From 47a749faa8426246de56b3ef5307dea37f0a4e95 Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Thu, 11 Sep 2025 10:17:25 +0800 Subject: [PATCH] =?UTF-8?q?[+]=E5=88=A0=E9=99=A4=E9=93=BE=E8=B7=AF?= =?UTF-8?q?=E8=BF=BD=E8=B8=AA=EF=BC=8C=E4=BF=AE=E6=94=B9=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..96a334a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,74 @@ +# Build stage +FROM golang:1.24-alpine AS builder + +WORKDIR /app + +# Install dependencies +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \ + apk add --no-cache git build-base + +# 通过构建参数接收敏感信息 +ARG GOPRIVATE_ARG +ARG GOPROXY_ARG +ARG GOSUMDB_ARG=off + +# 设置Go环境变量 +ENV GOPRIVATE=${GOPRIVATE_ARG} +ENV GOPROXY=${GOPROXY_ARG} +ENV GOSUMDB=${GOSUMDB_ARG} + +# Copy go mod and sum files +COPY go.mod go.sum ./ +RUN go mod download + +ENV CGO_ENABLED=1 +# Install migrate tool +RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest + +# Copy source code +COPY . . + +# Build the application +RUN make build-prod + +# Final stage +FROM alpine:3.17 + +WORKDIR /app + +# Install runtime dependencies +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \ + apk update && apk upgrade && \ + apk add --no-cache build-base postgresql-client mysql-client ca-certificates tzdata sed curl bash supervisor vim wget + +# Copy the binary from the builder stage +COPY --from=builder /app/WeKnora . +COPY --from=builder /app/config ./config +COPY --from=builder /app/scripts ./scripts +COPY --from=builder /app/migrations ./migrations +COPY --from=builder /app/dataset/samples ./dataset/samples + +# Copy migrate tool from builder stage +COPY --from=builder /go/bin/migrate /usr/local/bin/ +COPY --from=builder /go/pkg/mod/github.com/yanyiwu /go/pkg/mod/github.com/yanyiwu/ + +# Make scripts executable +RUN chmod +x ./scripts/*.sh + +# Setup supervisor configuration +RUN mkdir -p /etc/supervisor.d/ +COPY docker/config/supervisord.conf /etc/supervisor.d/supervisord.conf + +# Expose ports +EXPOSE 8080 + +# Set environment variables +ENV CGO_ENABLED=1 + +# Create a non-root user and switch to it +RUN mkdir -p /data/files && \ + adduser -D -g '' appuser && \ + chown -R appuser:appuser /app /data/files + +# Run supervisor instead of direct application start +CMD ["supervisord", "-c", "/etc/supervisor.d/supervisord.conf"] \ No newline at end of file