This document provides a detailed guide on the automation scripts used for Continuous Integration and Continuous Deployment (CI/CD) in the chainguard-dev/apko project.
Overview of CI/CD Scripts
In the chainguard-dev/apko project, CI/CD automation is primarily achieved through GitHub Actions and shell scripts located in the hack/ci/
directory. The scripts are designed to automate various stages of development, from building the project to running tests and publishing artifacts.
Key CI/CD Scripts
Build Scripts
hack/ci/00-build.sh
: This script is responsible for building the application. It leverages the Go build process and ensures all necessary dependencies are handled appropriately.- Example usage:
#! /bin/bash set -e go build -o apko ./main.go
Publish Scripts
hack/ci/01-publish.sh
: This script is used to publish built artifacts to a designated repository. It typically kicks in after a successful build.- Example usage:
#! /bin/bash set -e # Example commands to publish the Docker image docker push my-repo/apko:latest
Testing Scripts
hack/ci-tests.sh
: This script runs the suite of tests to ensure the integrity of the codebase. It is invoked during CI to catch issues before merging changes.- Example usage:
#! /bin/bash set -e go test ./...
GitHub Actions Workflows
In addition to shell scripts, the CI/CD process is integrated with GitHub Actions via various workflow YAML files located in .github/workflows/
. Here are some of the key workflow files:
Build Workflow
- File:
.github/workflows/build.yaml
- This workflow defines the steps for building the application, including running
hack/ci/00-build.sh
. - Example snippet from build.yaml:
name: Build on: push: branches: - main jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Build apko run: hack/ci/00-build.sh
- File:
Test Workflow
- File:
.github/workflows/go-tests.yaml
- This workflow is responsible for running tests using the
hack/ci-tests.sh
. - Example snippet from go-tests.yaml:
name: Go Tests on: pull_request: branches: - main jobs: test: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Run tests run: hack/ci-tests.sh
- File:
Release Workflow
- File:
.github/workflows/release.yaml
- This handles the publication of releases when a new tag is pushed.
- Example snippet from release.yaml:
name: Release on: push: tags: - 'v*.*.*' jobs: release: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Publish apko run: hack/ci/01-publish.sh
- File:
Usage of Makefile for CI/CD
The Makefile
found in the root directory provides several useful commands that assist in the CI/CD process. Key targets include:
- test: Invokes test commands.
- ci: Helper target for CI-related tasks, can orchestrate multiple CI operations.
- lint: Helps maintain code quality by running linters.
Example command usage:
make test
make ci
make lint
Conclusion
The CI/CD automation for chainguard-dev/apko project involves a combination of shell scripts, Makefile commands, and GitHub Actions. By utilizing these resources effectively, the project automates the testing, building, and publishing of software artifacts, ensuring a consistent and reliable development workflow.
This guide serves as an overview of the CI/CD automation scripts, emphasizing the importance of each component in maintaining the project’s lifecycle.
Source: Provided structure and directory listings