github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/scripts/gitlab/runners/setup.sh (about) 1 2 #!/bin/bash 3 # Combination of steps from https://confluence.nvidia.com/pages/viewpage.action?pageId=2565826909#id-%F0%9F%A6%8AGitLabRunnerSetup-ContainerRuntime 4 # Run as root 5 set -e 6 7 SCRIPTS_DIR=$(dirname $(realpath -s $0)) 8 TMP_DOWNLOAD="$SCRIPTS_DIR/tmp_download" 9 10 SYSBOX_VER=v0.6.4 11 SYSBOX_PKG=sysbox-ce_0.6.4-0.linux_amd64.deb 12 RUNNER_VERSION=16.9.1-1 13 14 # Create the directory if it doesn't already exist 15 if [ ! -d "$TMP_DOWNLOAD" ]; then 16 mkdir -p "$TMP_DOWNLOAD" 17 fi 18 cd $TMP_DOWNLOAD 19 20 install_docker() { 21 # Add Docker's official GPG key 22 apt-get update && apt-get install -y ca-certificates curl jq 23 install -m 0755 -d /etc/apt/keyrings 24 curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc 25 chmod a+r /etc/apt/keyrings/docker.asc 26 27 # Add the repository to Apt sources 28 echo \ 29 "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ 30 $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ 31 tee /etc/apt/sources.list.d/docker.list > /dev/null 32 33 # Install the Docker packages 34 apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin 35 36 # Check if the Docker system service is running 37 systemctl status docker --no-pager 38 39 # Assuming this script is run as sudo, add the calling user to the docker group 40 usermod -aG docker $SUDO_USER 41 42 echo "Docker installed" 43 echo "Log out and back in or run 'newgrp docker' to allow root-less docker access (required for minikube). Then re-run start_runner.sh" 44 } 45 46 confirm_docker_rm() { 47 # Call with a prompt string or use a default 48 read -r -p "${1:-Are you sure you want to remove all Docker containers? [y/N]} " response 49 case "$response" in 50 [yY][eE][sS]|[yY]) 51 true 52 ;; 53 *) 54 false 55 ;; 56 esac 57 } 58 59 install_sysbox() { 60 echo "Installing Sysbox Docker runtime" 61 # Download the latest Sysbox .deb package on the GitHub releases page (https://github.com/nestybox/sysbox/releases). We want the Linux x86-64 (AMD64) variant. 62 wget https://downloads.nestybox.com/sysbox/releases/$SYSBOX_VER/$SYSBOX_PKG 63 64 if confirm_docker_rm; then 65 echo "Removing all Docker containers..." 66 docker rm $(docker ps -a -q) -f || true 67 else 68 echo "Canceled setup script due to user request." 69 exit 1 70 fi 71 72 # Install Sysbox. 73 apt install ./$SYSBOX_PKG 74 75 # Check if the Sysbox system service is running. 76 systemctl status sysbox --no-pager 77 78 # Delete the Sysbox .deb package. 79 rm $SYSBOX_PKG 80 81 # If docker daemon json is empty, create a json config object 82 if [ ! -s /etc/docker/daemon.json ]; then 83 echo '{}' | tee /etc/docker/daemon.json 84 fi 85 86 # Set Docker Engine's default container runtime to sysbox-runc. We can't read from and write to the same file: https://github.com/jqlang/jq/issues/2152 87 jq '. + { 88 "default-runtime": "sysbox-runc", 89 "runtimes": { 90 "sysbox-runc": { 91 "path": "/usr/bin/sysbox-runc" 92 } 93 } 94 }' /etc/docker/daemon.json | tee /etc/docker/daemon-staging.json && mv -f /etc/docker/daemon-staging.json /etc/docker/daemon.json 95 96 # Restart the Docker Engine system service. 97 systemctl restart docker 98 } 99 100 install_runner() { 101 echo "Installing Gitlab Runner" 102 #Add the official GitLab repository. 103 curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash 104 # Install GitLab Runner. 105 apt install gitlab-runner=$RUNNER_VERSION 106 } 107 108 start_runner() { 109 # Enable the GitLab Runner system service in system mode (runs as a newly-created gitlab-runner user with root privileges). 110 systemctl enable gitlab-runner 111 # Check if the GitLab Runner system service is running. 112 systemctl status gitlab-runner --no-pager 113 } 114 115 # Install docker if needed 116 if ! docker info > /dev/null 2>&1; then 117 echo "Installing Docker" 118 install_docker 119 fi 120 121 defaultRuntime=$(docker info --format '{{.DefaultRuntime}}') 122 123 # TODO: Restore later if we need docker available in runners 124 # if [ "$defaultRuntime" != "sysbox-runc" ]; then 125 # echo "Installing sysbox and setting as default Docker runtime" 126 # install_sysbox 127 # fi 128 129 # Install minikube if needed 130 if [ ! -f /usr/local/bin/minikube ]; then 131 echo "Installing minikube" 132 curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 133 install minikube-linux-amd64 /usr/local/bin/minikube 134 mkdir -p /var/local/minikube -m 777 135 fi 136 137 # Install kubectl if needed 138 if [ ! -f /usr/local/bin/kubectl ]; then 139 echo "Installing kubectl" 140 curl -LO https://dl.k8s.io/release/v1.29.2/bin/linux/amd64/kubectl 141 install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl 142 fi 143 144 # Install gitlab-runner if needed 145 if ! dpkg -l | grep -qw gitlab-runner; then 146 install_runner 147 fi 148 149 # Start gitlab-runner service if needed 150 if ! systemctl is-active --quiet gitlab-runner; then 151 start_runner 152 fi 153 154 cd $SCRIPTS_DIR 155 rm -rf "$TMP_DOWNLOAD"