NewCode CLOUD — 20% off your first month on all cloud VPSClaim

GitLab Runner on Hong Kong VPS: Self-Hosted CI/CD Pipeline (2026)

· 5 min read

GitLab’s shared runners are located in Europe and the US — pulling Docker images, cloning repos, and deploying to your Hong Kong VPS across the Pacific adds 30–90 seconds to every pipeline. A self-hosted GitLab Runner on your HK VPS runs CI/CD jobs locally: Docker image pulls hit the HK Docker Hub mirror, deployments are local SSH commands, and the entire pipeline completes 2–4× faster. This guide covers installing and configuring a GitLab Runner that integrates with gitlab.com or your self-hosted GitLab CE.


Step 1: Install GitLab Runner

<code">curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | bash
apt install -y gitlab-runner docker.io

# Add gitlab-runner user to docker group (for Docker executor)
usermod -aG docker gitlab-runner

gitlab-runner --version

Step 2: Register Runner with GitLab

<code"># Get registration token from:
# gitlab.com → Your Project → Settings → CI/CD → Runners → New project runner

gitlab-runner register \
  --non-interactive \
  --url "https://gitlab.com/" \
  --token "YOUR_REGISTRATION_TOKEN" \
  --name "hk-vps-runner" \
  --executor "docker" \
  --docker-image "docker:24-dind" \
  --docker-privileged \
  --docker-volumes "/var/run/docker.sock:/var/run/docker.sock" \
  --tag-list "hk,docker,production" \
  --run-untagged false

# Or register as shell executor (for deployments that need host access)
gitlab-runner register \
  --non-interactive \
  --url "https://gitlab.com/" \
  --token "YOUR_REGISTRATION_TOKEN" \
  --name "hk-vps-shell-runner" \
  --executor "shell" \
  --tag-list "hk,deploy"

systemctl enable --now gitlab-runner
gitlab-runner status

Step 3: Configure Runner for Performance

<code"># /etc/gitlab-runner/config.toml — tune for HK VPS
concurrent = 4   # Max 4 concurrent jobs (adjust for your vCPU count)
check_interval = 3

[session_server]
  session_timeout = 1800

[[runners]]
  name = "hk-vps-docker"
  url = "https://gitlab.com/"
  token = "RUNNER_TOKEN"
  executor = "docker"
  limit = 2  # This runner: max 2 concurrent jobs

  [runners.docker]
    image = "docker:24-dind"
    privileged = true
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]

    # Use local Docker Hub mirror to speed up image pulls
    pull_policy = ["if-not-present", "always"]  # Use cached images first

    # Share Docker layer cache between jobs
    cache_dir = "/cache"

    # Resource limits per job
    memory = "2g"
    cpus = "2.0"

    # Network mode for service containers (PostgreSQL, Redis in tests)
    network_mode = "bridge"

[[runners]]
  name = "hk-vps-deploy"
  url = "https://gitlab.com/"
  token = "DEPLOY_RUNNER_TOKEN"
  executor = "shell"
  limit = 1  # Only 1 deploy at a time
  [runners.custom_build_dir]
    enabled = true

Step 4: .gitlab-ci.yml Pipeline

<code"># .gitlab-ci.yml — complete pipeline for a Node.js app deployed to HK VPS
stages:
  - test
  - build
  - deploy

variables:
  DOCKER_DRIVER: overlay2
  IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
  DEPLOY_HOST: "deploy@YOUR_VPS_IP"
  DEPLOY_PATH: "/var/www/myapp"

# ── TEST ──────────────────────────────────────────────
test:unit:
  stage: test
  image: node:20-alpine
  tags: [hk, docker]
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - node_modules/
  services:
    - postgres:16-alpine   # Test DB spun up as service container
  variables:
    POSTGRES_DB: test_db
    POSTGRES_USER: test_user
    POSTGRES_PASSWORD: testpass
    DATABASE_URL: postgresql://test_user:testpass@postgres/test_db
  before_script:
    - npm ci --cache .npm --prefer-offline
  script:
    - npm run test:unit
    - npm run test:integration
  coverage: '/Lines\s*:\s*(\d+\.\d+)%/'

test:lint:
  stage: test
  image: node:20-alpine
  tags: [hk, docker]
  script:
    - npm ci --prefer-offline
    - npm run lint
    - npm run typecheck

