-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (56 loc) · 1.64 KB
/
Copy pathDockerfile
File metadata and controls
75 lines (56 loc) · 1.64 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
# Multi-stage build for nmcd
# Supports amd64 and arm64 architectures
# Build stage
FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS builder
# Install build dependencies
RUN apk add --no-cache git ca-certificates tzdata
# Set working directory
WORKDIR /build
# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build arguments for version and platform
ARG VERSION=dev
ARG TARGETOS
ARG TARGETARCH
# Build the binary
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build -v -trimpath \
-ldflags="-s -w -X main.version=${VERSION}" \
-o /build/nmcd \
./cmd/nmcd
# Runtime stage
FROM --platform=$TARGETPLATFORM alpine:latest
# Install runtime dependencies
RUN apk add --no-cache ca-certificates tzdata wget
# Create non-root user
RUN addgroup -S nmcd && adduser -S nmcd -G nmcd
# Create data directory
RUN mkdir -p /data && chown nmcd:nmcd /data
# Copy binary from builder
COPY --from=builder /build/nmcd /usr/local/bin/nmcd
# Set ownership
RUN chown nmcd:nmcd /usr/local/bin/nmcd
# Switch to non-root user
USER nmcd
# Set working directory
WORKDIR /data
# Expose ports
# 8334: P2P (mainnet)
# 8336: RPC (mainnet)
# 18334: P2P (testnet)
# 18336: RPC (testnet)
# 18444: P2P (regtest)
# 18445: RPC (regtest)
# 9090: Prometheus metrics
EXPOSE 8334 8336 18334 18336 18444 18445 9090
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8336/health || exit 1
# Volume for data persistence
VOLUME ["/data"]
# Default command
ENTRYPOINT ["/usr/local/bin/nmcd"]
CMD ["-datadir=/data", "-rpcaddr=127.0.0.1:8336"]