@@ -2,33 +2,60 @@ FROM golang:1.23-alpine AS builder
22
33ARG VERSION=unknown
44
5- # copy project
6- COPY . /app
5+ # Install ca-certificates and timezone data for final stage
6+ RUN apk add --no-cache ca-certificates tzdata
77
8- # set working directory
8+ # Set working directory
99WORKDIR /app
1010
11- # using goproxy if you have network issues
12- # ENV GOPROXY=https://goproxy.cn,direct
11+ # Copy go mod files first for better caching
12+ COPY go.mod go.sum ./
13+ RUN go mod download
1314
14- # build
15- RUN CGO_ENABLED=0 go build \
15+ # Copy project files
16+ COPY . .
17+
18+ # Build with optimizations and security flags
19+ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
1620 -ldflags "\
21+ -s -w \
1722 -X 'github.com/langgenius/dify-plugin-daemon/internal/manifest.VersionX=${VERSION}' \
1823 -X 'github.com/langgenius/dify-plugin-daemon/internal/manifest.BuildTimeX=$(date -u +%Y-%m-%dT%H:%M:%S%z)'" \
1924 -o /app/main cmd/server/main.go
2025
21- FROM alpine:latest
26+ # Use Alpine for better permission handling with mounted volumes
27+ FROM alpine:3.20
28+
29+ # Install ca-certificates for SSL/TLS
30+ RUN apk add --no-cache ca-certificates tzdata
2231
32+ # Create non-root user with specific UID/GID for consistency
33+ RUN addgroup -g 1000 appgroup && \
34+ adduser -D -u 1000 -G appgroup appuser
35+
36+ # Set working directory
2337WORKDIR /app
2438
25- # check build args
26- ARG PLATFORM=serverless
39+ # Create storage directory with proper permissions
40+ RUN mkdir -p /app/api/storage && \
41+ chown -R appuser:appgroup /app && \
42+ chmod -R 755 /app
2743
44+ # Build args and environment
45+ ARG PLATFORM=serverless
2846ENV PLATFORM=$PLATFORM
2947ENV GIN_MODE=release
48+ ENV TZ=UTC
49+
50+ # Copy binary with proper ownership
51+ COPY --from=builder --chown=appuser:appgroup /app/main /app/main
52+
53+ # Run as non-root user
54+ USER appuser
3055
31- COPY --from=builder /app/main /app/main
56+ # Health check
57+ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
58+ CMD ["./main" , "health" ] || exit 1
3259
33- # run the server
34- CMD [". /main" ]
60+ # Run the server
61+ ENTRYPOINT ["/app /main" ]
0 commit comments