Skip to content

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.

ServerPurpose
deploy-serverGitLab, Jenkins, Harbor (requires Docker & Docker Compose)
srv-dataMySQL, Redis, Elasticsearch, etc. (data services)
nginx-gatewayAPI gateway, external to the cluster
K8s clusterKubernetes nodes (for K8s deployments)
Terminal window
mkdir gitlab && cd gitlab
docker-compose.yml
version: "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/gitlab
Terminal window
docker-compose up -d

The default admin account is root. Set a password on first login.

Add your public SSH key in Settings → SSH Keys so you can push code without entering a password.

Download the offline installer from Harbor releases:

Terminal window
tar -xzf harbor-offline-installer-v2.x.0.tgz
cd harbor
cp harbor.yml.tmpl harbor.yml

Edit 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/log
Terminal window
sudo ./install.sh

Default credentials: admin / Harbor12345.

If Harbor uses HTTP (not HTTPS), configure Docker to allow insecure registries:

/etc/docker/daemon.json
{
"insecure-registries": ["192.168.1.180:8077"]
}
Terminal window
sudo systemctl restart docker

Login to verify:

Terminal window
docker login 192.168.1.180:8077 -u admin -p Harbor12345
Terminal window
mkdir jenkins && cd jenkins
docker-compose.yml
version: "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"
Terminal window
docker-compose up -d
  1. Visit http://<your-server>:8989
  2. Get the initial admin password: cat jenkins_home/secrets/initialAdminPassword
  3. Install the recommended plugins
  4. Create an admin user

Three options to make Go available inside the Jenkins container:

  1. Jenkins Go Plugin — Install via Manage Jenkins → Plugin Manager, search for “Go”, then configure under Global Tool Configuration
  2. Copy Go binary into container — Download Go and docker cp it in:
    Terminal window
    docker cp /usr/local/go jenkins:/usr/local/
  3. Bare-metal Jenkins — Install Jenkins directly on the server and use the system Go installation

For Kubernetes deployments, copy goctl and kubectl into the Jenkins container:

Terminal window
# goctl
docker cp $GOPATH/bin/goctl jenkins:/usr/local/bin
# kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
docker cp kubectl jenkins:/usr/local/bin
# K8s config
docker cp ~/.kube jenkins:/root/
  1. Manage Jenkins → Manage Credentials
  2. Add a credential of type SSH Username with private key
  3. Copy the Jenkins server’s public key to GitLab (Settings → SSH Keys)