-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulator
More file actions
74 lines (56 loc) · 1.93 KB
/
simulator
File metadata and controls
74 lines (56 loc) · 1.93 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
# Stage 1: Build the simulator
ARG GO_VERSION=1.24
FROM golang:${GO_VERSION}-alpine AS builder
# Install necessary build tools and strip binaries
RUN apk add --no-cache binutils upx git
# Build arguments
ARG RPC_PORT=20000
ARG HTTP_PORT=8080
ARG VERSION=1.0.0
WORKDIR /app
# Copy go.mod and go.sum to leverage Docker cache
COPY go.mod go.sum ./
# Download dependencies only (no tidy needed in Docker)
RUN go mod download
# Copy the entire source tree
COPY . .
# Build the simulator binary with maximum optimization
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-gcflags="-N -l" \
-trimpath \
-ldflags="-s -w -buildid=" \
-o simulator ./cmd/simulator && \
strip --strip-all simulator && \
upx --best --lzma simulator && \
rm -rf /go/pkg /go/src
# Create user and group files for non-root execution
RUN addgroup -g 1000 dero && \
adduser -D -s /bin/sh -u 1000 -G dero dero
# Stage 2: Create the final minimal image from scratch
FROM scratch
# Re-declare build arguments for the second stage
ARG RPC_PORT=20000
ARG HTTP_PORT=8080
ARG VERSION=1.0.0
# Add proper labels to final image
LABEL org.opencontainers.image.version="${VERSION}"
LABEL org.opencontainers.image.description="Dero simulator node"
LABEL org.opencontainers.image.source="https://github.com/civilware/derohe"
LABEL maintainer="moralpriest@tutamail.com"
# Copy user/group files from builder stage
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
# Copy only the necessary files
COPY --from=builder /app/simulator /simulator
# Create /data directory path
VOLUME /data
# Expose ports
EXPOSE ${RPC_PORT}/tcp
EXPOSE ${HTTP_PORT}/tcp
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD /simulator --version || exit 1
# Switch to non-root user
USER dero
# Default command with arguments
ENTRYPOINT ["/simulator"]
CMD ["--rpc-bind=0.0.0.0:20000", "--http-address=0.0.0.0:8080", "--data-dir=/data"]