-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (40 loc) · 1.24 KB
/
Dockerfile
File metadata and controls
56 lines (40 loc) · 1.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
# Build stage
FROM golang:1.25-alpine AS builder
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache git ca-certificates tzdata
# 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" \
-o /app/hsm \
main.go
# Final stage
FROM alpine:3.21
WORKDIR /app
# Install runtime dependencies
RUN apk add --no-cache ca-certificates tzdata && \
addgroup -g 1000 hsm && \
adduser -u 1000 -G hsm -s /bin/sh -D hsm
# Copy binary from builder
COPY --from=builder /app/hsm /usr/local/bin/hsm
# Copy entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Create data directory
RUN mkdir -p /data && chown -R hsm:hsm /data
# Switch to non-root user
USER hsm
# Set working directory to data for session storage
WORKDIR /data
# Expose default port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:${HSM_PORT:-8080}/health || exit 1
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["serve"]