diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..7390eb6 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +REPOSITORY_OWNER=TourmalineCore +REG_TOKEN= +RUNNER_GROUP=Default +LABELS=self-hosted \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..94f480d --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/DockerImage/Dockerfile b/DockerImage/Dockerfile new file mode 100644 index 0000000..fb8a666 --- /dev/null +++ b/DockerImage/Dockerfile @@ -0,0 +1,63 @@ +FROM ubuntu:24.04 + +ARG RUNNER_VERSION="2.334.0" +ARG DOCKER_VERSION="28.5.2" + +# curl and sudo is needed to install packages +# libicu-dev is needed to run a runner +# ca-certificates is needed to install docker +RUN apt-get update -y && \ + apt-get upgrade -y && \ + apt-get install -y \ + curl \ + sudo \ + ca-certificates + +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=5:${DOCKER_VERSION}-1~ubuntu.24.04~noble \ + docker-ce-cli=5:${DOCKER_VERSION}-1~ubuntu.24.04~noble \ + docker-compose-plugin && \ + rm -rf /var/lib/apt/lists/* + +RUN curl -fsSL --retry 3 "https://github.com/moby/moby/raw/v${DOCKER_VERSION}/hack/dind" -o /usr/local/bin/dind \ + && chmod a+x /usr/local/bin/dind + +# Runner cannot be run as the root user, so it`s needed to create a separate user +RUN useradd -m runner && \ + usermod -aG docker runner && \ + usermod -aG sudo runner && \ + echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers + +ARG TARGETARCH + +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 + +RUN /home/runner/actions-runner/bin/installdependencies.sh + +USER runner + +# Copy the start script and make it executable +COPY start.sh /start.sh +RUN sudo chmod +x /start.sh + +# Without this volume docker can't mount and use the overlay2 storage-driver, and will instead use the slower VFS +# Also without this volume and overlay2, errors occur when creating a cluster using kind +VOLUME /var/lib/docker + +ENTRYPOINT ["/start.sh"] diff --git a/DockerImage/start.sh b/DockerImage/start.sh new file mode 100644 index 0000000..8387536 --- /dev/null +++ b/DockerImage/start.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +cd /home/runner/actions-runner || exit + +# Cleanup docker dirs because docker fails to start if they haven`t been cleaned up after restart +sudo rm -f /var/run/docker.pid +sudo rm -rf /var/run/docker + +./config.sh --url https://github.com/${REPOSITORY_OWNER} --token ${REG_TOKEN} --runnergroup $RUNNER_GROUP --labels $LABELS + +sudo /usr/local/bin/dind dockerd --log-level=error & + +cleanup() { + echo "Removing runner..." + ./config.sh remove --token ${REG_TOKEN} +} + +trap 'cleanup' TERM + +./run.sh & wait $! \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4016317 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +services: + runner: + build: + dockerfile: Dockerfile + context: ./DockerImage + restart: unless-stopped + env_file: .env + privileged: true + deploy: + mode: replicated + replicas: 2 + resources: + limits: + cpus: '2' + memory: 2G + reservations: + cpus: '0.4' + memory: 256M