From 129e438b077d11d2680f6bc75626edca834dd2e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=96=B9=E6=88=90?= Date: Thu, 16 Oct 2025 14:02:05 +0800 Subject: [PATCH] =?UTF-8?q?ci(docker):=20=E6=B7=BB=E5=8A=A0Dockerfile?= =?UTF-8?q?=E5=92=8C=E6=9B=B4=E6=96=B0CI=E5=B7=A5=E4=BD=9C=E6=B5=81?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加新的Dockerfile用于构建miniChat应用镜像 更新.gitea/workflows/docker.yaml CI工作流配置,优化构建和发布流程 --- { .gitea => .gitea}/workflows/docker.yaml | 2 +- Dockerfile | 51 +++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) rename { .gitea => .gitea}/workflows/docker.yaml (98%) create mode 100644 Dockerfile diff --git a/ .gitea/workflows/docker.yaml b/.gitea/workflows/docker.yaml similarity index 98% rename from .gitea/workflows/docker.yaml rename to .gitea/workflows/docker.yaml index 9a7fc7f..aa80098 100644 --- a/ .gitea/workflows/docker.yaml +++ b/.gitea/workflows/docker.yaml @@ -97,4 +97,4 @@ jobs: echo ${SERVICE_NAME} echo ${APIDOC_CONTAINER_NAME} echo ${SWAGGER_JSON} - make swagger-docker \ No newline at end of file + make swagger-docker \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b8a7b87 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +# Build stage +FROM golang:1.24.5-alpine AS builder + +# Set working directory +WORKDIR /app + +# Install dependencies +RUN apk add --no-cache git ca-certificates tzdata + +# Copy go mod files +COPY go.mod go.sum ./ + +# Download dependencies +RUN go mod download + +# Copy source code +COPY . . + +# Build the application +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-w -s' -trimpath -o miniChat . + +# Final stage +FROM alpine:latest + +# Install ca-certificates for HTTPS requests +RUN apk --no-cache add ca-certificates tzdata + +# Set timezone +ENV TZ=Asia/Shanghai + +# Create app directory +WORKDIR /app + +# Copy binary from builder stage +COPY --from=builder /app/miniChat . + +# Copy configuration files if they exist +COPY --from=builder /app/configs ./configs + +# Create logs directory +RUN mkdir -p /app/logs + +# Expose port +EXPOSE 9991 + +# Health check +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD wget --no-verbose --tries=1 --spider http://localhost:9991/system/health || exit 1 + +# Run the application +CMD ["./miniChat"] \ No newline at end of file