Skip to content

Commit

Permalink
Add FORWARD_HOST/FORWARD_PORTS tool to self-hosted-runner container
Browse files Browse the repository at this point in the history
  • Loading branch information
dimikot committed Mar 8, 2024
1 parent 1c5b698 commit de6cede
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docker/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ services:
- GH_TOKEN
- CI_STORAGE_HOST=${CI_STORAGE_HOST:-host:22}
- CI_STORAGE_HOST_PRIVATE_KEY_EVAL=${CI_STORAGE_HOST_PRIVATE_KEY_EVAL_TEST_ONLY?}
- FORWARD_HOST=${CI_STORAGE_HOST:-host}
- FORWARD_PORTS=22/tcp
2 changes: 1 addition & 1 deletion docker/host/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
set -u -e

if [[ "${CI_STORAGE_HOST_PUBLIC_KEY_EVAL:=}" == "" ]]; then
echo "CI_STORAGE_HOST_PUBLIC_KEY_EVAL must be contain a bash script which prints a valid SSH public key (e.g. fetched from AWS Secrets Manager or so)."
echo "CI_STORAGE_HOST_PUBLIC_KEY_EVAL must contain a bash script which prints a valid SSH public key (e.g. fetched from AWS Secrets Manager or so)."
exit 1
fi

Expand Down
2 changes: 2 additions & 0 deletions docker/self-hosted-runner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ ENV GH_LABELS=""
ENV GH_TOKEN=""
ENV CI_STORAGE_HOST=""
ENV CI_STORAGE_HOST_PRIVATE_KEY_EVAL=""
ENV FORWARD_HOST=""
ENV FORWARD_PORTS=""

ENV DEBIAN_FRONTEND=noninteractive
RUN true \
Expand Down
3 changes: 3 additions & 0 deletions docker/self-hosted-runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ self-hosted runners as you want. An example scenario:
artifacts of someone else. If the job then uses ci-storage GitHub action to
restore the files from a slot, it will be very quick, because most of the
files are already there.
5. Additionally, if `FORWARD_HOST` and `FORWARD_PORTS` are passed, the container
sets up rinetd port forwarding from localhost's ports to the ports of
`$FORWARD_HOST`.

The container in this Dockerfile serves only one particular GitHub repository
(controlled by `GH_REPOSITORY` environment variable at boot time). To serve
Expand Down
10 changes: 10 additions & 0 deletions docker/self-hosted-runner/root/entrypoint.00-validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ if [[ "${CI_STORAGE_HOST_PRIVATE_KEY_EVAL:=}" != "" && "$CI_STORAGE_HOST_PRIVATE
echo "If CI_STORAGE_HOST_PRIVATE_KEY_EVAL is passed, it must contain a shell command which prints an SSH private key (e.g. fetched from AWS Secrets Manager or so).";
exit 1;
fi

if [[ "${FORWARD_HOST:=}" != "" && ! "$FORWARD_HOST" =~ ^[-.[:alnum:]]+(:[0-9]+)?$ ]]; then
echo "If FORWARD_HOST is passed, it must be in form of host[:port].";
exit 1;
fi

if [[ "${FORWARD_PORTS:=}" != "" && ! "$FORWARD_PORTS" =~ ^([[:space:]]*[0-9]+(/tcp|/udp)?[[:space:]]*)+$ ]]; then
echo 'If FORWARD_PORTS is passed, it must be in form of (example): "123 456/udp 789/tcp".';
exit 1;
fi
19 changes: 19 additions & 0 deletions docker/self-hosted-runner/root/entrypoint.05-forward.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -u -e

if [[ "$FORWARD_HOST" == "" ]]; then
FORWARD_HOST="$CI_STORAGE_HOST"
fi

if [[ "$FORWARD_HOST" != "" && "$FORWARD_PORTS" != "" ]]; then
FORWARD_HOST="${FORWARD_HOST%%:*}"
for port in $FORWARD_PORTS; do
echo "127.0.0.1 $port $FORWARD_HOST $port";
done > /etc/rinetd.conf

service rinetd start

echo "Forwarding ports:"
cat /etc/rinetd.conf
echo
fi

0 comments on commit de6cede

Please sign in to comment.