CI/CD and Build Pipeline for https://github.com/docker/go-events/

Purpose

The CI/CD and Build Pipeline for https://github.com/docker/go-events/ is designed to automate the build, test, and deployment processes for the go-events project. This pipeline ensures that all changes are thoroughly tested before being released, and it streamlines the release process, making it faster and more reliable.

Pipeline Overview

The CI/CD pipeline is implemented using GitHub Actions. It is triggered on every push to the main branch. The pipeline consists of the following steps:

  1. Build: The project is built using go mod tidy and go build.
  2. Test: The project is tested using go test.
  3. Lint: The code is linted using golangci-lint.
  4. Publish: If all tests and lints pass, the built binaries are published to the Docker Hub.

Configuration

The pipeline is configured in the .github/workflows/ci.yml file. The following sections provide detailed descriptions of each step in the pipeline.

Build

- name: Build
            run: |
              go mod tidy
              go build -o go-events
          

The Build step uses the following commands:

  • go mod tidy: Ensures that the project’s dependencies are up-to-date.
  • go build -o go-events: Builds the project and creates an executable named go-events.

Test

- name: Test
            run: |
              go test -v ./...
          

The Test step uses the following command:

  • go test -v ./...: Runs all tests in the project and provides verbose output.

Lint

- name: Lint
            run: |
              golangci-lint run --timeout=5m
          

The Lint step uses the following command:

  • golangci-lint run --timeout=5m: Runs the golangci-lint tool to check the code for style and best practices.

Publish

- name: Publish
            if: ${{ success() && startsWith(github.ref, 'refs/heads/main') }}
            uses: docker/build-push-action@v2
            with:
              context: .
              push: true
              tags: |
                docker.io/library/go-events:latest
                docker.io/library/go-events:${{ runner.os }}-amd64
                docker.io/library/go-events:${{ runner.os }}-arm64
          

The Publish step uses the following commands:

  • docker/build-push-action@v2: Builds and pushes the Docker image to Docker Hub.
  • context: .: Specifies the context for the Docker build.
  • push: true: Pushes the image to Docker Hub after building.
  • tags: | ...: Defines the tags for the Docker image.

Options

The CI/CD pipeline offers the following options:

  • Skip tests: Set the SKIP_TESTS environment variable to true to skip the test step.
  • Skip lint: Set the SKIP_LINT environment variable to true to skip the lint step.
  • Custom image tag: Set the IMAGE_TAG environment variable to specify a custom tag for the Docker image.

Example Usage

Skip tests

jobs:
            build:
              runs-on: ubuntu-latest
              environment:
                SKIP_TESTS: true
          

Skip lint

jobs:
            build:
              runs-on: ubuntu-latest
              environment:
                SKIP_LINT: true
          

Custom image tag

jobs:
            build:
              runs-on: ubuntu-latest
              environment:
                IMAGE_TAG: v1.0.0
          

References