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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.idea/
.vscode/
.vs/
.env
8 changes: 0 additions & 8 deletions Docker Image/Dockerfile.mac

This file was deleted.

43 changes: 0 additions & 43 deletions Dockerfile.mac

This file was deleted.

139 changes: 19 additions & 120 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Self-Hosted Runner Dockerization

Based on the original work by [youssefbrr](https://github.com/youssefbrr/self-hosted-runner)

Welcome to the GitHub Self-Hosted Runner Dockerization repository. This project provides a Dockerized solution for setting up a self-hosted GitHub Actions runner.

## Features
Expand All @@ -14,18 +16,18 @@ Welcome to the GitHub Self-Hosted Runner Dockerization repository. This project
- `LICENSE`: The license file for this project.
- `README.md`: The documentation file you are currently reading.
- `docker-compose.yml`: The Docker Compose file to deploy the self-hosted runner on Linux.
- `docker-compose.mac.yml`: The Docker Compose file to deploy the self-hosted runner on macOS.
- `docker-compose.windows.yml`: The Docker Compose file to deploy the self-hosted runner on Windows.
- `Docker Image/`: A directory containing the Dockerfiles and start scripts for building the runner images.
- `Runner/`: A directory containing the Dockerfile and start scripts for building the runner image.

## Getting Started

### Prerequisites

- Docker
- Docker Compose
- Docker Desktop (for macOS and Windows users)
- Get a GitHub runner registration token from your GitHub repository settings. Go to your repository, click on "Settings" > "Actions" > "Runners" > "New self-hosted runner", scroll down to the `Configure` script, and copy the value after `--token`.

### Using Docker Compose on Linux
### Using Docker Compose

1. Clone the repository:

Expand All @@ -36,140 +38,37 @@ Welcome to the GitHub Self-Hosted Runner Dockerization repository. This project

2. Edit the `docker-compose.yml` file to specify your repository, registration token, and runner name.

3. Deploy the self-hosted runner:
```sh
docker-compose up -d
```

### Using Docker Compose on macOS

1. Clone the repository:

```sh
git clone https://github.com/youssefbrr/self-hosted-runner.git
cd self-hosted-runner
```

2. Edit the `docker-compose.mac.yml` file to specify your repository, registration token, and runner name.

3. Deploy the self-hosted runner:
```sh
docker-compose -f docker-compose.mac.yml up -d
```

### Using Docker Compose on Windows

1. Prerequisites:

- Install Docker Desktop for Windows
- Enable WSL 2 (Windows Subsystem for Linux)
- Install Ubuntu 20.04 from the Microsoft Store or enable it through PowerShell

2. Clone the repository:

```sh
git clone https://github.com/youssefbrr/self-hosted-runner.git
cd self-hosted-runner
```

3. Edit the `docker-compose.windows.yml` file to specify your repository, registration token, and runner name.

4. Deploy the self-hosted runner:
```sh
docker-compose -f docker-compose.windows.yml up -d
```

### Building Your Own Docker Image on Linux

1. Clone the repository:

```sh
git clone https://github.com/youssefbrr/self-hosted-runner.git
cd self-hosted-runner
```

2. Build the Docker image:
3. Build the Docker image. This step is especially necessary if you have made changes to the Dockerfile since a previous build:

```sh
cd Docker Image
docker build -t custom-github-runner:latest ./
docker-compose build --no-cache
```

3. Edit the `docker-compose.yml` file to use your custom image.

4. Deploy the self-hosted runner:
```sh
docker-compose up -d
```

### Building Your Own Docker Image on macOS

1. Clone the repository:

```sh
git clone https://github.com/youssefbrr/self-hosted-runner.git
cd self-hosted-runner
docker-compose up
```

2. Build the Docker image:
5. Tear down the deployment if you don't want to leave it running:

```sh
cd Docker Image
docker build -t custom-github-runner-mac:latest -f Dockerfile.mac ./
```

3. Edit the `docker-compose.mac.yml` file to use your custom image.

4. Deploy the self-hosted runner:
```sh
docker-compose -f docker-compose.mac.yml up -d
```

### Building Your Own Docker Image on Windows

1. Clone the repository:

```sh
git clone https://github.com/youssefbrr/self-hosted-runner.git
cd self-hosted-runner
```

2. Build the Docker image:

```sh
cd Docker Image
docker build -t custom-github-runner-windows:latest -f Dockerfile.windows ./
```

3. Edit the `docker-compose.windows.yml` file to use your custom image.

4. Deploy the self-hosted runner:
```sh
docker-compose -f docker-compose.windows.yml up -d
docker-compose down
```

## Configuration

### Environment Variables

Add your environment variables in a file called `.env` in the root directory of the repository. The `.env` file should contain the following variables:

- `REPO`: The GitHub repository to register the runner to (format: `<owner>/<repo>`).
- `REG_TOKEN`: The registration token for the self-hosted runner from the GitHub repository settings.
- `NAME`: The name of the self-hosted runner.

## Notes for macOS Users

For macOS, keep in mind:

1. You need to have Docker Desktop for Mac installed and running.
2. The macOS runner uses different base images and paths compared to the Linux version.
3. Performance may differ from the Linux version due to the virtualization layer.

## Notes for Windows Users

For Windows, keep in mind:
### Example `.env` File

1. You need to have Docker Desktop for Windows installed and running.
2. WSL 2 must be enabled and properly configured.
3. The Ubuntu 20.04 distribution should be installed through WSL.
4. Performance may vary depending on your system's virtualization settings.
5. Make sure your Windows system meets the minimum requirements for running Docker Desktop and WSL 2.
```env
REPO=dymaptic/GeoBlazor
REG_TOKEN=abcd1234efgh5678ijk
NAME=self-hosted-runner
```
18 changes: 16 additions & 2 deletions Docker Image/Dockerfile → Runner/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

ARG RUNNER_VERSION="2.317.0"
ARG RUNNER_VERSION="2.325.0"
ARG DEBIAN_FRONTEND=noninteractive

# Update and upgrade the system
Expand All @@ -13,6 +13,15 @@ RUN useradd -m docker
RUN apt install -y --no-install-recommends \
curl build-essential libssl-dev libffi-dev python3 python3-venv python3-dev python3-pip jq
RUN apt-get -yqq install ssh
# Install Git 2.18 or higher
RUN apt install -y git && git --version
# Install PowerShell
RUN apt update && apt install -y wget apt-transport-https software-properties-common \
&& wget -q https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb \
&& apt update && apt install -y powershell
# Install Azure CLI
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
# Set up the actions runner
RUN cd /home/docker && mkdir actions-runner && cd actions-runner \
&& curl -o actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz \
Expand All @@ -21,9 +30,14 @@ RUN cd /home/docker && mkdir actions-runner && cd actions-runner \
# Change ownership to docker user and install dependencies
RUN chown -R docker /home/docker && /home/docker/actions-runner/bin/installdependencies.sh

# Grant permissions to docker user for /usr/share/dotnet
RUN mkdir -p /usr/share/dotnet && chown docker:docker /usr/share/dotnet

# Copy the start script and make it executable
COPY start.sh /start.sh
RUN chmod +x /start.sh
# Ensure start.sh has LF line endings
RUN sed -i 's/\r$//' /start.sh

# Switch to docker user
USER docker
Expand Down
2 changes: 2 additions & 0 deletions Docker Image/start.sh → Runner/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ REPO=$REPO
REG_TOKEN=$REG_TOKEN
NAME=$NAME

echo "Initializing GitHub Actions Runner named ${NAME} for repository ${REPO}."

cd /home/docker/actions-runner || exit
./config.sh --url https://github.com/${REPO} --token ${REG_TOKEN} --name ${NAME}

Expand Down
23 changes: 0 additions & 23 deletions docker-compose.mac.yml

This file was deleted.

21 changes: 4 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
version: '3.8'

services:
runner:
image: youssefbrr/github-actions:latest # You can use this image or build your own
build:
context: ./Runner
dockerfile: Dockerfile
restart: always
environment:
- REPO=<owner>/<repo>
- REG_TOKEN=<reg-token-for-self-hosted-runner>
- NAME=<runner-name>
deploy:
mode: replicated
replicas: 2
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.4'
memory: 256M
env_file: .env
18 changes: 0 additions & 18 deletions start-mac.sh

This file was deleted.