Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
REPOSITORY_OWNER=TourmalineCore
REG_TOKEN=<TO_BE_MODIFIED!!!>
RUNNER_GROUP=Default
LABELS=self-hosted
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.gitattributes
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
54 changes: 54 additions & 0 deletions DockerImage/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM ubuntu:24.04

RUN apt-get update -y && \
apt-get upgrade -y && \
apt-get install -y \
curl \
sudo \
ca-certificates

ARG DOCKER_VERSION="28.5.2"

# Install Docker
RUN install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && \
chmod a+r /etc/apt/keyrings/docker.asc && \
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null && \
apt-get update && \
apt install -y --no-install-recommends \
containerd.io \
docker-buildx-plugin \
docker-ce-cli=5:${DOCKER_VERSION}-1~ubuntu.24.04~noble \
docker-compose-plugin && \
rm -rf /var/lib/apt/lists/*

# Add a user named runner and add it to sudoers
RUN useradd -m runner && \
usermod -aG sudo runner && \
echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers

ARG TARGETARCH
ARG RUNNER_VERSION="2.334.0"

# Set up the actions runner
RUN ARCH=$([ "$TARGETARCH" = "amd64" ] && echo x64 || echo arm64) && \
cd /home/runner && \
mkdir actions-runner && \
cd actions-runner && \
curl -o actions-runner-linux-${ARCH}-${RUNNER_VERSION}.tar.gz -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-${ARCH}-${RUNNER_VERSION}.tar.gz && \
tar xzf ./actions-runner-linux-${ARCH}-${RUNNER_VERSION}.tar.gz

# Install the dependencies required to run the runner
RUN /home/runner/actions-runner/bin/installdependencies.sh

USER runner

# Copy the script and make it executable
COPY start.sh /start.sh
RUN sudo chmod +x /start.sh

ENTRYPOINT ["/start.sh"]
29 changes: 29 additions & 0 deletions DockerImage/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

cd /home/runner/actions-runner || exit

./config.sh --url https://github.com/${REPOSITORY_OWNER} --token ${REG_TOKEN} --runnergroup $RUNNER_GROUP --labels $LABELS

# Get the ID of the group to which the file belongs
export DOCKER_GID=$(stat -c '%g' /var/run/docker.sock)

# Checking if a group exists
if getent group "${DOCKER_GID}" >/dev/null; then
# Adding a user to the group because it has already been created
export DOCKER_GNAME=$(stat -c '%G' /var/run/docker.sock)
sudo usermod -aG ${DOCKER_GNAME} runner
else
# Create a group if one doesn't already exist, and add the user to it
sudo groupadd -g ${DOCKER_GID} docker
sudo usermod -aG docker runner
fi

cleanup() {
echo "Removing runner..."
./config.sh remove --token ${REG_TOKEN}
}

trap 'cleanup' TERM

# Start a new session for the runner user to make new group settings accessible in the runner and start runner
sudo -E -u runner bash -c ./run.sh & wait $!
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
# github-self-hosted-runners-template
# github-self-hosted-runners-template

> These repositories helped us create this repository:
> 1. [Groupe-3D/self-hosted-runner](https://github.com/Groupe-3D/self-hosted-runner)

## Prerequisites

1. Install Docker Desktop (Windows, macOS) or Docker Engine (Linux)

## Configuring runners

1. Open `github-self-hosted-runners-template` repo folder

2. Copy .env.example file with env variables as .env

3. Get runner registration token from GitHub -> <ORGANIZATION_NAME> -> Settings -> Actions -> Runners -> New runner

Or use this link: https://github.com/organizations/<ORGANIZATION_NAME>/settings/actions/runners/new
>Change `<ORGANIZATION_NAME>` to your organization name

4. Open .env file

4. Paste the copied token instead of `<TO_BE_MODIFIED!!!>`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add info about place where i can find tis token on page


5. Change TourmalineCore to your organization name

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add info about another env variales in file and why its needed and how i can use it (that this variables means)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

especially for labels


## Run runners

To run runners execute the following command:
```bash
docker compose up -d --build
```

## Troubleshooting on Mac

### 1. Runner is unavailable when the Mac screen turns off
This issue occurs because the Mac and its apps go into sleep mode when the screen turns off due to inactivity. To fix this, enable the following setting:
> `System Settings -> Energy -> Prevent automatic sleeping when the display is off`

### 2. Once the power goes out, you need to go to the Mac and turn it on manually
To make your Mac enable when powered on, enable the following setting:
> `System Settings -> Energy -> Start up automatically after power failure`

### 3. Docker and runner won't start until a password is entered
Yes, on a Mac, apps only launch after you enter your password. To avoid entering a password and automatically log in when the Mac starts, enable the following setting:
> `System Settings -> Users & Groups -> Automatically log in as`
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
runner:
build:
dockerfile: Dockerfile
context: ./DockerImage
restart: unless-stopped
env_file: .env
deploy:
mode: replicated
replicas: 2
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '0.1'
memory: 256M
Comment on lines +10 to +17

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add to readme info about these options for configuration runners count and resources

volumes:
- /var/run/docker.sock:/var/run/docker.sock