Setup Docker Environment

  1. Ensure Prerequisites: Install Docker on your machine by following the official installation guide for your operating system. Verify the installation by checking the version:

    docker --version
    
  2. Clone the Repository: Clone the jaeger-lib repository to your local development environment.

    git clone https://github.com/jaegertracing/jaeger-lib.git
    cd jaeger-lib
    
  3. Create a Dockerfile: In the root of the repository, create a Dockerfile that defines the development environment.

    # Use the official Go image
    FROM golang:1.19 AS builder
    
    WORKDIR /go/src/app
    
    # Copy the go.mod and go.sum files
    COPY go.mod go.sum ./
    
    # Download the dependencies
    RUN go mod download
    
    # Copy the source code
    COPY . .
    
    # Run tests
    RUN make test
    
  4. Build the Docker Image: Build the Docker image from the Dockerfile created in the previous step.

    docker build -t jaeger-lib-dev .
    
  5. Run Docker Container: Start a container from the image. This allows you to work in an isolated environment.

    docker run -it --rm jaeger-lib-dev /bin/bash
    

    The -it flag makes the container interactive, and --rm ensures that it is removed once stopped.

Use Makefile for Development Tasks

The Makefile in the project defines several targets that streamline development tasks. Below are the key targets related to Docker usage.

Default Goal

.DEFAULT_GOAL: test-and-lint

The default goal is set to test-and-lint, meaning this target will be executed if no target is specified. The test-and-lint target runs tests and checks the code for linting issues.

Testing in Docker

While inside the running Docker container, execute the following:

make test

This will utilize the command defined in the Makefile:

.PHONY: test
test: dep-check
    $(GOTEST) $(PACKAGES) | $(COLORIZE)

Make sure that the dep-check target verifies that dependencies are correctly set up.

Code Formatting

You can ensure the code is properly formatted by executing:

make fmt

The corresponding rule in the Makefile is:

.PHONY: fmt
fmt:
    $(GOFMT) -e -s -l -w $(ALL_SRC)

This invokes gofmt on all Go files in the repository, ensuring consistent formatting.

Linter Execution

To run lint checks on the codebase, utilize the following command:

make lint

This executes:

.PHONY: lint
lint:
    $(GOLINT) $(PACKAGES) | $(COLORIZE)

Combined Testing, Formatting, and Linting

To execute all the above tasks in one command, utilize the default target:

make

This will trigger all steps defined in test-and-lint, running tests, formatting the code, and performing lint checks.

Conclusion

Using Docker in the development environment for jaegertracing/jaeger-lib helps isolate dependencies and ensures consistency across different development setups. The provided Makefile targets simplify workflows for testing, formatting, and linting, allowing for a smooth development experience.

Source: jaegertracing/jaeger-lib GitHub