-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (55 loc) · 1.99 KB
/
Dockerfile
File metadata and controls
70 lines (55 loc) · 1.99 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
# Multi-stage build for HyperCache
# Stage 1: Build stage
FROM golang:1.23.2-alpine AS builder
# Install necessary packages
RUN apk add --no-cache git ca-certificates tzdata
# Set working directory
WORKDIR /app
# Copy go mod files first (for better caching)
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build the binary with optimizations
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags='-w -s -extldflags "-static"' \
-a -installsuffix cgo \
-o hypercache \
cmd/hypercache/main.go
# Stage 2: Final minimal image
FROM alpine:3.18
# Install necessary runtime packages
RUN apk add --no-cache ca-certificates tzdata wget net-tools
# Create non-root user and necessary directories
RUN addgroup -g 1000 hypercache && \
adduser -D -u 1000 -G hypercache hypercache && \
mkdir -p /data /app/logs /config && \
chown -R hypercache:hypercache /data /app /config && \
chmod 755 /data /app /config /app/logs
# Copy the binary
COPY --from=builder /app/hypercache /hypercache
RUN chmod +x /hypercache
# Copy config files into image so docker-compose doesn't need local mounts
COPY --from=builder /app/configs/docker/ /app/configs/docker/
COPY --from=builder /app/configs/node1-config.yaml /app/configs/
COPY --from=builder /app/configs/node2-config.yaml /app/configs/
COPY --from=builder /app/configs/node3-config.yaml /app/configs/
COPY --from=builder /app/filebeat-docker.yml /app/filebeat-docker.yml
COPY --from=builder /app/grafana/provisioning/ /app/grafana/provisioning/
# Set working directory
WORKDIR /app
# Switch to non-root user
USER hypercache
# Expose ports
# RESP Protocol
EXPOSE 8080
# HTTP API
EXPOSE 9080
# Gossip Protocol
EXPOSE 7946
# Health check using the proper health endpoint
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:9080/health || exit 1
# Default command
ENTRYPOINT ["/hypercache"]
CMD ["--config", "/config/hypercache.yaml", "--protocol", "resp"]