我们相信您已经对 Docker 有了一定了解,如果没有,请自行百度。以下脚本为作者自用,仅供参考,不保证绝对的通用性
Dockerfile 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 FROM ubuntu:latestARG RUNNER_VERSION="2.309.0" RUN apt-get update -y && apt-get upgrade -y && useradd -m docker &&\ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends curl libssl-dev python3 python3-pip\ && cd /home/docker && mkdir actions-runner && cd actions-runner \ && curl -O -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION} /actions-runner-linux-x64-${RUNNER_VERSION} .tar.gz \ && tar xzf ./actions-runner-linux-x64-${RUNNER_VERSION} .tar.gz \ && rm ./actions-runner-linux-x64-${RUNNER_VERSION} .tar.gz\ && chown -R docker ~docker && /home/docker/actions-runner/bin/installdependencies.sh \ && apt remove curl libssl-dev python3 python3-pip -y \ && apt autoremove -y && apt clean\ && apt-get update && apt-get install -y sudo lsb-release && apt-get clean all \ && echo "docker ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers \ && sudo -u docker ./config.sh --url https://github.com/<YOUR_ORG_OR_REPO_HERE> --token <YOUR_TOKEN_HERE> USER dockerWORKDIR /home/docker/actions-runner COPY start.sh start.sh CMD ["/home/docker/actions-runner/start.sh" ]
start.sh
请在构建前确保此脚本有执行权限
reset.sh
请在开启自动重置前确认此脚本有执行权限
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #!/bin/sh CONTAINER_NAME="actions-runner" IMAGE_NAME="actions-runner" docker stop $CONTAINER_NAME docker rm $CONTAINER_NAME docker run --name $CONTAINER_NAME -d $IMAGE_NAME echo "The container $CONTAINER_NAME has been reset."
auto_reset.sh
自动重置脚本,需要 root 权限
1 2 3 4 5 while (true );do ./reset.sh sleep 86400 done