forked from ssvlabs/ssv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.multiarch
More file actions
111 lines (97 loc) · 3.28 KB
/
Dockerfile.multiarch
File metadata and controls
111 lines (97 loc) · 3.28 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Dockerfile: Orchestrates multi-architecture builds via hooks/build
# Supports cross-compilation for amd64/arm64/arm targets with proper CGO settings
#
# Global build arguments
#
## Note BUILDPLATFORM and TARGETARCH are crucial variables:
## see https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope
ARG BUILDPLATFORM
ARG TARGETARCH
#
# STEP 1: Base image with common dependencies
#
FROM --platform=$BUILDPLATFORM golang:1.24@sha256:30baaea08c5d1e858329c50f29fe381e9b7d7bced11a0f5f1f69a1504cdfbf5e AS base
# Install essential build tools
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
curl \
git \
ca-certificates \
make \
gcc-aarch64-linux-gnu \
g++-aarch64-linux-gnu \
libc6-dev-arm64-cross \
gcc-arm-linux-gnueabihf \
g++-arm-linux-gnueabihf \
libc6-dev-armhf-cross \
gcc-x86-64-linux-gnu \
g++-x86-64-linux-gnu \
libc6-dev-amd64-cross \
zip \
unzip \
bzip2 && \
rm -rf /var/lib/apt/lists/*
# Set working directory for the build
WORKDIR /go/src/github.com/ssvlabs/ssv/
# Cache dependencies
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,mode=0755,target=/go/pkg \
go mod download && go mod verify
#
# STEP 2: Build executable binary with cross-compilation
#
FROM base AS builder
ARG TARGETARCH
WORKDIR /go/src/github.com/ssvlabs/ssv/
# Copy source code
COPY . .
# Pull in target glibc static libs for -static to find libm.a and libmvec.a
RUN set -eux; \
TARGET_DEB_ARCH=$(case "$TARGETARCH" in \
amd64) echo amd64 ;; \
arm64) echo arm64 ;; \
*) echo armhf ;; \
esac); \
dpkg --add-architecture "$TARGET_DEB_ARCH"; \
apt-get update; \
apt-get install -y --no-install-recommends libc6-dev:"$TARGET_DEB_ARCH"; \
rm -rf /var/lib/apt/lists/*
# Build the static binary
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,mode=0755,target=/go/pkg \
COMMIT=$(git rev-parse HEAD) && \
VERSION=$(git describe --tags $(git rev-list --tags --max-count=1) --always) && \
CC=$(case "$TARGETARCH" in \
amd64) echo x86_64-linux-gnu-gcc ;; \
arm64) echo aarch64-linux-gnu-gcc ;; \
*) echo arm-linux-gnueabihf-gcc ;; \
esac) && \
echo "Building version $VERSION (commit $COMMIT) for $TARGETARCH" && \
CGO_ENABLED=1 GOOS=linux GOARCH=$TARGETARCH CC=$CC \
go build -tags="blst_enabled" \
-ldflags "\
-X main.Commit=$COMMIT \
-X main.Version=$VERSION \
-s -w \
-linkmode external \
-extldflags '-static -lm'" \
-o /go/bin/ssvnode ./cmd/ssvnode
#
# STEP 3: Runner image
#
FROM golang:1.24@sha256:30baaea08c5d1e858329c50f29fe381e9b7d7bced11a0f5f1f69a1504cdfbf5e AS runner
# Install minimal runtime dependencies
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
dnsutils && \
rm -rf /var/lib/apt/lists/*
# Copy binary and configuration
WORKDIR /
COPY --from=builder /go/bin/ssvnode /go/bin/ssvnode
COPY Makefile .env* ./
COPY config/* ./config/
# Expose ports and set DNS resolver
EXPOSE 5678 5000 4000/udp
ENV GODEBUG="netdns=go"
#ENTRYPOINT ["/go/bin/ssvnode"]