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