Last active
January 18, 2024 10:18
-
-
Save salyh/9482a4c281a6b130093abeefcd7cde9a to your computer and use it in GitHub Desktop.
Install a self-hosted github runner on ubuntu arm64 or x64 with docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Install a self-hosted github runner on ubuntu arm64 or x64 with docker | |
# This runner can only execute one job concurrently. This is a general limitation of self-hosted github runner. | |
# Do not run multiple github runners on one machine, this cause race conditions. Use more (virtual-) machines. | |
# This script uses svc.sh to install the runner as systemd daemon which is automatically stared when the machine reboots. | |
# The runner gets the label "linux-$ARCH" (and no further default labels) and a default name (which is typically the host name). | |
# You can also run this script via ssh, without copying, from another machine via: | |
# cat install_docker_github_runner_ubuntu.sh | ssh root@xxx.xxx.xxx.xxx | |
# WARNING: This script creates a user USERNAME and assign sudo permissions without password (that means effectively root permissions!) | |
# The user is added to the sudo and docker group and assigned sudo NOPASSWD permissions in /etc/sudoers | |
# get your token from github clicking "New self hosted runner" | |
TOKEN="" | |
REPO="your-github-repo" | |
RUNNER_RELEASE="2.311.0" | |
ARCH="arm64" | |
#ARCH="x64" | |
USERNAME="githubrunner" | |
sudo apt-get -yqq update | |
sudo apt-get -yqq install ca-certificates curl gnupg | |
sudo rm -f /etc/apt/keyrings/docker.gpg | |
sudo install -m 0755 -d /etc/apt/keyrings | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg | |
sudo chmod a+r /etc/apt/keyrings/docker.gpg | |
# Add the repository to Apt sources: | |
echo \ | |
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ | |
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ | |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
sudo apt-get -yqq update | |
sudo apt-get -yqq install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | |
echo "$USERNAME ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/10-$USERNAME | |
create_user(){ | |
echo "Create user $1 as $(id)" | |
sudo useradd -m ${1} -s /bin/bash | |
sudo usermod -aG docker ${1} | |
#sudo usermod -aG sudo ${1} | |
} | |
install_runner(){ | |
echo "Install runner as $(id)" | |
mkdir actions-runner && cd actions-runner | |
curl -Ss -o actions-runner-linux-${1}-${2}.tar.gz -L https://github.com/actions/runner/releases/download/v${2}/actions-runner-linux-${1}-${2}.tar.gz | |
tar xzf ./actions-runner-linux-${1}-${2}.tar.gz | |
./config.sh --url https://github.com/${3} --token "${4}" --no-default-labels --unattended --labels linux-${1} | |
sudo ./svc.sh install | |
sudo ./svc.sh start | |
} | |
sudo bash -c "$(declare -f create_user); create_user $USERNAME" | |
sudo su - "$USERNAME" -c "$(declare -f install_runner); install_runner $ARCH $RUNNER_RELEASE $REPO $TOKEN" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment