Skip to content

Commit

Permalink
Start a docker daemon in background
Browse files Browse the repository at this point in the history
  • Loading branch information
brmzkw committed Oct 9, 2023
1 parent 438faf9 commit 7f064e1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
40 changes: 34 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
# This Dockerfile is used to run a self-hosted GitHub runner on Koyeb.

# Unfortunately, docker:dind only exists for alpine, so we can't use it as a
# base image. As a workaround, we first install system dependencies and copy the
# binaries from docker:dind.
FROM ubuntu

ARG RUNNER_VERSION
RUN test -n "$RUNNER_VERSION"
RUN apt-get update

RUN apt-get install -y \
btrfs-progs \
e2fsprogs \
iptables \
openssl \
xfsprogs \
xz-utils \
pigz \
fuse-overlayfs

COPY --from=docker:dind /etc/subuid /etc/subuid
COPY --from=docker:dind /etc/subgid /etc/subgid

# Install various dependencies that might be useful in a runner
COPY --from=docker:dind /usr/local/bin/ /usr/local/bin/
COPY --from=docker:dind /usr/local/libexec/docker/cli-plugins/ /usr/local/libexec/docker/cli-plugins/

# Then, we install various dependencies that might be useful in a runner.
# This is minimalist and we might want to extend this list. See
# https://github.com/actions/runner-images/tree/main to check what is installed
# on GitHub runners by default.
RUN apt-get update && apt-get install -y \
libicu70 \
ca-certificates \
Expand All @@ -18,19 +41,24 @@ RUN apt-get update && apt-get install -y \
git \
docker.io

RUN pip install poetry

# Finally, let's install the runner.
RUN groupadd -r runner && useradd -r -g runner runner
RUN mkdir -p /home/runner

WORKDIR /home/runner
RUN chown -R runner:runner /home/runner

# In Oct. 2023, the last RUNNER_VERSION was 2.310.0.
ARG RUNNER_VERSION
RUN test -n "$RUNNER_VERSION"

ADD https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz /home/runner/
RUN tar xzf /home/runner/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz
RUN rm -f /home/runner/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz

USER runner
#ENV RUNNER_ALLOW_RUNASROOT=1

COPY ./entrypoint.sh /entrypoint.sh
CMD ["/entrypoint.sh"]

ENTRYPOINT ["/entrypoint.sh"]
27 changes: 20 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

set -e

# Run docker daemon
/usr/local/bin/dockerd-entrypoint.sh --tls=false >/dev/null 2>&1 &

echo "Waiting for docker daemon to start..."
while true;
do
test -S /var/run/docker.sock && echo "ok!" && break
echo -n .
sleep .5
done

chown runner:runner /var/run/docker.sock

for required_env in \
REPO_URL \
GITHUB_TOKEN \
Expand Down Expand Up @@ -40,14 +53,14 @@ then
exit 1
fi

./config.sh \
--url "$REPO_URL" \
--token "$RUNNER_TOKEN" \
--name "koyeb-runner-$(hostname)" \
su -c "./config.sh \
--url '$REPO_URL' \
--token '$RUNNER_TOKEN' \
--name 'koyeb-runner-$(hostname)' \
--runnergroup default \
--no-default-labels \
--labels "$RUNNER_LABELS" \
--labels '$RUNNER_LABELS' \
--work workspace \
--replace
--replace" runner

exec ./run.sh
exec su -c "/usr/local/bin/dockerd-entrypoint.sh ./run.sh" runner

0 comments on commit 7f064e1

Please sign in to comment.