This documentation outlines the CI/CD automation scripts implemented within the sourcegraph/zoekt project. The project utilizes various scripts to facilitate continuous integration and delivery processes, ensuring that the codebase remains robust and deployable.

CI/CD Overview

The CI/CD process within sourcegraph/zoekt is primarily managed using GitHub Actions, leveraging a series of YAML configuration files and shell scripts located in the .github/workflows directory.

Existing CI/CD Scripts

1. GitHub Workflows

The primary GitHub Actions workflows are defined in YAML files under the .github/workflows directory. Key workflows include:

  • buf-breaking-check.yml: This workflow performs checks to ensure that any changes made to the protocol buffers do not introduce breaking changes. An example YAML segment is as follows:

    name: Buf Breaking Check
    on:
      push:
        branches:
          - main
      pull_request:
        branches:
          - main
    jobs:
      buf:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout code
            uses: actions/checkout@v2
          - name: Install buf
            run: |
              curl -sSL https://github.com/bufbuild/buf/releases/latest/download/curl-install.sh | bash
          - name: Run buf breaking check
            run: buf break check
    
  • ci.yml: This workflow orchestrates the CI process, which includes building the project and running tests. An example configuration is shown below:

    name: CI
    on: [push, pull_request]
    
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout repository
            uses: actions/checkout@v2
          - name: Set up Go
            uses: actions/setup-go@v2
            with:
              go-version: '1.22'
          - name: Build
            run: go build ./...
          - name: Run tests
            run: go test ./...
    

2. Shell Scripts

Several shell scripts are used to complement the workflows, ensuring that all facets of the CI process are covered. Notable scripts include:

  • buf-format-check.sh: This script checks the formatting of protocol buffer files. Below is a code snippet demonstrating its implementation:

    #!/bin/sh
    buf format check
    
  • buf-generate-check.sh: This script ensures that generated files are up to date. An example of the script is as follows:

    #!/bin/sh
    buf generate --template buf.gen.yaml
    

3. Dockerfile Configuration

The Dockerfile used to build the project is optimized for Go applications and plays a crucial role in the CI/CD process. Notably, it sets up a multi-stage build environment as follows:

# First stage: build the Go application
FROM golang:1.22.2-alpine3.19 AS builder

RUN apk add --no-cache ca-certificates

ENV CGO_ENABLED=0
WORKDIR /go/src/github.com/sourcegraph/zoekt

# Cache dependencies
COPY go.mod go.sum ./
RUN go mod download

# Copy the entire source code
COPY . ./
ARG VERSION
RUN go install -ldflags "-X github.com/sourcegraph/zoekt.Version=$VERSION" ./cmd/...

This Dockerfile handles the setup process, caching dependencies, and compiling the source code. Followed by:

# Final stage: Preparing the runtime image
FROM alpine:3.19 AS zoekt

RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget

COPY install-ctags-alpine.sh .
RUN ./install-ctags-alpine.sh && rm install-ctags-alpine.sh

# Copy binaries from the builder stage
COPY --from=builder /go/bin/* /usr/local/bin/

ENTRYPOINT ["/sbin/tini", "--"]

Summary

The CI/CD automation in the sourcegraph/zoekt project is enabled through a combination of GitHub Actions workflows and shell scripts that work in tandem to ensure code quality and facilitate deployment.

Next Steps

If no CI/CD processes are currently set up in the project, the following steps are recommended:

  • Explore the existing workflows and scripts in the project to understand the CI/CD pipeline.
  • Create a new directory for custom workflows if necessary.
  • Implement basic workflows for building and testing the application.
  • Enhance the CI/CD pipeline incrementally by adding more sophisticated testing and deployment strategies.

By following these steps, contributors can effectively set up a robust CI/CD process for the sourcegraph/zoekt project.