This documentation provides a comprehensive guide for configuring Docker within the development environment of ConsenSys Quorum. It focuses on the setup and utilization of Docker, ensuring developers can effectively build and test the software without delving into production concerns.

Dockerfile Overview

The primary Docker configuration is defined in the Dockerfile, where the build process for the go-ethereum components is detailed. Below is the Dockerfile used in the project, including explanations of each section.

# Support setting various labels on the final image
ARG COMMIT=""
ARG VERSION=""
ARG BUILDNUM=""

# Build Geth in a stock Go builder container
FROM golang:1.22-alpine as builder

RUN apk add --no-cache gcc musl-dev linux-headers git

# Get dependencies - will also be cached if we won't change go.mod/go.sum
COPY go.mod /go-ethereum/
COPY go.sum /go-ethereum/
RUN cd /go-ethereum && go mod download

ADD . /go-ethereum
RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth
RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/bootnode

# Pull Geth into a second stage deploy alpine container
FROM alpine:latest

RUN apk add --no-cache ca-certificates curl
RUN apk add --no-cache openssl # quorum (6 may 2024): 3.1.4-r5 is the installed openssl version, want 3.1.4-r6 to get fix for CVE-2024-2511
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
COPY --from=builder /go-ethereum/build/bin/bootnode /usr/local/bin/

EXPOSE 8545 8546 30303 30303/udp
ENTRYPOINT ["geth"]

# Add some metadata labels to help programmatic image consumption
ARG COMMIT=""
ARG VERSION=""
ARG BUILDNUM=""

LABEL commit="$COMMIT" version="$VERSION" buildnum="$BUILDNUM"

Key Steps in the Dockerfile

  1. Setting Build Arguments:

    • The ARG directives at the beginning allow for customization of the image metadata during the build process.
  2. Builder Stage:

    • Start with the Go builder image (golang:1.22-alpine) which is lightweight and includes necessary tools for building Go applications.
    • Install required packages using apk that are necessary for building the Quorum binaries.
  3. Dependencies Management:

    • go.mod and go.sum files are copied to the container and Go modules are downloaded. This ensures that the required dependencies are cached.
  4. Application Build:

    • The source code is added, and the Geth and Bootnode binaries are built using a provided Go build script build/ci.go.
  5. Final Stage:

    • A second stage based on alpine:latest is initiated to create a minimal runtime image.
    • The built binaries are copied from the builder stage to the final image for a cleaner deployment.
  6. Port Exposure:

    • Ports 8545, 8546, and 30303 are exposed for network communication, allowing interaction with the Geth blockchain node.
  7. Entrypoint:

    • The default command for the container is set to run geth.
  8. Metadata Labels:

    • Additional labels are applied to the image for programmatic consumption, such as commit, version, and build number.

Building the Docker Image

To create the Docker image for development, execute the following command in the directory where your Dockerfile is located:

docker build -t my-quorum-image --build-arg COMMIT="your-commit" --build-arg VERSION="v1.0" --build-arg BUILDNUM="1" .

Replace my-quorum-image with the desired name for your Docker image. This command customizes the image by passing values for the commit, version, and build number.

Running Tests inside Docker

To ensure that your developments are functioning as expected, run tests involving defined build constraints. Specifically, tests related to gofuzz can be executed within the Docker environment. First, ensure that you’re inside your Docker container:

docker run -it --rm my-quorum-image /bin/sh

Then, run your tests with the specific build constraint:

go test -tags gofuzz ./...

This command runs all tests in the repository that are tagged appropriately.

Makefile Usage

The Makefile within the project provides various convenient targets to streamline building and testing processes. Here are some relevant targets:

  • To build a specific binary, use:

    make geth
    
  • For testing the project:

    make test
    

The available functions in the Makefile include functions specifically for cross-compilation and other utilities such as linting and cleaning the build environment.

Conclusion

Using Docker for the development environment of ConsenSys Quorum provides a flexible, consistent, and clean setup for building and testing the software. By following this guide, expert developers can quickly bootstrap their development efforts, ensuring that dependencies and configurations are managed effectively.

Source: The content of this documentation is derived from specific files referenced including the Dockerfile and Makefile. The structure and commands are tailored for efficient utilization of Docker in the contextual Quorum development environment.