Skip to content

Instantly share code, notes, and snippets.

@b23prodtm
Last active December 30, 2022 00:32
Show Gist options
  • Save b23prodtm/f0f51a85eaf5e7bcdd2edd1f4157cda3 to your computer and use it in GitHub Desktop.
Save b23prodtm/f0f51a85eaf5e7bcdd2edd1f4157cda3 to your computer and use it in GitHub Desktop.
Setup a Unix Runner on GitLab. To perform our own gitlab-runner at home.
#!/usr/bin/env bash
# to enable all branches, remove .gitlab-ci only:[/pr-*/] tags
shared=/srv
[ ! -e /etc/os-release ] && shared=/Users/Shared && echo "Not a Linux system.. srv=$shared"
shared_tags='light, docker, c3.small.x86'
PROJECT_REGISTRATION_TOKEN=''
[ "$#" -gt 0 ] && PROJECT_REGISTRATION_TOKEN=$1
printf "token PROJECT_REGISTRATION_TOKEN=%s\n" "${PROJECT_REGISTRATION_TOKEN}"
gitlab=$(docker ps -q -a -f "name=gitlab-runner")
[ "$gitlab" != "" ] && docker stop $gitlab && docker rm -f $gitlab
docker run -d --name gitlab-runner --restart always \
-v $shared/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest \
&& docker run --rm -v $shared/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register \
--non-interactive \
--executor "docker" \
--docker-image docker:dind \
--url "https://gitlab.com/" \
--registration-token "$PROJECT_REGISTRATION_TOKEN" \
--description "docker-runner" \
--tag-list "${shared_tags}" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"
#!/usr/bin/env bash
# to enable all branches, remove .gitlab-ci only:[/pr-*/] tags
shared=/srv
[ ! -e /etc/os-release ] && shared=/Users/Shared && echo "Not a Linux system.. srv=$shared"
shared_tags='light, docker, c3.small.x86'
PROJECT_REGISTRATION_TOKEN=''
[ "$#" -gt 0 ] && PROJECT_REGISTRATION_TOKEN=$1
printf "token PROJECT_REGISTRATION_TOKEN=%s\n" "${PROJECT_REGISTRATION_TOKEN}"
help=("" \
" HOW TO REGISTER NEW RUNNER SHELL" \
"" \
" sudo apt update -y && sudo apt install gitlab-runner \\" \
" && sudo rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/*" \
" sudo gitlab-runner register" \
" sudo /usr/sbin/usermod -G admin gitlab-runner" \
" sudo apt-get update -y && "\
" sudo apt-get install -y moreutils" \
" sudo gitlab-runner list" \
" sudo sed -i.old -E -e \"/ExecStart/s/(--user)[^\\\"]**/\\\\1 root/\" /etc/systemd/system/gitlab-ci-multi-runner.service" \
" sudo sed -i.old -E -e \"s/(concurrent).*/\\\\1 = 4/\" /etc/gitlab-runner/config.toml" \
" sudo systemctl daemon-reload" \
" sudo systemctl restart gitlab-runner" \
"" \
" KUBESPRAY TESTS" \
" wget https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb" \
" sudo dpkg -i vagrant_2.2.9_x86_64.deb" \
" sudo apt build-dep vagrant ruby-libvirt" \
" sudo apt install -yqq qemu libvirt-daemon-system libvirt-clients ebtables dnsmasq-base" \
" sudo apt install -yqq libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev" \
" sudo apt install -yqq qemu-kvm vagrant-libvirt moreutils" \
" sudo systemctl enable --now libvirtd && sudo kvm-ok" \
" sudo find /usr -name '*.pyc' -delete" \
" sudo pip3 install --upgrade pip setuptools" \
" vagrant -v && vagrant plugin install vagrant-libvirt" \
"")
printf "%s\n" "${help[@]}"
if command -v gitlab-runner; then
gitlab-runner register \
--non-interactive \
--executor "docker" \
--docker-image docker:dind \
--url "https://gitlab.com/" \
--registration-token "$PROJECT_REGISTRATION_TOKEN" \
--description "docker-runner" \
--tag-list "${shared_tags}" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"
fi
@echo off
set shared=C:\Users\Shared
echo %shared%
set shared_tags=light, packet, c3.small.x86
set /p PROJECT_REGISTRATION_TOKEN="Gitlab token :"
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÎÍÍ%
echo ° Token %PROJECT_REGISTRATION_TOKEN% °
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ%
set configdir=%shared%\gitlab-runner\config
rem
rem grant ACL to all users
rem
echo %configdir%
powershell -Command "& {get-acl $env:configdir | fl;}"
set /p user="Get-User ?"
powershell -Command "& {$acl = get-acl $env:configdir; $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($env:user, 'Ful
lControl', 'Allow'); $acl.SetAccessRule($rule); $acl | set-acl $env:configdir;}"
rem
rem run and register runner
rem
for /f %%i in ('docker ps -q -a -f ''name=gitlab-runner'' 2^> nul') do (
docker rm %%i
)
docker run -d --name gitlab-runner --restart always ^
-v %shared%\gitlab-runner\config:/etc/gitlab-runner ^
-v /var/run/docker.sock:/var/run/docker.sock ^
gitlab/gitlab-runner:latest
docker run --rm -v %shared%\gitlab-runner\config:/etc/gitlab-runner ^
gitlab/gitlab-runner register ^
--non-interactive ^
--executor "docker" ^
--docker-image docker:dind ^
--url "https://gitlab.com/" ^
--registration-token "%PROJECT_REGISTRATION_TOKEN%" ^
--description "docker-runner" ^
--tag-list "docker,%shared_tags%" ^
--run-untagged="true" ^
--locked="false" ^
--access-level="not_protected"
@b23prodtm
Copy link
Author

b23prodtm commented May 30, 2020

usage: . ./nix-runner.sh <PROJECT_REGISTRATION_TOKEN>

PROJECT_REGISTRATION_TOKEN is stored in Gitlab Settings/ CI / CD "Runners"

@b23prodtm
Copy link
Author

b23prodtm commented Jun 4, 2020

usage: wind-runner.bat

Pick the Get-User Value to grant All Users permissions to gitlab-runner
Optimize the gitlab-runner concurrent jobs. To do the following, browse to:
C:\Users\Shared\gitlab-runner\config\config.toml

    concurrent=<number-of-jobs>
    [[runners]]

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