Gitlab setup
January 8, 2025Less than 1 minute
Create docker-compose.yml
services:
gitlab:
image: gitlab/gitlab-ce:17.7.0-ce.0
container_name: roger-gitlab
restart: always
hostname: "gitlab.luojia.work"
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.luojia.work:8929'
gitlab_rails['gitlab_shell_ssh_port'] = 2424
ports:
- "8929:8929"
- "2424:22"
volumes:
- "./volumes/config:/etc/gitlab"
- "./volumes/logs:/var/log/gitlab"
- "./volumes/data:/var/opt/gitlab"
shm_size: "256m"
gitlab-runner:
image: gitlab/gitlab-runner:v17.7.0
container_name: roger-gitlab-runner
restart: always
depends_on:
- gitlab
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "./volumes/config/gitlab-runner:/etc/gitlab-runner"
- "./volumes/bin/docker:/usr/bin/docker"
command: ["run", "--user=root", "--working-directory=/home/gitlab-runner"]
privileged: true
Modify permission for docker.sock
sudo chmod 666 /var/run/docker.sock
Register the runner to gitlab
docker exec -it roger-gitlab-runner gitlab-runner register
Configure .gitlab-ci.yml file
stages:
- build
- deploy
build:
stage: build
tags:
- docker
script:
- docker build -t $IMAGE_NAME:$IMAGE_TAG .
deploy:
stage: deploy
tags:
- docker
before_script:
- chmod 400 $SSH_KEY
script:
- ssh -o StrictHostKeyChecking=no -i $SSH_KEY ${DEPLOY_USER}@${DEPLOY_HOST} "
kind load docker-image $IMAGE_NAME:$IMAGE_TAG --name roger &&
kubectl apply -f $K8S_CONFIG_PATH
"