diff --git a/.gitignore b/.gitignore index 9f11b75..755839a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ .idea/ +.vscode/ +.vs/ +.env \ No newline at end of file diff --git a/Docker Image/Dockerfile.mac b/Docker Image/Dockerfile.mac deleted file mode 100644 index b8e8eb0..0000000 --- a/Docker Image/Dockerfile.mac +++ /dev/null @@ -1,8 +0,0 @@ -FROM ubuntu:latest - -# Copy the start script to the runner's home directory and make it executable -COPY start-mac.sh /home/runner/start.sh -RUN chmod +x /home/runner/start.sh - -# Define the entrypoint -ENTRYPOINT ["/home/runner/start.sh"] \ No newline at end of file diff --git a/Dockerfile.mac b/Dockerfile.mac deleted file mode 100644 index fd144d2..0000000 --- a/Dockerfile.mac +++ /dev/null @@ -1,43 +0,0 @@ -FROM --platform=linux/arm64 ubuntu:latest - -ARG RUNNER_VERSION="2.317.0" - -# Add a user for the runner -RUN useradd -m -s /bin/bash runner - -# Install necessary packages including .NET Core dependencies -RUN apt-get update && apt-get install -y \ - curl \ - jq \ - python3 \ - sudo \ - libicu-dev \ - libkrb5-3 \ - zlib1g \ - iputils-ping \ - openssh-client \ - && rm -rf /var/lib/apt/lists/* - -# Set up the runner user -RUN echo "runner ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers - -WORKDIR /home/runner - -# Set up the actions runner for ARM64 -RUN mkdir -p /home/runner/actions-runner && cd /home/runner/actions-runner \ - && curl -o actions-runner-linux-arm64-${RUNNER_VERSION}.tar.gz -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-arm64-${RUNNER_VERSION}.tar.gz \ - && tar xzf actions-runner-linux-arm64-${RUNNER_VERSION}.tar.gz - -# Install dependencies -RUN cd /home/runner/actions-runner \ - && ./bin/installdependencies.sh - -# Copy the start script and make it executable -COPY start-mac.sh /home/runner/start.sh -RUN chown runner:runner /home/runner/start.sh && chmod +x /home/runner/start.sh - -# Switch to runner user -USER runner - -# Define the entrypoint -ENTRYPOINT ["/home/runner/start.sh"] \ No newline at end of file diff --git a/README.md b/README.md index f23623b..12c0c1d 100644 --- a/README.md +++ b/README.md @@ -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 @@ -14,9 +16,7 @@ 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 @@ -24,8 +24,10 @@ Welcome to the GitHub Self-Hosted Runner Dockerization repository. This project - 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: @@ -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: `/`). - `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 +``` diff --git a/Docker Image/Dockerfile b/Runner/Dockerfile similarity index 60% rename from Docker Image/Dockerfile rename to Runner/Dockerfile index 9dcee63..992de72 100644 --- a/Docker Image/Dockerfile +++ b/Runner/Dockerfile @@ -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 @@ -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 \ @@ -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 diff --git a/Docker Image/start.sh b/Runner/start.sh similarity index 81% rename from Docker Image/start.sh rename to Runner/start.sh index ccbe63e..86c6d92 100644 --- a/Docker Image/start.sh +++ b/Runner/start.sh @@ -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} diff --git a/docker-compose.mac.yml b/docker-compose.mac.yml deleted file mode 100644 index 202c5a5..0000000 --- a/docker-compose.mac.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: "3.8" - -services: - runner: - image: custom-github-runner-mac:latest - platform: linux/arm64 - restart: always - environment: - - REPO=/ - - REG_TOKEN= - - NAME= - volumes: - - /var/run/docker.sock:/var/run/docker.sock - deploy: - mode: replicated - replicas: 1 - resources: - limits: - cpus: "1" - memory: 1G - reservations: - cpus: "0.5" - memory: 512M diff --git a/docker-compose.yml b/docker-compose.yml index 6e8f98d..81c0eb8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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=/ - - REG_TOKEN= - - NAME= - deploy: - mode: replicated - replicas: 2 - resources: - limits: - cpus: '0.5' - memory: 512M - reservations: - cpus: '0.4' - memory: 256M \ No newline at end of file + env_file: .env \ No newline at end of file diff --git a/start-mac.sh b/start-mac.sh deleted file mode 100644 index e1c37e8..0000000 --- a/start-mac.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -REPO=$REPO -REG_TOKEN=$REG_TOKEN -NAME=$NAME - -cd /home/runner/actions-runner || exit -./config.sh --url https://github.com/${REPO} --token ${REG_TOKEN} --name ${NAME} - -cleanup() { - echo "Removing runner..." - ./config.sh remove --unattended --token ${REG_TOKEN} -} - -trap 'cleanup; exit 130' INT -trap 'cleanup; exit 143' TERM - -./run.sh & wait $! \ No newline at end of file