This documentation provides a detailed step-by-step guide on implementing a CI/CD workflow for the slimtoolkit/slim project. The examples provide clarity on how to structure your pipeline, focusing on automation for build, test, and deployment processes.

Overview

As of now, slimtoolkit/slim does not have a CI/CD setup in place. To facilitate continuous integration and continuous deployment, steps must be taken to define the CI/CD pipeline using tools like GitHub Actions, GitLab CI, or CircleCI.

Next Steps to Set Up CI/CD

  1. Choose a CI/CD Service: Evaluate options like GitHub Actions, Travis CI, GitLab CI/CD, or CircleCI based on your team’s requirements.

  2. Define the Workflow: Draft a .yaml configuration file that outlines the build, test, and deployment processes.

  3. Set Up Docker Configuration: Ensure that all necessary environment details are encapsulated within the Dockerfile and accessible during the CI/CD processes.

  4. Create a Makefile with Commands: Use the provided Makefile to define commands for building, testing, and packaging your application.

  5. Integrate Testing: Include the test suite within the CI/CD pipeline specifically noting the build constraint for the “e2e” tests.

Example CI/CD Configuration

For illustration, here we will set up a basic CI/CD pipeline using GitHub Actions.

Step 1: Create .github/workflows/ci.yml

name: CI

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: '1.18'

      - name: Install golangci-lint
        run: |
          curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $GOPATH/bin v1.24.0

      - name: Install dependencies
        run: go get -v -u ./...

      - name: Run linters
        run: golangci-lint run

      - name: Build the application
        run: make build

      - name: Run tests
        run: make test
        env:
          GO_FLAGS: '-tags=e2e'

Explanation of the CI Workflow Steps

  1. Triggering Events: The CI pipeline is triggered on pushes and pull requests to the main branch.

  2. Job Configuration: The job runs on the latest Ubuntu environment.

  3. Checkout Code: The action checks out the code from the repository to make it available for the next steps.

  4. Set up Go Environment: The Go environment is set based on the specified version.

  5. Golangci-lint Installation: The linter is installed for checking the code quality.

  6. Dependency Installation: This step fetches all dependencies specified in the module.

  7. Run Linters: Executes the linter to ensure code quality.

  8. Build Application: Utilizes the Makefile command make build, which is defined to encapsulate build commands.

  9. Run Tests: Runs tests using make test, with environment variables set to include build constraints for end-to-end tests (-tags=e2e).

Example of Makefile Commands

The Makefile included within the slimtoolkit/slim project offers various targets enhancing the build and testing procedure:

# Example sections of the Makefile

.PHONY: build test

build:
    go build -o slim github.com/slimtoolkit/slim

test:
    go test -v -tags=e2e ./...

Conclusion

Setting up a CI/CD workflow for the slimtoolkit/slim project will enhance your development process by automating builds and tests. Following the outlined steps and examples can help you to create a robust CI/CD pipeline tailored to your project’s needs, ensuring quality and efficiency in your development lifecycle.

This information has been derived from the provided code snippets and project structure, focusing on the primary files associated with the slimtoolkit/slim project.