Skip to content

Commit

Permalink
add script to install docker rootless.
Browse files Browse the repository at this point in the history
  • Loading branch information
k-shlomi committed Aug 28, 2023
1 parent fcc49e4 commit cf0aa93
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ create-teams:
python3 src/utils/github_topics_to_json_file.py && \
python3 src/scripts/create_teams.py teams.json

setup-self-hosted-runner-centos:
sudo yum install -y jq && \
chmod +x src/self-hosted-runners/scripts/setup-self-hosted-runner-centos.sh && \
./src/scripts/self-hosted-runners/setup-self-hosted-runner-centos.sh


help:
@echo "Usage: make [target]"
@echo ""
Expand Down
75 changes: 75 additions & 0 deletions src/scripts/self-hosted-runners/setup-self-hosted-runner-centos.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOL > ~/.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"

0 comments on commit cf0aa93

Please sign in to comment.