CI/CD Integration

The Docker CLI project leverages GitHub Actions to automate its build, test, and release processes. This outline provides an overview of the CI/CD infrastructure.

Workflow Overview

The CI/CD workflows are defined in .github/workflows and consist of various jobs that execute different tasks. Here are some key workflows:

release.yml: Triggers a release workflow on a push to the main branch. It performs the following steps:

  • Builds docker images: Uses scripts/build scripts to build Docker images.
  • Runs tests: Executes integration and unit tests using scripts/test scripts.
  • Publishes releases: Publishes releases to GitHub and Docker Hub.

ci.yml: Triggers a continuous integration workflow on every push to the main branch. It performs the following steps:

  • Builds docker images: Uses scripts/build scripts to build Docker images.
  • Runs tests: Executes unit and integration tests using scripts/test scripts.
  • Performs code analysis: Analyzes code quality using tools such as SonarQube.

build-images.yml: Triggers a workflow for building Docker images on pushes to the main branch.

  • Builds docker images: Uses scripts/build scripts to build Docker images.

release-images.yml: Triggers a workflow for releasing Docker images to Docker Hub on pushes to the main branch.

  • Builds docker images: Uses scripts/build scripts to build Docker images.
  • Publishes releases: Publishes releases to Docker Hub.

pr-test.yml: Triggers a pull request workflow on every pull request opened.

  • Builds docker images: Uses scripts/build scripts to build Docker images.
  • Runs tests: Executes unit and integration tests using scripts/test scripts.

Scripts and Tools

scripts/build: Contains scripts for building Docker images.

scripts/test: Contains scripts for running unit and integration tests.

scripts/release: Contains scripts for creating and publishing releases.

Examples

release.yml:

name: Release
          on:
            push:
              branches:
                - main
          jobs:
            build-and-test:
              runs-on: ubuntu-latest
              steps:
              - uses: actions/checkout@v3
              - name: Build Docker images
                run: ./scripts/build.sh
              - name: Run tests
                run: ./scripts/test.sh
            publish-release:
              runs-on: ubuntu-latest
              needs: build-and-test
              steps:
              - uses: actions/checkout@v3
              - name: Publish release to GitHub
                uses: actions/create-release@v1
                with:
                  tag_name: ${{ github.ref }}
                  body: Release notes
              - name: Publish release to Docker Hub
                run: ./scripts/release.sh
          

ci.yml:

name: CI
          on:
            push:
              branches:
                - main
          jobs:
            build-and-test:
              runs-on: ubuntu-latest
              steps:
              - uses: actions/checkout@v3
              - name: Build Docker images
                run: ./scripts/build.sh
              - name: Run tests
                run: ./scripts/test.sh
            code-analysis:
              runs-on: ubuntu-latest
              steps:
              - uses: actions/checkout@v3
              - name: Analyze code quality
                uses: sonarsource/sonar-scanner-action@master
          

build-images.yml:

name: Build Images
          on:
            push:
              branches:
                - main
          jobs:
            build:
              runs-on: ubuntu-latest
              steps:
              - uses: actions/checkout@v3
              - name: Build Docker images
                run: ./scripts/build.sh
          

release-images.yml:

name: Release Images
          on:
            push:
              branches:
                - main
          jobs:
            release:
              runs-on: ubuntu-latest
              steps:
              - uses: actions/checkout@v3
              - name: Build Docker images
                run: ./scripts/build.sh
              - name: Publish images to Docker Hub
                run: ./scripts/release.sh
          

pr-test.yml:

name: PR Test
          on:
            pull_request:
              branches:
                - main
          jobs:
            test:
              runs-on: ubuntu-latest
              steps:
              - uses: actions/checkout@v3
              - name: Build Docker images
                run: ./scripts/build.sh
              - name: Run tests
                run: ./scripts/test.sh
          

scripts/build.sh:

#!/bin/bash
          # Build Docker image
          docker build -t docker.io/docker/cli:latest .
          

scripts/test.sh:

#!/bin/bash
          # Run unit and integration tests
          go test ./...
          

scripts/release.sh:

#!/bin/bash
          # Publish release to Docker Hub
          docker push docker.io/docker/cli:latest
          

This outline provides a high-level view of the CI/CD integration in the Docker CLI project. For detailed information, refer to the specific workflow files in .github/workflows and the scripts in scripts/build, scripts/test, and scripts/release.