added gitlab runner install

This commit is contained in:
Snogard 2023-07-07 16:37:43 +02:00
parent 08b6af03b7
commit a86baecffb
5 changed files with 123 additions and 0 deletions

25
src/commands/install.sh Normal file
View File

@ -0,0 +1,25 @@
#!/bin/bash
prefix=install
rootFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
scriptFolder=${rootFolder}/${prefix}
scriptName=$1
scriptPath=${scriptFolder}/${prefix}-${scriptName}.sh
instanceName=$2
instanceMainPort=$3
instanceVersion=$4
if test -f "$scriptPath"; then
if [[ ! -x "$scriptPath" ]]; then
sudo chmod +x $scriptPath
fi
echo "Executing: $scriptPath $instanceName $instanceMainPort $instanceVersion"
$scriptPath $instanceName $instanceMainPort $instanceVersion $5 $6 $7
else
echo "Error file not found: ${scriptPath}"
fi

View File

@ -0,0 +1,39 @@
#!/bin/baash
source /opt/kaido/src/libs/bash/lib.sh
option=$1
token=$2
# setup
imageName=docker.io/gitlab/gitlab-runner:alpine3.18-v16.1.0
containerName=gitlab-runner
architecture=$(arch)
srcFolder=/mnt/storage/containers/$containerName/
srcSock=/var/run/user/1001/podman/podman.sock
# pre install
create_folder $srcFolder
stop_and_remove_container $containerName
# install
# systemctl --user enable --now podman.service
podman run -d \
--name $containerName \
-v "$srcFolder":/etc/gitlab-runner \
-v "$srcSock":/var/run/docker.sock \
$imageName
if [ $option == "register" ]; then
sleep 5
podman exec gitlab-runner \
gitlab-runner register -n \
--url https://gitlab.com/ \
--registration-toke $token \
--executor docker \
--description "Snogard's $architecture server" \
--tag-list "docker,$architecture"
fi
systemctl --user enable --now $containerName

3
src/libs/bash/envs.sh Normal file
View File

@ -0,0 +1,3 @@
#TODO: make envs configurable
CONTAINERS_FOLDER="/mnt/storage/containers"
MASTER_CONFIG_FOLDER="/opt/kaido/configuration"

View File

@ -0,0 +1,54 @@
function stop_and_remove_container()
{
local name=$1
if podman ps --all | grep -qi ${name}; then
echo "Stopping old container"
systemctl --user disable $name
systemctl --user stop $name
echo "Removing old container"
podman rm $name
fi
}
function create_folder(){
local path=$1
if [ ! -d "${path}" ]; then
echo "Creating folder path at ${path}"
mkdir -p $path
fi
}
function symlink_folder()
{
local src=$1
local dst=$2
if [ ! -L "${dst}" ]; then
echo "Creating symlink from ${src} to ${dst}"
ln -s $src $dst
fi
}
function ensure_file(){
local src=$1
local dst=$2
if [ ! -f "${dst}" ]; then
if [ -f "${src}"]; then
echo "Copy ${src} to ${dst}"
cp "${src}" "${dst}"
else
echo "Creating empty file at ${dst}"
touch "${dst}"
fi
fi
}
function open_port()
{
local port=$1
#TODO: check if port is already open
sudo ufw allow $port
}

2
src/libs/bash/lib.sh Normal file
View File

@ -0,0 +1,2 @@
source /opt/src/libs/bash/lib/envs.sh
source /opt/src/libs/bash/functions.sh