Wednesday, March 9, 2022

How to Configure Gitlab & Docker Dind as CI/CD Platform

On this tutorial, we will using gitlab as CICD platform. And, we are also using docker dind.
First Install repository. Update apt package.
$ sudo apt-get update
$ sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
2. Add docker’s GPG key.
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
3. Set up stable docker repository.
$ echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install docker engine

Update apt package and install docker engine.
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
2. Config docker start on boot.
$ sudo systemctl enable docker.service
$ sudo systemctl enable containerd.service
Config docker access remote
Open docker.sevice with editor.
$ sudo systemctl edit docker.service
2. Place this below code value in docker.service.
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://127.0.0.1:2375
3. Save file
4. Reload systemctl configuration.
5. Restart docker.
$ sudo systemctl restart docker.service
6. Check docker configuration with ss confirm dockerd listening port.
$ sudo ss -lntp | grep dockerd

Install gitlab runner

1. Download the binary for your system.
$ sudo curl -L — output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
2. Give it permission to execute.
$ sudo chmod +x /usr/local/bin/gitlab-runner
3. Create a GitLab Runner user.
$ sudo useradd — comment ‘GitLab Runner’ — create-home gitlab-runner — shell /bin/bash
4. Install and run as a service.
$ sudo gitlab-runner install — user=gitlab-runner — working-directory=/home/gitlab-runner
sudo gitlab-runner start
5. Register runner.
$ sudo gitlab-runner register --url https://gitlab.com/ --registration-token $REGISTRATION_TOKEN

Config gitlab runner

Config /etc/gitlab-runner/config.toml
$ sudo nano /etc/gitlab-runner/config.toml
2. Add this below line for each runner in [runner.docker]
volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock"]
network_mode = "host"
And thats all folks! try with your own responsibility.

0 comments:

Post a Comment