This documentation covers the essential steps and configurations for using Docker within the development environment of the Cilium project. It is intended for expert developers familiar with the Cilium project.

Prerequisites

Before proceeding, ensure that you have Docker installed and configured properly to build and run containers as per the project’s requirements.

Setting Up Docker

1. Dockerfile Configuration

Cilium utilizes multiple Dockerfiles based on the components being built. The main Dockerfile used for building the Cilium container is found at images/builder/Dockerfile. Below is an overview of its contents:

# TARGETARCH is an automatic platform ARG enabled by Docker BuildKit.
ARG TARGETARCH

RUN \
    apt-get update && \
    apt-get upgrade -y --no-install-recommends && \
    apt-get install -y --no-install-recommends \
      gcc-aarch64-linux-gnu \
      g++-aarch64-linux-gnu \
      libc6-dev-arm64-cross \
      binutils-aarch64-linux-gnu \
      gcc-x86-64-linux-gnu \
      g++-x86-64-linux-gnu \
      libc6-dev-amd64-cross \
      binutils-x86-64-linux-gnu \
      unzip \
      binutils \
      coreutils \
      curl \
      gcc \
      git \
      libc6-dev \
      make && \
    apt-get purge --auto-remove && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

This Dockerfile installs all necessary tools for building Cilium, including the GCC and G++ compilers for both ARM and x86 architectures.

2. Build Configuration

Cilium employs a Makefile to facilitate the building process. Below is an excerpt from the Makefile relevant to Docker targets:

docker-images-all: docker-cilium-image docker-plugin-image docker-hubble-relay-image docker-clustermesh-apiserver-image docker-operator-images-all

docker-images-all-unstripped: docker-cilium-image-unstripped docker-plugin-image-unstripped docker-hubble-relay-image-unstripped docker-clustermesh-apiserver-image-unstripped docker-operator-images-all-unstripped

These targets are utilized to build all Docker images relevant to the Cilium project.

3. Docker Context

To build Docker images efficiently, the context must include relevant files while excluding unnecessary ones. This is managed using a .dockerignore file found at images/cilium/.dockerignore. It ensures that only essential files are sent to the Docker daemon:

*
!/Makefile*
!/go.sum
!/go.mod
!/VERSION
!/images/cilium/Dockerfile
!/.git
!/api
!/bpf
!/bugtool
!/cilium
!/cilium-health
!/daemon
!...

This will help speed up builds and keep the context clean.

4. Developing with Docker

To run the development environment with Docker, the Makefile includes a section dedicated to building Docker images. Developers can simply invoke:

make docker-images-all

This command compiles all necessary images for a local development environment. The images created can be used for running tests or development servers.

5. Running Tests with Docker

While running tests, several build constraints apply based on specific requirements. For instance, you can run tests related to the Cilium project by ensuring the combination of flags:

go test -tags="gofuzz race linux !darwin !race" ./...

Using Docker within this context requires configuring the Docker environment correctly to allow network interactions and necessary dependencies.

6. Utilizing Docker in Windows/Linux

The Docker setup utilizes specific runtime configurations that allow easy integration with the host system. For instance, when running Docker commands from a script, proper handling of Docker login credentials using environment variables is crucial:

if ! [[ -z $DOCKER_LOGIN && -z $DOCKER_PASSWORD ]]; then
    echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_LOGIN}" --password-stdin
fi

This approach ensures that sensitive information is handled securely.

Conclusion

By following the outlined steps and configurations, developers can set up a productive Docker environment for Cilium development. Utilize the provided commands and configurations in conjunction to ensure a smooth build and testing process.

References

  • Cilium/Documentation for Docker configurations within the development environment.

For further details on specific commands and configurations, refer directly to the project’s repository and Makefile definitions.