Overview
This project currently does not have set up Continuous Integration (CI) or Continuous Deployment (CD) automation scripts. However, various mechanisms are in place to facilitate CI/CD processes, primarily through GitHub Actions workflows and a Makefile.
Existing Workflows
In the directory .github/workflows
, several YAML files represent workflows that potentially can be adapted for CI/CD pipelines:
ci.yml
: This file typically defines the CI process, including steps for building, testing, and linting the code.codeql.yml
: This workflow is related to security analysis using the CodeQL tool, which can identify vulnerabilities in the codebase.merge.yml
: This may automate checks or steps taken upon pull request merges.scorecards.yml
: This could be used to evaluate the health of the project on various metrics.
The following sections outline how to set up CI/CD automation using these elements and provide examples of scripts and configurations using the provided structure.
Step-by-Step Guide for CI/CD Automation
1. CI/CD Configuration via GitHub Actions
ci.yml
Example
The ci.yml
workflow could look something like this:
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.19' # Specify the Go version
- name: Install Dependencies
run: make check-dependencies
- name: Lint Code
run: make lint
- name: Run Tests
run: make test
- name: Build
run: make binary
This script covers checkout, setting up Go, installing dependencies, linting code, running tests, and building the project.
2. Using Makefile for CI/CD Tasks
The Makefile
contains several targets that assist in CI/CD automation. The following are some of them along with their expected commands:
make lint
: Runs the linter over the codebase. This is critical for maintaining code quality.make test
: Executes unit tests to validate the functionality of the code.make build
: Builds the application. This target should create the binary outputs which can be deployed.make e2e
: Executes end-to-end tests that may check the integration of various components.make validate-go-mod
: Ensures that the Go modules are correctly referenced and up-to-date.
3. Additional Modern Practices
To enhance the automation scripts, consider implementing:
Testing & Code Coverage: Modify the
test
job inci.yml
to also include coverage reports. You can update the Makefile target for tests to produce coverage reports, which can be published as artifacts by GitHub Actions.Automatic Deployments: If a deployment strategy exists, augment the CI workflow to include deployment steps to your chosen environment(s) based on the branch or tag pushed.
Docker Usage: Given that the project includes a
Dockerfile
anddocker-compose.yml
, it can be beneficial to build and push Docker images as part of CI. You could add steps inci.yml
to log in to a Docker repository, build the image, and push it.
Example Addition to ci.yml
for Docker Deployment
- name: Build Docker Image
run: |
docker build -t myrepo/myimage:${{ github.sha }} .
- name: Push Docker Image
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
docker push myrepo/myimage:${{ github.sha }}
Next Steps
Since CI/CD is not yet fully established, consider the following steps:
- Set up the
ci.yml
file to automate continuous integration processes. - Explore utilizing the GitHub Actions to implement deployment workflows.
- Incorporate additional scripts and Makefile targets as necessary to ensure quality and stability through testing.
Consider reviewing the existing workflows in .github/workflows
for additional features that may augment your CI/CD pipeline.
Source: Directory layout and files provided by the user input.