Repository navigation
Expand file tree
/
Copy pathexplorer
More file actions
64 lines (47 loc) · 1.63 KB
/
Copy pathexplorer
File metadata and controls
64 lines (47 loc) · 1.63 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
# Stage 1: Build the application
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 VERSION=1.0.0
ARG EXPLORER_PORT=8081
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 explorer with maximum optimization
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-gcflags="-N -l" \
-trimpath \
-ldflags="-s -w -buildid=" \
-o explorer ./cmd/explorer && \
strip --strip-all explorer && \
upx --best --lzma explorer && \
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
ARG VERSION=1.0.0
ARG EXPLORER_PORT=8081
LABEL org.opencontainers.image.version="${VERSION}"
LABEL org.opencontainers.image.description="Dero blockchain explorer"
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 the binary
COPY --from=builder /app/explorer /explorer
EXPOSE ${EXPLORER_PORT}/tcp
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD /explorer --version || exit 1
# Switch to non-root user
USER dero
ENTRYPOINT ["/explorer"]
CMD ["--http-address=0.0.0.0:8081"]