forked from ssvlabs/ssv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (56 loc) · 1.92 KB
/
Dockerfile
File metadata and controls
70 lines (56 loc) · 1.92 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
ARG GO_VERSION=1.24
#
# STEP 1: Base image with common dependencies
#
FROM golang:${GO_VERSION} 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 \
zip unzip bzip2 g++ && \
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
#
FROM base AS builder
## Note TARGETARCH is crucial variable:
## see https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope
ARG TARGETARCH
# Copy source code
COPY . .
# Build the application
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) && \
CGO_ENABLED=1 GOOS=linux GOARCH=$TARGETARCH \
go install \
-tags="blst_enabled" \
-ldflags "-X main.Commit=$COMMIT -X main.Version=$VERSION -linkmode external -extldflags '-static -lm'" \
./cmd/ssvnode
#
# STEP 3: Prepare image to run the binary
#
FROM golang:${GO_VERSION} 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 port for load balancing
EXPOSE 5678 5000 4000/udp
# Force using Go's DNS resolver because Alpine's DNS resolver (when netdns=cgo) may cause issues.
ENV GODEBUG="netdns=go"
#ENTRYPOINT ["/go/bin/ssvnode"]