{"id":24645064,"url":"https://github.com/weak-head/go-gitlab-ci","last_synced_at":"2026-04-07T18:32:53.183Z","repository":{"id":232020156,"uuid":"663539793","full_name":"weak-head/go-gitlab-ci","owner":"weak-head","description":"Example of a Go service with the complete GitLab CI/CD pipeline, Helm chart and Kubernetes deployment automation.","archived":false,"fork":false,"pushed_at":"2023-07-07T14:52:30.000Z","size":108,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-03T16:29:48.335Z","etag":null,"topics":["ci-cd","gitlab","gitlab-ci","golang","helm","kubernetes"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weak-head.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-07-07T14:29:21.000Z","updated_at":"2025-11-03T23:58:11.000Z","dependencies_parsed_at":"2024-04-07T13:28:33.842Z","dependency_job_id":null,"html_url":"https://github.com/weak-head/go-gitlab-ci","commit_stats":null,"previous_names":["weak-head/go-gitlab-ci"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/weak-head/go-gitlab-ci","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weak-head%2Fgo-gitlab-ci","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weak-head%2Fgo-gitlab-ci/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weak-head%2Fgo-gitlab-ci/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weak-head%2Fgo-gitlab-ci/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weak-head","download_url":"https://codeload.github.com/weak-head/go-gitlab-ci/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weak-head%2Fgo-gitlab-ci/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31524525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T16:28:08.000Z","status":"ssl_error","status_checked_at":"2026-04-07T16:28:06.951Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci-cd","gitlab","gitlab-ci","golang","helm","kubernetes"],"created_at":"2025-01-25T14:14:12.388Z","updated_at":"2026-04-07T18:32:53.139Z","avatar_url":"https://github.com/weak-head.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go GitLab CI/CD \u003c!-- omit from toc --\u003e\n\n[![go1.20](https://img.shields.io/badge/Go-1.20-00ADD8.svg)](https://go.dev/dl/)\n[![gitlab](https://img.shields.io/badge/GitLab-CI/CD-fc6d27.svg)](https://docs.gitlab.com/ee/ci/)\n[![OpenAPI](https://img.shields.io/badge/OpenAPI-2.0-84e92d.svg)](https://swagger.io/specification/v2/)\n[![docker](https://img.shields.io/badge/Docker-24-0db7ed.svg)](https://docs.docker.com/engine/release-notes/24.0/)\n[![helm3](https://img.shields.io/badge/Helm-3.12-0f1689.svg)](https://helm.sh/)\n\n## Table of Contents \u003c!-- omit from toc --\u003e\n\n- [Overview](#overview)\n- [GitLab CI/CD setup](#gitlab-cicd-setup)\n- [Installation](#installation)\n  - [Configure GitLab Container registry](#configure-gitlab-container-registry)\n  - [Configure GitLab Helm registry](#configure-gitlab-helm-registry)\n  - [Deploy to Kubernetes](#deploy-to-kubernetes)\n- [Building and testing](#building-and-testing)\n- [Troubleshooting](#troubleshooting)\n  - [Render Helm template](#render-helm-template)\n  - [Deploy using local Helm template](#deploy-using-local-helm-template)\n- [CLI usage](#cli-usage)\n  - [Options](#options)\n\n## Overview\n\nThis is a simple Go service with the complete end-to-end GitLab CI/CD pipeline that includes: \n- Compiling API documentation\n- Building executable\n- Running unit tests and race detection\n- Generating code coverage report and publishing it to GitLab Pages\n- Bundling docker image and publishing it to the private GitLab Container Registry\n- Bundling helm chart and publishing it to the private GitLab Package Registry\n- Deploying the application on tag to a configured Kubernetes cluster\n\nThis GitLab CI pipeline tags docker images based on the git tags.\nFor example the git tag `v1.2.0` will result in a docker container with tag `1.2.0` pushed to the private GitLab Container Registry and the application deployed to Kubernetes using `1.2.0` docker image tag.\n\nAlso this example demonstrates the typical Go project structure that includes:\n- [Cobra](https://github.com/spf13/cobra) and [Viper](https://github.com/spf13/viper) setup and configuration\n- HTTP REST API request and middleware handling using [Gin](https://github.com/gin-gonic/gin)\n- RESTful API documentation using [swag](https://github.com/swaggo/swag) and [gin-swagger](https://github.com/swaggo/gin-swagger)\n- gRPC status and health check using [grpc-health-probe](https://github.com/grpc-ecosystem/grpc-health-probe)\n- Customized logger with support of custom fields using [logrus](https://github.com/sirupsen/logrus)\n- Handling correlation id that is provided via [x-request-id](https://http.dev/x-request-id) header.\n- Prometheus metrics using [client_golang](https://github.com/prometheus/client_golang)\n- Simple unit tests and code coverage reports\n- [Multi-stage](https://docs.docker.com/build/building/multi-stage/) Dockerfile\n- Deployment-ready Helm chart with ingress, secrets, auto-scaling and service account for pulling docker images from private registry\n\n## GitLab CI/CD setup\n\nIn order to have the deployment automation, the following environment variables should be set via `Settings -\u003e CI/CD -\u003e Variables` on GitLab side:\n- `KUBERNETES_SERVER` - The endpoint to the Kubernetes API.\n- `KUBERNETES_CERTIFICATE_AUTHORITY_DATA` - The CA configuration for the Kubernetes cluster.\n- `KUBERNETES_USER_NAME` - Kubernetes user name.\n- `KUBERNETES_USER_TOKEN` - Kubernetes user token.\n- `GITLAB_REGISTRY` - GitLab container registry that Kubernetes should use for auth.\n- `GITLAB_REGISTRY_USER_NAME` - Persistent GitLab user name to pull image from the GitLab container registry.\n- `GITLAB_REGISTRY_USER_TOKEN` - Persistent GitLab user token to pull image from the GitLab container registry. \n- `APPLICATION_DOMAIN` - The FQDN the application is deployed to.\n- `APPLICATION_KUBERNETES_NAMESPACE` - The Kubernetes namespace the application is deployed to.\n\nRefer to the [gitlab-ci.yml](./.gitlab-ci.yml) for the configured GitLab CI/CD steps.\n\nThe deployment account could be crated via `Settings -\u003e Repository -\u003e Deploy tokens` (`GITLAB_REGISTRY_USER_NAME` and `GITLAB_REGISTRY_USER_TOKEN`). The account should have the `read_registry` scope in order to pull a docker image from the GitLab Container registry.\n\n## Installation\n\nThis readme refers to the two private registries that I use internally for my home infrastructure.  \nThese two resources are not publicly available and require private GitLab authentication:  \n- GitLab Package registry ( https://git.lothric.net/api/v4/projects/examples%2Fgo%2Fgogin/packages/helm/stable )\n- GitLab Container registry ( https://registry.lothric.net )\n\nMake sure to replace the references to these two private resources with your own links.\n\n### Configure GitLab Container registry\n\nThis docker configuration is used by Kubernetes to pull a docker image from the private GitLab Container registry.\n\n```bash\n# GitLab: Settings -\u003e Repository -\u003e Deploy tokens\nexport GITLAB_CONTAINER_REGISTRY=https://registry.lothric.net\nexport GITLAB_CONTAINER_REGISTRY_USER_NAME=registryUserName\nexport GITLAB_CONTAINER_REGISTRY_USER_TOKEN=registryUserToken\n\n# Create base64 encoded docker auth config\nexport DOCKER_CONFIG=$({\ncat \u003c\u003c EOF\n{\n    \"auths\": {\n        \"${GITLAB_CONTAINER_REGISTRY}\":{\n            \"auth\":\"`echo -n \"${GITLAB_CONTAINER_REGISTRY_USER_NAME}:${GITLAB_CONTAINER_REGISTRY_USER_TOKEN}\" | base64 -w 0`\"\n        }\n    }\n}\nEOF\n} | base64 -w 0)\n```\n\nUse this value for the `image.registry.dockerConfig` in the Helm chart.\n\n### Configure GitLab Helm registry\n\nThis is setup and connection to the private GitLab Helm chart registry.\n\n```sh\n# GitLab: Settings -\u003e Repository -\u003e Deploy tokens\nexport GITLAB_HELM_REGISTRY=https://git.lothric.net/api/v4/projects/examples%2Fgo%2Fgogin/packages/helm/stable\nexport GITLAB_HELM_USER_NAME=deploymentUserName\nexport GITLAB_HELM_USER_TOKEN=deploymentUserToken\n\nhelm repo add \\\n    --username ${GITLAB_HELM_USER_NAME} \\\n    --password ${GITLAB_HELM_USER_TOKEN} \\\n    gogin-repo \\\n    ${GITLAB_HELM_REGISTRY}\n\nhelm repo update\n```\n\n### Deploy to Kubernetes\n\nMake sure ingress is correctly configured on your Kubernetes cluster and you have sub-domain routing rules for the specified application domain.\n\n```sh\nexport DOCKER_CONFIG=ewCAogog...\nexport APPLICATION_DOMAIN=gogin.k8s.lothric.net\n\nhelm upgrade \\\n    --install gogin \\\n    gogin-repo/gogin \\\n    --version 0.2.0 \\\n    --namespace=services \\\n    --create-namespace \\\n    --set=\"image.registry.dockerConfig=${DOCKER_CONFIG}\" \\\n    --set=\"ingress.host.goginDomain=${APPLICATION_DOMAIN}\"\n\nhelm uninstall \\\n    --namespace=services \\\n    gogin\n```\n\n## Building and testing\n\nRun `make help` for the list of available commands. The most useful commands are the following:\n```sh\n# Generate OpenAPI documentation\nmake swagger\n\n# Create executable\nmake build\n\n# Run unit tests\nmake test\n\n# Generate code coverage report\nmake coverage\n```\n\n## Troubleshooting\n\nThis is how you can troubleshoot, test and verify the helm template locally.\n\n### Render Helm template\n\n```sh\nhelm template \\\n    gogin ./helm\n```\n\n### Deploy using local Helm template\n\n```sh\nexport DOCKER_CONFIG=ewodGhwog...\nexport APPLICATION_DOMAIN=gogin.k8s.lothric.net\n\nhelm upgrade \\\n    --install gogin \\\n    ./helm \\\n    --namespace=services \\\n    --create-namespace \\\n    --set=\"image.registry.dockerConfig=${DOCKER_CONFIG}\" \\\n    --set=\"ingress.host.goginDomain=${APPLICATION_DOMAIN}\"\n\nhelm uninstall \\\n    --namespace=services \\\n    gogin\n```\n\n## CLI usage\n\nThis command could be used to start the application locally.\n\u003e `gogin [flags]`\n\n### Options\n```\n      --config string                    Path to config file.\n  -h, --help                             help for gogin\n      --http.gin.mode string             Gin mode. (default \"release\")\n      --http.port string                 HTTP API port. (default \"8080\")\n      --log.formatter string             Log formatter. (default \"json\")\n      --log.level string                 Log level. (default \"info\")\n      --metrics.prometheus.addr string   HTTP address of prometheus metrics endpoint. (default \":8880\")\n      --metrics.prometheus.path string   HTTP URL endpoint of prometheus metrics endpoint. (default \"/metrics\")\n      --node.name string                 Unique server ID.\n      --status.rpc.addr string           Rpc address of status server. (default \":8400\")\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweak-head%2Fgo-gitlab-ci","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweak-head%2Fgo-gitlab-ci","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweak-head%2Fgo-gitlab-ci/lists"}