CI/CD Setup
Before deploying go-zero services, you need a CI/CD pipeline. This guide walks through setting up GitLab (source control), Jenkins (build & deploy), and Harbor (container registry) using Docker Compose.
Infrastructure Overview
Section titled “Infrastructure Overview”| Server | Purpose |
|---|---|
deploy-server | GitLab, Jenkins, Harbor (requires Docker & Docker Compose) |
srv-data | MySQL, Redis, Elasticsearch, etc. (data services) |
nginx-gateway | API gateway, external to the cluster |
| K8s cluster | Kubernetes nodes (for K8s deployments) |
GitLab
Section titled “GitLab”Deploy with Docker Compose
Section titled “Deploy with Docker Compose”mkdir gitlab && cd gitlabversion: "3"
services: gitlab: image: "gitlab/gitlab-ce:latest" container_name: "gitlab" restart: always hostname: "192.168.1.180" environment: TZ: "Asia/Shanghai" GITLAB_OMNIBUS_CONFIG: | external_url 'http://192.168.1.180' gitlab_rails['gitlab_shell_ssh_port'] = 2222 unicorn['port'] = 8888 ports: - "80:80" - "2222:22" volumes: - ./etc:/etc/gitlab - ./data:/var/opt/gitlab - ./logs:/var/log/gitlabdocker-compose up -dThe default admin account is root. Set a password on first login.
Configure SSH Key
Section titled “Configure SSH Key”Add your public SSH key in Settings → SSH Keys so you can push code without entering a password.
Harbor (Container Registry)
Section titled “Harbor (Container Registry)”Deploy Harbor
Section titled “Deploy Harbor”Download the offline installer from Harbor releases:
tar -xzf harbor-offline-installer-v2.x.0.tgzcd harborcp harbor.yml.tmpl harbor.ymlEdit harbor.yml:
hostname: 192.168.1.180
http: port: 8077
# Comment out https section for local dev#https:# port: 443# certificate: /your/certificate/path# private_key: /your/private/key/path
data_volume: /root/harbor/data
log: level: info local: rotate_count: 50 rotate_size: 200M location: /root/harbor/logsudo ./install.shDefault credentials: admin / Harbor12345.
Configure Docker Daemon
Section titled “Configure Docker Daemon”If Harbor uses HTTP (not HTTPS), configure Docker to allow insecure registries:
{ "insecure-registries": ["192.168.1.180:8077"]}sudo systemctl restart dockerLogin to verify:
docker login 192.168.1.180:8077 -u admin -p Harbor12345Jenkins
Section titled “Jenkins”Deploy with Docker Compose
Section titled “Deploy with Docker Compose”mkdir jenkins && cd jenkinsversion: "3"services: jenkins: image: "jenkins/jenkins:lts" container_name: jenkins restart: always environment: - TZ=Asia/Shanghai user: root ports: - "8989:8080" - "50000:50000" volumes: - "./jenkins_home:/var/jenkins_home" - "/var/run/docker.sock:/var/run/docker.sock" - "/usr/bin/docker:/usr/bin/docker"docker-compose up -dInitial Setup
Section titled “Initial Setup”- Visit
http://<your-server>:8989 - Get the initial admin password:
cat jenkins_home/secrets/initialAdminPassword - Install the recommended plugins
- Create an admin user
Install Go in Jenkins
Section titled “Install Go in Jenkins”Three options to make Go available inside the Jenkins container:
- Jenkins Go Plugin — Install via Manage Jenkins → Plugin Manager, search for “Go”, then configure under Global Tool Configuration
- Copy Go binary into container — Download Go and
docker cpit in:Terminal window docker cp /usr/local/go jenkins:/usr/local/ - Bare-metal Jenkins — Install Jenkins directly on the server and use the system Go installation
Mount Additional Tools
Section titled “Mount Additional Tools”For Kubernetes deployments, copy goctl and kubectl into the Jenkins container:
# goctldocker cp $GOPATH/bin/goctl jenkins:/usr/local/bin
# kubectlcurl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"chmod +x kubectldocker cp kubectl jenkins:/usr/local/bin
# K8s configdocker cp ~/.kube jenkins:/root/Add GitLab Credentials
Section titled “Add GitLab Credentials”- Manage Jenkins → Manage Credentials
- Add a credential of type SSH Username with private key
- Copy the Jenkins server’s public key to GitLab (Settings → SSH Keys)
What’s Next
Section titled “What’s Next”- Bare Metal Deployment — Deploy directly to physical servers
- Docker Deployment — Build and run with Docker
- Kubernetes Deployment — Deploy to a K8s cluster