The repository includes various CI/CD automation scripts designed to streamline the process of continuous integration and deployment. Below is a detailed breakdown of the existing automation scripts and a step-by-step guide to utilizing them.

CI/CD Workflow Files

The CI/CD automation is primarily managed through GitHub Actions, with the workflow files located in the .github/workflows/ directory. Each file defines a specific pipeline that performs various tasks.

Available Workflow Files

  1. ansible-lint.yaml

    • Runs Ansible lint checks on the Ansible configuration.
  2. build-balena-disk-image.yaml

    • Responsible for building the disk image for Balena deployments.
  3. build-webview.yaml

    • Builds the webview component of the application.
  4. codeql-analysis.yaml

    • Performs static analysis using CodeQL to identify vulnerabilities.
  5. deploy-website.yaml

    • Deploys the website after building.
  6. docker-build.yaml

    • Builds Docker images for services defined in the docker-compose files.
  7. docker-test.yaml

    • Runs tests in Docker containers and uploads coverage reports to Codecov.
  8. python-lint.yaml

    • Executes Python linting using flake8.
  9. sbom.yaml

    • Generates a Software Bill of Materials for compliance and security auditing.

Example Workflow File: docker-test.yaml

A typical example of a CI job is found in the docker-test.yaml file, which defines the testing process for Docker containers.

name: Docker Tests

on:
  push:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Build Docker image
        run: |
          docker-compose -f docker-compose.test.yml build

      - name: Run tests
        run: |
          docker-compose -f docker-compose.test.yml up -d
          docker-compose -f docker-compose.test.yml exec anthias-test ./manage.py test

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v5
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

      - name: Stop the test container
        run: |
          docker-compose -f docker-compose.test.yml down

Local Execution of CI Jobs

Using act for Local CI Testing

act enables the execution of GitHub Actions locally, facilitating the development and testing of CI/CD workflows without pushing changes to the repository. Installation instructions are available in the documentation. Once set up, you can run a specific workflow, for instance, to execute the Python linter:

$ act -W .github/workflows/python-lint.yaml

Running Tests Locally

You may also run the Docker-based tests locally by executing the following commands:

$ docker compose -f docker-compose.test.yml up -d --build

$ docker compose -f docker-compose.test.yml exec anthias-test bash ./bin/prepare_test_environment.sh -s

# Run unit tests excluding integration tests
$ docker compose -f docker-compose.test.yml exec anthias-test ./manage.py test --exclude-tag=integration

# Run integration tests separately
$ docker compose -f docker-compose.test.yml exec anthias-test ./manage.py test --tag=integration

Shell Script for Deployment

The project includes a deployment script, deploy_to_balena.sh, which automates the deployment process to Balena. An excerpt from the script outlines its usage:

#!/bin/bash

set -euo pipefail

print_help() {
    echo "Usage: deploy_to_balena.sh [options]"
    echo "Options:"
    echo "  -h, --help            show this help message and exit"
    echo "  -b, --board BOARD     specify the board to build for (pi1, pi2, pi3, pi4)"
    echo "  -f, --fleet FLEET     specify the fleet name to deploy to"
    echo "  -s, --short-hash HASH specify the short hash to use for the image tag"
    echo "  -d, --dev             run in dev mode"
}

while [[ $# -gt 0 ]]; do
    key="$1"
    case $key in
        -b|--board)
            export BOARD="$2"
            shift
            shift
            ;;
        -f|--fleet)
            export FLEET="$2"
            shift
            shift
            ;;
        -s|--short-hash)
            export GIT_SHORT_HASH="$2"
            shift
            shift
            ;;
        -d|--dev)
            export DEV_MODE=1
            shift
            ;;
        *)
            echo "Unknown option $key"
            print_help
            exit 1
            ;;
    esac
done

This script manages the deployment process by taking parameters such as the target hardware board, fleet name, and deployment mode.

Conclusion

The repository effectively utilizes GitHub Actions for CI/CD, providing various workflows and scripts for testing, building, and deploying the application. Developers can leverage these scripts to automate processes, ensuring robust delivery and integration.

Source: Directory listing and code snippets provided in the prompt.