Skip to content

Commit e1a8604

Browse files
author
Zachary Becker
authored
fix: do multistage builds for e2e-node (cometbft#5220)
--- I removed .git from the .dockerignore because it's used during building. Doing multistage builds should keep it out of the runtime build. Open to alternative ideas. #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments
1 parent c70bafa commit e1a8604

File tree

3 files changed

+80
-39
lines changed

3 files changed

+80
-39
lines changed

.dockerignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ build
22
test/e2e/build
33
test/e2e/networks
44
test/logs
5-
test/p2p/data
6-
.git
5+
test/p2p/data

test/e2e/docker/Dockerfile

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,55 @@
1-
# We need to build in a Linux environment to support C libraries, e.g. RocksDB.
2-
# We use Debian instead of Alpine, so that we can use binary database packages
3-
# instead of spending time compiling them.
4-
FROM cometbft/cometbft-db-testing:v1.0.4
1+
# Multi-stage build Dockerfile for CometBFT end-to-end testing
2+
# Stage 1: Build environment - compiles the application and test node
3+
FROM cometbft/cometbft-db-testing:v1.0.4 AS build
54

6-
RUN apt-get -qq update -y && apt-get -qq upgrade -y >/dev/null
7-
8-
# For latency emulation, install iproute2, which includes tc.
9-
RUN apt-get -qq install -y iputils-ping iproute2 >/dev/null
10-
11-
# Set up build directory /src/cometbft
12-
ENV COMETBFT_BUILD_OPTIONS=badgerdb,rocksdb,clock_skew,bls12381,secp256k1eth
135
WORKDIR /src/cometbft
146

15-
# Fetch dependencies separately (for layer caching)
7+
# Copy Go module files and download dependencies
8+
# This is done before copying the rest of the code to leverage Docker's build cache
169
COPY go.mod go.sum api/go.mod api/go.sum ./
1710
RUN go mod download
1811

19-
# Build CometBFT and install into /usr/bin/cometbft
12+
# Copy the entire codebase into the container
2013
COPY . .
21-
RUN make build && cp build/cometbft /usr/bin/cometbft
22-
COPY test/e2e/docker/entrypoint* /usr/bin/
23-
RUN cd test/e2e && make node && cp build/node /usr/bin/app
2414

25-
# Set up runtime directory. We don't use a separate runtime image since we need
26-
# e.g. leveldb and rocksdb which are already installed in the build image.
15+
# Set build options to include specific features and databases
16+
ENV COMETBFT_BUILD_OPTIONS=badgerdb,rocksdb,clock_skew,bls12381,secp256k1eth
17+
RUN make build
18+
RUN cd test/e2e && make node
19+
20+
# Stage 2: Final image - minimal runtime environment
21+
FROM debian:bookworm-slim AS runtime
22+
23+
# Update system packages and install network utilities
24+
RUN apt-get -qq update -y && apt-get -qq upgrade -y >/dev/null
25+
RUN apt-get -qq install -y iputils-ping iproute2 >/dev/null
26+
2727
WORKDIR /cometbft
2828
VOLUME /cometbft
2929
ENV CMTHOME=/cometbft
30+
31+
# Configure Go race detector to halt on error
3032
ENV GORACE="halt_on_error=1"
3133

34+
# Copy RocksDB shared libraries from the build stage
35+
COPY --from=build /usr/local/lib/librocksdb.so* /lib/
36+
37+
# Copy executables from the build stage
38+
# - entrypoint script for container initialization
39+
# - cometbft binary for the blockchain node
40+
# - app binary for the test application
41+
COPY --from=build /src/cometbft/test/e2e/docker/entrypoint* /usr/bin/
42+
COPY --from=build /src/cometbft/build/cometbft /usr/bin/cometbft
43+
COPY --from=build /src/cometbft/test/e2e/build/node /usr/bin/app
44+
45+
# Expose ports:
46+
# - 26656: P2P communication between nodes
47+
# - 26657: RPC server for API requests
48+
# - 26660: ABCI server for application communication
49+
# - 6060: Prometheus metrics endpoint
3250
EXPOSE 26656 26657 26660 6060
51+
52+
# Set the entrypoint script to initialize the container
3353
ENTRYPOINT ["/usr/bin/entrypoint"]
54+
# Default command to run when container starts (can be overridden)
3455
CMD ["node"]
35-
STOPSIGNAL SIGTERM

test/e2e/docker/Dockerfile.debug

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,54 @@
1-
# We need to build in a Linux environment to support C libraries, e.g. RocksDB.
2-
# We use Debian instead of Alpine, so that we can use binary database packages
3-
# instead of spending time compiling them.
4-
FROM cometbft/cometbft-db-testing:v1.0.4
1+
# Multi-stage build Dockerfile for CometBFT debug end-to-end testing
2+
# Stage 1: Build environment - compiles the application and test node with debugging support
3+
FROM cometbft/cometbft-db-testing:v1.0.4 AS build
54

6-
RUN apt-get -qq update -y && apt-get -qq upgrade -y >/dev/null
7-
RUN apt-get -qq install -y zsh vim >/dev/null
8-
RUN go install github.com/go-delve/delve/cmd/dlv@latest
9-
10-
# Set up build directory /src/cometbft
11-
ENV COMETBFT_BUILD_OPTIONS=badgerdb,rocksdb,nostrip,clock_skew,bls12381,secp256k1eth
125
WORKDIR /src/cometbft
136

14-
# Fetch dependencies separately (for layer caching)
15-
COPY go.mod go.sum ./
7+
# Copy Go module files and download dependencies
8+
# This is done before copying the rest of the code to leverage Docker's build cache
9+
COPY go.mod go.sum api/go.mod api/go.sum ./
1610
RUN go mod download
1711

18-
# Build CometBFT and install into /usr/bin/cometbft
12+
# Copy the entire codebase into the container
1913
COPY . .
20-
RUN echo $COMETBFT_BUILD_OPTION && make build && cp build/cometbft /usr/bin/cometbft
21-
COPY test/e2e/docker/entrypoint-delve /usr/bin/entrypoint-builtin
22-
RUN cd test/e2e && make node && cp build/node /usr/bin/app
2314

24-
# Set up runtime directory. We don't use a separate runtime image since we need
25-
# e.g. leveldb and rocksdb which are already installed in the build image.
15+
# Set build options to include specific features and databases
16+
ENV COMETBFT_BUILD_OPTIONS=badgerdb,rocksdb,clock_skew,bls12381,secp256k1eth,nostrip
17+
RUN make build
18+
RUN cd test/e2e && make node
19+
20+
# Stage 2: Final image - runtime environment with debugging support
21+
FROM golang:1.23 AS runtime
22+
23+
# Update system packages and install network utilities
24+
RUN apt-get -qq update -y && apt-get -qq upgrade -y >/dev/null
25+
RUN apt-get -qq install -y iputils-ping iproute2 >/dev/null
26+
RUN apt-get -qq install -y zsh vim >/dev/null
27+
RUN go install github.com/go-delve/delve/cmd/dlv@latest
28+
2629
WORKDIR /cometbft
2730
VOLUME /cometbft
2831
ENV CMTHOME=/cometbft
32+
33+
# Configure Go race detector to halt on error
2934
ENV GORACE="halt_on_error=1"
3035

36+
# Copy RocksDB shared libraries from the build stage
37+
COPY --from=build /usr/local/lib/librocksdb.so* /lib/
38+
39+
# Copy executables from the build stage
40+
# - entrypoint script for container initialization
41+
# - cometbft binary for the blockchain node
42+
# - app binary for the test application
43+
COPY --from=build /src/cometbft/test/e2e/docker/entrypoint-delve /usr/bin/entrypoint-builtin
44+
COPY --from=build /src/cometbft/build/cometbft /usr/bin/cometbft
45+
COPY --from=build /src/cometbft/test/e2e/build/node /usr/bin/app
46+
47+
# Expose ports:
48+
# - 26656: P2P communication between nodes
49+
# - 26657: RPC server for API requests
50+
# - 26660: ABCI server for application communication
51+
# - 6060: Prometheus metrics endpoint
52+
# - 2345, 2346: Delve debugger ports
3153
EXPOSE 26656 26657 26660 6060 2345 2346
3254
STOPSIGNAL SIGTERM

0 commit comments

Comments
 (0)