# ── BUILD ─────────────────────────────────────────────
build:docker:
  stage: build
  image: docker:24
  tags: [hk, docker]
  services:
    - docker:24-dind
  before_script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
  script:
    - docker build --cache-from $CI_REGISTRY_IMAGE:latest
        --tag $IMAGE_NAME
        --tag $CI_REGISTRY_IMAGE:latest .
    - docker push $IMAGE_NAME
    - docker push $CI_REGISTRY_IMAGE:latest
  only:
    - main
    - /^release\/.*/

# ── DEPLOY ────────────────────────────────────────────
deploy:production:
  stage: deploy
  image: alpine:latest
  tags: [hk, deploy]
  environment:
    name: production
    url: https://yourdomain.com
  before_script:
    - apk add --no-cache openssh-client
    - eval $(ssh-agent -s)
    - echo "$DEPLOY_SSH_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - echo "$DEPLOY_HOST_KEY" > ~/.ssh/known_hosts
  script:
    - |
      ssh $DEPLOY_HOST << SSHEOF
        cd $DEPLOY_PATH
        echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY \
          -u $CI_REGISTRY_USER --password-stdin
        docker pull $IMAGE_NAME
        docker stop myapp || true
        docker rm myapp || true
        docker run -d \
          --name myapp \
          --restart unless-stopped \
          -p 127.0.0.1:3000:3000 \
          --env-file .env.production \
          $IMAGE_NAME
        sleep 5
        curl -sf http://127.0.0.1:3000/health && echo "Deploy OK"
      SSHEOF
  when: manual   # Require manual trigger for production
  only:
    - main

Step 5: Docker Layer Cache for Faster Builds

<code"># Dockerfile optimised for layer caching (dependencies rarely change)
FROM node:20-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production

FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=deps /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json .
EXPOSE 3000
CMD ["node", "dist/index.js"]

Local Docker Registry Mirror on HK VPS

<code"># Speed up Docker pulls by running a local registry mirror
docker run -d \
  --name registry-mirror \
  --restart unless-stopped \
  -p 127.0.0.1:5000:5000 \
  -e REGISTRY_PROXY_REMOTEURL=https://registry-1.docker.io \
  -v /opt/registry:/var/lib/registry \
  registry:2

# Configure Docker to use mirror
cat > /etc/docker/daemon.json << 'EOF'
{
  "registry-mirrors": ["http://127.0.0.1:5000"]
}
EOF
systemctl restart docker

Step 6: Pipeline Performance Optimisation

<code"># Speed up pipelines on HK runner:

# 1. Cache node_modules between jobs
cache:
  key: "$CI_COMMIT_REF_SLUG-$CI_JOB_NAME"
  paths:
    - .npm/       # npm cache dir
    - node_modules/
  policy: pull-push

# 2. Use --prefer-offline to use cache without network
before_script:
  - npm ci --cache .npm --prefer-offline

# 3. Parallel test execution
test:
  parallel: 3   # Run 3 parallel test jobs
  script:
    - npm test -- --shard=$CI_NODE_INDEX/$CI_NODE_TOTAL

# 4. Only run expensive jobs on main branch
deploy:
  only:
    - main
  when: manual

Pipeline Speed: HK Runner vs GitLab Shared Runners

Stage GitLab Shared (EU) HK VPS Runner
Docker image pull (node:20) 45–90s 5–15s (local cache)
npm ci (cached) 20–40s 3–8s
Unit tests 30–60s 15–30s (more CPU)
Docker build (cached) 60–120s 20–45s
Deploy (SSH to HK VPS) 15–30s + network 5–10s (local)
Total pipeline ~5–7 min ~1.5–3 min

Conclusion

A self-hosted GitLab Runner on your Hong Kong VPS cuts pipeline duration by 50–70% compared to GitLab’s shared EU runners — Docker images pull from a local cache in seconds instead of minutes, deployments are local SSH commands, and test databases spin up on the same LAN. The runner tags system lets you route specific jobs (tests, deployments) to the HK runner while keeping others on shared infrastructure, giving teams a practical hybrid CI/CD setup without fully abandoning GitLab’s managed compute.

Speed up your pipelines: Browse Server.HK Hong Kong VPS plans — a 4 GB VPS runs GitLab Runner with 4 concurrent Docker jobs while still hosting your production application.

Related articles

More in VPS & ServersServer setup guides