Skip to content

Instantly share code, notes, and snippets.

@benoitpetit
Last active May 8, 2024 16:20
Show Gist options
  • Save benoitpetit/cbe19cdd369ec8c1e0defd245d91751f to your computer and use it in GitHub Desktop.
Save benoitpetit/cbe19cdd369ec8c1e0defd245d91751f to your computer and use it in GitHub Desktop.
complete Gitlab installation and a runner with docker
version: '4.5'
services:
# GITLAB
gitlab-web:
image: 'gitlab/gitlab-ce:latest'
restart: always
container_name: gitlab-web
hostname: '192.168.0.14'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://192.168.0.14'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
ports:
- "80:80"
- "443:443"
- "2222:22"
volumes:
- './gitlab/config:/etc/gitlab'
- './gitlab/logs:/var/log/gitlab'
- './gitlab/data:/var/opt/gitlab'
networks:
- gitlab-network
# RUNNER
gitlab-runner1:
image: gitlab/gitlab-runner:alpine
restart: always
container_name: gitlab-runner1
hostname: gitlab-runner1
depends_on:
- gitlab-web
volumes:
- ./config/gitlab-runner:/etc/gitlab-runner
- /var/run/docker.sock:/var/run/docker.sock
networks:
- gitlab-network
networks:
gitlab-network:
name: gitlab-network
#!/bin/sh
###################################################################
# Récuperer le token d'enregistrement du runner via ce lien:
# http://localhost:8080/root/${project}/settings/ci_cd
# Benoit Petit: https://github.com/benoitpetit
###################################################################
# modifier avec votre token
registration_token=XXXXXXXXXXXXXXX
url=http://127.0.0.1
docker exec -it gitlab-runner1 \
gitlab-runner register \
--non-interactive \
--registration-token ${registration_token} \
--locked=false \
--description docker-stable \
--url ${url} \
--executor docker \
--docker-image docker:stable \
--docker-volumes "/var/run/docker.sock:/var/run/docker.sock" \
--docker-network-mode gitlab-network
# executer le script pour inscrire le runner dans Gitlab
@abubaker417
Copy link

how will run gitlab-runner-register.sh file, when we do docker-compose.yml up

@benoitpetit
Copy link
Author

how will run gitlab-runner-register.sh file, when we do docker-compose.yml up

Once the Docker container is executed and configured, navigate to the following address: example.com/root/${project}/settings/ci_cd

Replace ${project} with the name of your project. If you don't have one, you will need to create it and retrieve your registration token at this address. Insert the token into the shell script and run it. (Outside the Docker container), the script connects to the container.

For further automation, manual intervention is required, as I have not proceeded with automation beyond this point.

@Wesseldr
Copy link

Wesseldr commented Feb 15, 2024

Thanks! :-)
I found an auto register version for the runner for inspiration of your work and this combined might be helpful for those passing by:
https://gitlab.com/TyIsI/gitlab-runner-docker-compose/-/blob/main/docker-compose.yml?ref_type=heads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment