From 22d0d0bee3a2c66cc0ed0dd6002c10ded50e7324 Mon Sep 17 00:00:00 2001 From: jit-shlomi Date: Mon, 28 Aug 2023 12:59:28 +0300 Subject: [PATCH] add script to install docker rootless. --- Makefile | 6 ++ .../install-rootless-docker-centos.sh | 75 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 src/scripts/self-hosted-runners/install-rootless-docker-centos.sh diff --git a/Makefile b/Makefile index 8e5626f..e6a8511 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,12 @@ create-teams: python src/utils/github_topics_to_json_file.py && \ python src/scripts/create_teams.py teams.json +setup-self-hosted-runner-centos: + sudo yum install -y jq && \ + chmod +x src/scripts/setup-self-hosted-runner-centos.sh && \ + ./src/scripts/setup-self-hosted-runner-centos.sh + + help: @echo "Usage: make [target]" @echo "" diff --git a/src/scripts/self-hosted-runners/install-rootless-docker-centos.sh b/src/scripts/self-hosted-runners/install-rootless-docker-centos.sh new file mode 100644 index 0000000..f03851e --- /dev/null +++ b/src/scripts/self-hosted-runners/install-rootless-docker-centos.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# Exit on error +set -e + +# Check if script is run as root +if [ "$EUID" -eq 0 ]; then + echo "Please run this script as a non-root user." + exit 1 +fi + +# Install required packages only if they aren't already installed + +# Check for shadow-utils +if ! rpm -q shadow-utils &> /dev/null; then + echo "Installing shadow-utils..." + sudo yum install -y shadow-utils +fi + +# Check for curl or curl-minimal +if ! rpm -q curl &> /dev/null && ! rpm -q curl-minimal &> /dev/null; then + echo "Installing curl..." + sudo yum install -y curl +fi + +# Check for iptables +if ! rpm -q iptables &> /dev/null; then + echo "Installing iptables..." + sudo yum install -y iptables +fi + +# Download Docker installation script +echo "Installing Docker in rootless mode..." +curl -fsSL https://get.docker.com/rootless | sh + +# Set environment variables +echo "Updating environment variables..." +USER_NAME=$(whoami) +USER_ID=$(id -u) + +echo "export PATH=\$PATH:/home/$USER_NAME/bin" >> ~/.bashrc +echo "export DOCKER_HOST=unix:///run/user/$USER_ID/docker.sock" >> ~/.bashrc +source ~/.bashrc + +# Set up Docker as a systemd user service + +# Create the systemd service directory and file +mkdir -p ~/.config/systemd/user/ +cat < ~/.config/systemd/user/docker-rootless.service +[Unit] +Description=Docker Rootless +After=network-online.target + +[Service] +Type=simple +Restart=always +RestartSec=5s +ExecStart=/home/%u/bin/dockerd-rootless.sh + +[Install] +WantedBy=default.target +EOL + +# Reload systemd user instance, enable and start the service +systemctl --user daemon-reload +systemctl --user enable docker-rootless +systemctl --user start docker-rootless + +# Ensure user-level systemd services start at boot +sudo loginctl enable-linger $(whoami) + +echo "Docker in rootless mode has been installed and set to start on boot." + +sudo yum install libicu -y +echo "Installed libicu Dotnet for the github agent" \ No newline at end of file