ci(docker): 添加Dockerfile和更新CI工作流配置

添加新的Dockerfile用于构建miniChat应用镜像
更新.gitea/workflows/docker.yaml CI工作流配置,优化构建和发布流程
This commit is contained in:
邹方成 2025-10-16 14:02:05 +08:00
parent 2f747770dd
commit 129e438b07
2 changed files with 52 additions and 1 deletions

View File

@ -97,4 +97,4 @@ jobs:
echo ${SERVICE_NAME} echo ${SERVICE_NAME}
echo ${APIDOC_CONTAINER_NAME} echo ${APIDOC_CONTAINER_NAME}
echo ${SWAGGER_JSON} echo ${SWAGGER_JSON}
make swagger-docker make swagger-docker

51
Dockerfile Normal file
View File

@ -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"]