-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
96 lines (66 loc) · 2.24 KB
/
Dockerfile
File metadata and controls
96 lines (66 loc) · 2.24 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Build stage
FROM golang:1.21-alpine AS builder
# Install build dependencies
RUN apk add --no-cache git ca-certificates tzdata
# Set working directory
WORKDIR /app
# Copy go mod files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY . .
# Build server
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-w -s -X main.version=$(git describe --tags --always --dirty 2>/dev/null || echo 'dev')" \
-o /bin/goqueue-server ./cmd/server
# Build worker
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-w -s -X main.version=$(git describe --tags --always --dirty 2>/dev/null || echo 'dev')" \
-o /bin/goqueue-worker ./cmd/worker
# Build CLI
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-w -s -X main.version=$(git describe --tags --always --dirty 2>/dev/null || echo 'dev')" \
-o /bin/goqueue ./cmd/cli
# Server image
FROM alpine:3.19 AS server
RUN apk add --no-cache ca-certificates tzdata
# Create non-root user
RUN addgroup -g 1000 goqueue && \
adduser -u 1000 -G goqueue -s /bin/sh -D goqueue
WORKDIR /app
# Copy binary from builder
COPY --from=builder /bin/goqueue-server /usr/local/bin/
# Create data directory
RUN mkdir -p /data && chown goqueue:goqueue /data
# Switch to non-root user
USER goqueue
# Expose ports
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
# Default command
ENTRYPOINT ["goqueue-server"]
CMD ["--address", ":8080", "--storage-path", "/data/goqueue.db"]
# Worker image
FROM alpine:3.19 AS worker
RUN apk add --no-cache ca-certificates tzdata
# Create non-root user
RUN addgroup -g 1000 goqueue && \
adduser -u 1000 -G goqueue -s /bin/sh -D goqueue
WORKDIR /app
# Copy binary from builder
COPY --from=builder /bin/goqueue-worker /usr/local/bin/
# Create data directory
RUN mkdir -p /data && chown goqueue:goqueue /data
# Switch to non-root user
USER goqueue
# Default command
ENTRYPOINT ["goqueue-worker"]
CMD ["--storage-path", "/data/goqueue.db"]
# CLI image
FROM alpine:3.19 AS cli
RUN apk add --no-cache ca-certificates
COPY --from=builder /bin/goqueue /usr/local/bin/
ENTRYPOINT ["goqueue"]