-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (50 loc) · 1.53 KB
/
Dockerfile
File metadata and controls
70 lines (50 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Build stage
FROM golang:1.25-alpine AS builder
# Build arguments for multi-arch support
ARG TARGETOS=linux
ARG TARGETARCH
# Set working directory
WORKDIR /build
# Install build 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 application with target architecture
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o owlmail ./cmd/owlmail
# Runtime stage
FROM alpine:latest
# Install runtime dependencies
RUN apk --no-cache add ca-certificates tzdata wget
# Create non-root user
RUN addgroup -g 1000 owlmail && \
adduser -D -u 1000 -G owlmail owlmail
# Set working directory
WORKDIR /app
# Copy binary from builder stage
COPY --from=builder /build/owlmail /app/owlmail
# Copy web static files
COPY --from=builder /build/web /app/web
# Create mail storage directory
RUN mkdir -p /app/mail && \
chown -R owlmail:owlmail /app
# Switch to non-root user
USER owlmail
# Expose ports
# 1025: SMTP port
# 1080: Web API port
EXPOSE 1025 1080
# Set default environment variables
ENV OWLMAIL_SMTP_PORT=1025
ENV OWLMAIL_WEB_PORT=1080
ENV OWLMAIL_SMTP_HOST=0.0.0.0
ENV OWLMAIL_WEB_HOST=0.0.0.0
ENV OWLMAIL_MAIL_DIR=/app/mail
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --quiet --tries=1 -O /dev/null http://localhost:1080/healthz || exit 1
# Start application
ENTRYPOINT ["/app/owlmail"]