Add setup-forgejo-runner.sh
This commit is contained in:
commit
3e72240970
1 changed files with 84 additions and 0 deletions
84
setup-forgejo-runner.sh
Normal file
84
setup-forgejo-runner.sh
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
FORGEJO_URL=${FORGEJO_URL:-https://git.service.openshell.network/}
|
||||||
|
FORGEJO_RUNNER_TOKEN=${FORGEJO_RUNNER_TOKEN:-}
|
||||||
|
|
||||||
|
RUNNER_DIR="${RUNNER_DIR:-~/docker/ForgejoRunner}"
|
||||||
|
RUNNER_USER=${RUNNER_USER:-forgejo-runner}
|
||||||
|
RUNNER_NAME="${RUNNER_NAME:-$(hostname)}"
|
||||||
|
RUNNER_LABELS="${RUNNER_LABELS:-docker:docker://ghcr.io/catthehacker/ubuntu:runner-latest,runner-latest-arm:docker://ghcr.io/catthehacker/ubuntu:runner-latest,runner-latest:docker://ghcr.io/catthehacker/ubuntu:runner-latest,runner:docker://ghcr.io/catthehacker/ubuntu:runner-latest,runner-22.04-arm:docker://ghcr.io/catthehacker/ubuntu:runner-22.04,runner-20.04-arm:docker://ghcr.io/catthehacker/ubuntu:runner-20.04,runner-22.04:docker://ghcr.io/catthehacker/ubuntu:runner-22.04,runner-20.04:docker://ghcr.io/catthehacker/ubuntu:runner-20.04}"
|
||||||
|
|
||||||
|
mkdir -p "${RUNNER_DIR}"
|
||||||
|
cd "${RUNNER_DIR}"
|
||||||
|
|
||||||
|
if [[ -f compose.yaml ]]; then
|
||||||
|
echo The file compose.yaml exists, bailing... > /dev/stderr
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${FORGEJO_URL}" ]; then
|
||||||
|
read -p "Forgejo URL: " FORGEJO_URL
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${FORGEJO_RUNNER_TOKEN}" ]; then
|
||||||
|
read -p "Registration token: " FORGEJO_RUNNER_TOKEN
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
mkdir -p data/.cache
|
||||||
|
touch data/.runner
|
||||||
|
|
||||||
|
if ! id ${RUNNER_USER} >/dev/null 2>&1; then
|
||||||
|
echo Creating ${RUNNER_USER} user...
|
||||||
|
sudo useradd ${RUNNER_USER}
|
||||||
|
fi
|
||||||
|
|
||||||
|
FORGEJO_UID=$(id -u ${RUNNER_USER})
|
||||||
|
FORGEJO_GID=$(id -g ${RUNNER_USER})
|
||||||
|
|
||||||
|
|
||||||
|
chmod 775 data/.runner
|
||||||
|
chmod 775 data/.cache
|
||||||
|
|
||||||
|
sudo chown -R ${FORGEJO_UID}:${FORGEJO_GID} data/.cache
|
||||||
|
sudo chown -R ${FORGEJO_UID}:${FORGEJO_GID} data/.runner
|
||||||
|
sudo chmod g+s data/.runner
|
||||||
|
sudo chmod g+s data/.cache
|
||||||
|
|
||||||
|
|
||||||
|
cat > compose.yaml <<EOF
|
||||||
|
services:
|
||||||
|
docker-in-docker:
|
||||||
|
image: docker:dind
|
||||||
|
container_name: 'docker_dind'
|
||||||
|
privileged: 'true'
|
||||||
|
command: ['dockerd', '-H', 'tcp://0.0.0.0:2375', '--tls=false']
|
||||||
|
restart: 'unless-stopped'
|
||||||
|
|
||||||
|
runner:
|
||||||
|
image: 'data.forgejo.org/forgejo/runner:6'
|
||||||
|
links:
|
||||||
|
- docker-in-docker
|
||||||
|
depends_on:
|
||||||
|
docker-in-docker:
|
||||||
|
condition: service_started
|
||||||
|
container_name: 'runner'
|
||||||
|
environment:
|
||||||
|
DOCKER_HOST: tcp://docker-in-docker:2375
|
||||||
|
# User without root privileges, but with access to `./data`.
|
||||||
|
user: ${FORGEJO_UID}:${FORGEJO_GID}
|
||||||
|
volumes:
|
||||||
|
- ./data:/data
|
||||||
|
restart: 'unless-stopped'
|
||||||
|
|
||||||
|
command: '/bin/sh -c "sleep 5; forgejo-runner daemon"'
|
||||||
|
EOF
|
||||||
|
|
||||||
|
docker compose up -d
|
||||||
|
docker compose exec -it runner forgejo-runner register \
|
||||||
|
--no-interactive \
|
||||||
|
--token ${FORGEJO_RUNNER_TOKEN} \
|
||||||
|
--instance ${FORGEJO_URL} \
|
||||||
|
--name "${RUNNER_NAME}" \
|
||||||
|
--labels "${RUNNER_LABELS}"
|
Loading…
Add table
Add a link
Reference in a new issue