Sign inSign up

sergk/ci-golang

By sergk

•Updated about 1 year ago

Homepage https://gitlab.com/kuberocketci/ci-golang

Image
Integration & delivery
Developer tools
0

333

sergk/ci-golang repository overview

⁠GitLab CI/CD Templates for Go Applications

This repository contains a collection of reusable GitLab CI/CD templates that can be included in Go application repositories' .gitlab-ci.yml files.

⁠Overview

This library provides a set of standardized CI/CD templates specifically designed for Go applications. The templates are configurable through inputs and can be easily integrated into any GitLab project.

⁠Templates

⁠Common Template (templates/common.yml)

A base template that provides shared functionality used by other templates, including Go caching, build jobs, Helm validation, and more.

⁠Build Template (templates/build.yml)

A comprehensive template for building, testing, packaging, and publishing Go applications.

⁠Usage
include:
  - local: 'templates/build.yml'
    inputs:
      codebase_name: 'my-go-app'
      go_image: 'docker.io/golang:1.24-bookworm'
      image_registry: 'docker.io/myusername'
⁠Inputs
NameDescriptionDefault
stage_preparePreparation stage name'prepare'
stage_buildBuild stage name'build'
stage_testTest stage name'test'
stage_packagePackage stage name'package'
stage_publishPublish stage name'publish'
codebase_nameName of the Go project'gin-go'
go_imageGo Docker image to use'docker.io/golang:1.24-bookworm'
chart_dirDirectory containing Helm charts'deploy-templates'
image_registryDocker registry for image publishing'docker.io/${DOCKERHUB_USERNAME}'
⁠Review Template (templates/review.yml)

A template for running CI checks on merge requests and other non-main branches.

⁠Usage
include:
  - local: 'templates/review.yml'
    inputs:
      codebase_name: 'my-go-app'
⁠Inputs
NameDescriptionDefault
stage_preparePreparation stage name'prepare'
stage_buildBuild stage name'build'
stage_testTest stage name'test'
stage_verifyVerification stage name'verify'
codebase_nameName of the Go project'gin-go'
go_imageGo Docker image to use'docker.io/golang:1.24-bookworm'
chart_dirDirectory containing Helm charts'deploy-templates'

⁠Features

  • Go Build & Test: Standardized build and test with caching
  • Coverage Reporting: Integrated code coverage with Cobertura format
  • SonarQube Analysis: Built-in SonarQube integration for both MRs and main branch
  • Docker Image Building: buildkit-based Docker image builds
  • Helm Chart Validation: Chart linting and documentation generation
  • Dockerfile Linting: Using Hadolint
  • Git Tagging: Automated versioning with Git tags

⁠Required CI/CD Variables

To use these templates, you'll need to configure these CI/CD variables:

  • SONAR_HOST_URL: URL to your SonarQube instance
  • SONAR_TOKEN: Authentication token for SonarQube
  • DOCKERHUB_USERNAME: Docker Hub username for image publishing
  • DOCKERHUB_PASSWORD: Docker Hub password for image publishing
  • GITLAB_ACCESS_TOKEN: GitLab access token for Git operations

⁠Implementation Notes

⁠Visible Lint Fix Job

The sample .gitlab-ci.yml file includes a special job called visible-job-lint-fix in the .pre stage:

visible-job-lint-fix:
  stage: .pre
  rules: [ when: never ]
  script: [ echo "This is a visible job (but never run)" ]

This job is deliberately configured to never run (rules: [ when: never ]), but remains visible in the GitLab CI/CD interface. Its purpose is to address a linting issue in the GitLab CI validator - specifically to satisfy the requirement that there must be at least one visible job in the pipeline definition, even when all actual jobs come from included templates.

Note: This is a workaround for GitLab's CI/CD linting rules. Without this dummy job, the pipeline might fail validation if all actual jobs are defined in included templates and conditionally excluded based on pipeline rules.

⁠Development

To contribute to these templates:

  1. Ensure all templates are thoroughly tested
  2. Keep backward compatibility in mind
  3. Document all inputs and their default values

⁠License

This project is licensed under the Apache License, Version 2.0 - see the LICENSE.md⁠ file for details.

Tag summary

Content type

Image

Digest

sha256:b2c0d7f2e…

Size

10 MB

Last updated

about 1 year ago

docker pull sergk/ci-golang:fa2213f5