|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | +#------------------------------------------------------------------------------------# |
| 3 | +#Ubuntu 22.04 LTS :: https://wiki.ubuntu.com/Releases |
| 4 | +# Based on :: https://github.com/pkgforge/devscripts/blob/main/Github/Runners/ubuntu-systemd-base.dockerfile |
| 5 | +# Preconfigured with: Systemd + SSHD + Docker |
| 6 | +# REF :: https://docs.docker.com/engine/reference/builder/ |
| 7 | +# LINT :: https://github.com/hadolint/hadolint |
| 8 | +## Note :: NO SPACE after EOS using heredoc `EOS` to write multiline scripts |
| 9 | +#FROM nestybox/ubuntu-jammy-systemd-docker:latest |
| 10 | +# URL: https://hub.docker.com/r/azathothas/gh-runner-aarch64-ubuntu |
| 11 | +FROM ubuntu:latest |
| 12 | +#FROM ubuntu:jammy |
| 13 | +#------------------------------------------------------------------------------------# |
| 14 | +##Base Deps |
| 15 | +ENV DEBIAN_FRONTEND="noninteractive" |
| 16 | +RUN <<EOS |
| 17 | + #Base |
| 18 | + export DEBIAN_FRONTEND="noninteractive" |
| 19 | + echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections |
| 20 | + packages="apt-transport-https apt-utils bash ca-certificates coreutils curl dos2unix fdupes findutils git gnupg2 imagemagick jq locales locate moreutils nano ncdu p7zip-full rename rsync software-properties-common texinfo sudo tmux unzip util-linux xz-utils wget zip" |
| 21 | + #Install |
| 22 | + apt update -y -qq |
| 23 | + for pkg in $packages; do apt install -y --ignore-missing "$pkg"; done |
| 24 | + #Install_Re |
| 25 | + for pkg in $packages; do apt install -y --ignore-missing "$pkg"; done |
| 26 | + #unminimize : https://wiki.ubuntu.com/Minimal |
| 27 | + yes | unminimize |
| 28 | + #Python |
| 29 | + apt install python3 -y |
| 30 | + #Test |
| 31 | + python --version 2>/dev/null ; python3 --version 2>/dev/null |
| 32 | + #Install pip: |
| 33 | + #python3 -m ensurepip --upgrade ; pip3 --version |
| 34 | + #curl -qfsSL "https://bootstrap.pypa.io/get-pip.py" -o "$SYSTMP/get-pip.py" && python3 "$SYSTMP/get-pip.py" |
| 35 | + packages="libxslt-dev lm-sensors pciutils procps python3-distro python-dev-is-python3 python3-lxml python3-netifaces python3-pip python3-venv sysfsutils virt-what" |
| 36 | + for pkg in $packages; do apt install -y --ignore-missing "$pkg"; done |
| 37 | + pip install --break-system-packages --upgrade pip || pip install --upgrade pip |
| 38 | + #Misc |
| 39 | + pip install ansi2txt --break-system-packages --force-reinstall --upgrade |
| 40 | + #pipx |
| 41 | + pip install pipx --upgrade 2>/dev/null |
| 42 | + pip install pipx --upgrade --break-system-packages 2>/dev/null |
| 43 | +EOS |
| 44 | +#------------------------------------------------------------------------------------# |
| 45 | +##Systemd installation |
| 46 | +RUN <<EOS |
| 47 | + #SystemD |
| 48 | + apt update -y |
| 49 | + packages="dbus iptables iproute2 libsystemd0 kmod systemd systemd-sysv udev" |
| 50 | + for pkg in $packages; do apt install -y --ignore-missing "$pkg"; done |
| 51 | + ##Prevents journald from reading kernel messages from /dev/kmsg |
| 52 | + # echo "ReadKMsg=no" >> "/etc/systemd/journald.conf" |
| 53 | + #Disable systemd services/units that are unnecessary within a container. |
| 54 | + #systemctl mask "systemd-udevd.service" |
| 55 | + #systemctl mask "systemd-udevd-kernel.socket" |
| 56 | + #systemctl mask "systemd-udevd-control.socket" |
| 57 | + #systemctl mask "systemd-modules-load.service" |
| 58 | + #systemctl mask "sys-kernel-debug.mount" |
| 59 | + #systemctl mask "sys-kernel-tracing.mount" |
| 60 | + #Housekeeping |
| 61 | + apt clean -y |
| 62 | + rm -rf "/lib/systemd/system/getty.target" 2>/dev/null |
| 63 | + rm -rf "/lib/systemd/system/systemd"*udev* 2>/dev/null |
| 64 | + rm -rf "/usr/share/doc/"* 2>/dev/null |
| 65 | + rm -rf "/usr/share/local/"* 2>/dev/null |
| 66 | + rm -rf "/usr/share/man/"* 2>/dev/null |
| 67 | + rm -rf "/var/cache/debconf/"* 2>/dev/null |
| 68 | + rm -rf "/var/lib/apt/lists/"* 2>/dev/null |
| 69 | + rm -rf "/var/log/"* 2>/dev/null |
| 70 | + rm -rf "/var/tmp/"* 2>/dev/null |
| 71 | + rm -rf "/tmp/"* 2>/dev/null |
| 72 | +EOS |
| 73 | +# Make use of stopsignal (instead of sigterm) to stop systemd containers. |
| 74 | +STOPSIGNAL SIGRTMIN+3 |
| 75 | +#------------------------------------------------------------------------------------# |
| 76 | + |
| 77 | +#------------------------------------------------------------------------------------# |
| 78 | +##Create User + Setup Perms |
| 79 | +RUN <<EOS |
| 80 | + #Add runner |
| 81 | + useradd --create-home "runner" |
| 82 | + #Set password |
| 83 | + echo "runner:runneradmin" | chpasswd |
| 84 | + #Add runner to sudo |
| 85 | + usermod -aG "sudo" "runner" |
| 86 | + usermod -aG "sudo" "root" |
| 87 | + #Passwordless sudo for runner |
| 88 | + echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" >> "/etc/sudoers" |
| 89 | +EOS |
| 90 | +##Change Default shell for runner to bash |
| 91 | +RUN <<EOS |
| 92 | + #Check current shell |
| 93 | + grep runner "/etc/passwd" |
| 94 | + #Change to bash |
| 95 | + usermod --shell "/bin/bash" "runner" 2>/dev/null |
| 96 | + curl -qfsSL "https://raw.githubusercontent.com/pkgforge/devscripts/refs/heads/main/Linux/.bashrc" -o "/etc/bash.bashrc" |
| 97 | + dos2unix --quiet "/etc/bash.bashrc" 2>/dev/null |
| 98 | + ln --symbolic --force "/etc/bash.bashrc" "/home/runner/.bashrc" 2>/dev/null |
| 99 | + ln --symbolic --force "/etc/bash.bashrc" "/root/.bashrc" 2>/dev/null |
| 100 | + ln --symbolic --force "/etc/bash.bashrc" "/etc/bash/bashrc" 2>/dev/null |
| 101 | + #Recheck |
| 102 | + grep runner "/etc/passwd" |
| 103 | +EOS |
| 104 | +##Set PATH [Default: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin] /command is s6-tools |
| 105 | +#ENV PATH "/command:${PATH}" |
| 106 | +#RUN echo 'export PATH="/command:${PATH}"' >> "/etc/bash.bashrc" |
| 107 | +#------------------------------------------------------------------------------------# |
| 108 | + |
| 109 | +#------------------------------------------------------------------------------------# |
| 110 | +##Install Docker |
| 111 | +RUN <<EOS |
| 112 | + #Install Docker |
| 113 | + rm -rf "/var/lib/apt/lists/"* |
| 114 | + cd "$(mktemp -d)" >/dev/null 2>&1 |
| 115 | + curl -qfsSL "https://get.docker.com" -o "./get-docker.sh" && sh "./get-docker.sh" |
| 116 | + cd - >/dev/null 2>&1 |
| 117 | + #Add runner to docker |
| 118 | + usermod -aG "docker" "runner" |
| 119 | + #Add Docker Completions |
| 120 | + curl -qfsSL "https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker" > "/etc/bash_completion.d/docker.sh" |
| 121 | + #Confiure Docker Opts |
| 122 | + #Remove Hardlimit |
| 123 | + sed -i 's/ulimit -Hn/# ulimit -Hn/g' "/etc/init.d/docker" |
| 124 | + #Install Additional Deps |
| 125 | + packages="btrfs-progs fuse-overlayfs fuse3 kmod libfuse3-dev zfs-dkms" |
| 126 | + for pkg in $packages; do apt install -y --ignore-missing "$pkg"; done |
| 127 | +EOS |
| 128 | +#------------------------------------------------------------------------------------# |
| 129 | + |
| 130 | +#------------------------------------------------------------------------------------# |
| 131 | +##Addons |
| 132 | +RUN <<EOS |
| 133 | + #Addons |
| 134 | + #https://github.com/Azathothas/Arsenal/blob/main/misc/Linux/install_dev_tools.sh |
| 135 | + curl -qfsSL "https://raw.githubusercontent.com/pkgforge/devscripts/refs/heads/main/Linux/install_bins_curl.sh" -o "./tools.sh" |
| 136 | + dos2unix --quiet "./tools.sh" && chmod +x "./tools.sh" |
| 137 | + bash "./tools.sh" 2>/dev/null || true ; rm -rf "./tools.sh" |
| 138 | +EOS |
| 139 | +#------------------------------------------------------------------------------------# |
| 140 | + |
| 141 | +#------------------------------------------------------------------------------------# |
| 142 | +##Build Tools |
| 143 | +RUN <<EOS |
| 144 | + apt update -y |
| 145 | + packages="aria2 automake bc binutils b3sum build-essential ca-certificates ccache diffutils dos2unix findutils gawk lzip jq libtool libtool-bin make musl musl-dev musl-tools p7zip-full rsync texinfo wget xz-utils" |
| 146 | + for pkg in $packages; do apt install -y --ignore-missing "$pkg"; done |
| 147 | + apt install python3 -y |
| 148 | +EOS |
| 149 | +#------------------------------------------------------------------------------------# |
| 150 | + |
| 151 | +#------------------------------------------------------------------------------------# |
| 152 | +# Build args |
| 153 | +#ARG TARGETPLATFORM=arm64 |
| 154 | +#ARG RUNNER_VERSION=2.313.0 |
| 155 | +#------------------------------------------------------------------------------------# |
| 156 | +##Download Runner Script |
| 157 | +# https://github.com/actions/runner/releases |
| 158 | +WORKDIR /runner |
| 159 | +RUN <<EOS |
| 160 | + #Setup GH Runner (arm64) |
| 161 | + #eget "https://github.com/actions/runner" --asset "linux" --asset "arm64" --asset "tar.gz" --to "./runner.tar.gz" --download-only |
| 162 | + wget --quiet --show-progress "https://pub.ajam.dev/utils/gh-runner-aarch64/runner.tar.gz" -O "./runner.tar.gz" |
| 163 | + if [ ! -f "./runner.tar.gz" ]; then |
| 164 | + exit 1 |
| 165 | + fi |
| 166 | + #Untar |
| 167 | + mkdir -p "/runner-init" |
| 168 | + tar xzf "./runner.tar.gz" -C "/runner-init" && rm "./runner.tar.gz" |
| 169 | + #Dos2unix |
| 170 | + find "/runner-init" -type f -exec dos2unix --quiet {} \; 2>/dev/null || true |
| 171 | + #Run Install |
| 172 | + chmod +x "/runner-init/bin/installdependencies.sh" && bash "/runner-init/bin/installdependencies.sh" |
| 173 | + #Remove cache |
| 174 | + rm -rf "/var/lib/apt/lists/"* 2>/dev/null |
| 175 | +EOS |
| 176 | +#Copy startup script |
| 177 | +COPY "./manager.sh" "/usr/local/bin/manager.sh" |
| 178 | +RUN chmod +x "/usr/local/bin/manager.sh" |
| 179 | +#------------------------------------------------------------------------------------# |
| 180 | + |
| 181 | +#------------------------------------------------------------------------------------# |
| 182 | +##Display & x11 :: https://github.com/puppeteer/puppeteer/issues/8148 |
| 183 | +RUN <<EOS |
| 184 | + #x11 & display server |
| 185 | + echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections |
| 186 | + apt update -y |
| 187 | + packages="dbus-x11 fonts-ipafont-gothic fonts-freefont-ttf gtk2-engines-pixbuf imagemagick libxss1 xauth xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalable x11-apps xorg xvfb" |
| 188 | + for pkg in $packages; do DEBIAN_FRONTEND="noninteractive" apt install -y --ignore-missing "$pkg"; done |
| 189 | + #Re |
| 190 | + echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections |
| 191 | + apt update -y |
| 192 | + packages="dbus-x11 fonts-ipafont-gothic fonts-freefont-ttf gtk2-engines-pixbuf imagemagick libxss1 xauth xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalable x11-apps xorg xvfb" |
| 193 | + for pkg in $packages; do DEBIAN_FRONTEND="noninteractive" apt install -y --ignore-missing "$pkg"; done |
| 194 | + #Configure |
| 195 | + touch "/root/.Xauthority" |
| 196 | + sudo -u "runner" touch "/home/runner/.Xauthority" |
| 197 | + #To start: (-ac --> disable access control restrictions) |
| 198 | + #Xvfb -ac ":0" & |
| 199 | + # export DISPLAY=":0" && google-chrome |
| 200 | +EOS |
| 201 | +#------------------------------------------------------------------------------------# |
| 202 | + |
| 203 | +#------------------------------------------------------------------------------------# |
| 204 | +##This is no longer needed because replaced docker with podman |
| 205 | +##Docker systemctl https://github.com/gdraheim/docker-systemctl-replacement |
| 206 | +RUN <<EOS |
| 207 | +#systemctl |
| 208 | +#System has not been booted with systemd as init system (PID 1). Can't operate. |
| 209 | +#Failed to connect to bus: Host is down |
| 210 | +#Replace with patched |
| 211 | + apt install python3 -y |
| 212 | +# curl -qfsSL "https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl3.py" -o "$(which systemctl)" |
| 213 | + mkdir -p "/var/run/dbus" ; dbus-daemon --config-file="/usr/share/dbus-1/system.conf" --print-address |
| 214 | +EOS |
| 215 | +#------------------------------------------------------------------------------------# |
| 216 | + |
| 217 | +#------------------------------------------------------------------------------------# |
| 218 | +##Enable SSH & SSH Service |
| 219 | +RUN <<EOS |
| 220 | + ##Install SSH |
| 221 | + set +e |
| 222 | + apt update -y && apt install openssh-server ssh -y |
| 223 | + #Config |
| 224 | + mkdir -p "/run/sshd" ; mkdir -p "/etc/ssh" ; touch "/var/log/auth.log" "/var/log/btmp" 2>/dev/null || true |
| 225 | + mkdir -p "/root/.ssh" ; chown "root:root" "/root/.ssh" |
| 226 | + #touch "/etc/ssh/authorized_keys" "/root/.ssh/authorized_keys" "/root/.ssh/config" "/root/.ssh/known_hosts" |
| 227 | + mkdir -p "/home/runner/.ssh" ; chown "runner:runner" "/home/runner/.ssh" |
| 228 | + touch "/etc/ssh/authorized_keys" "/home/runner/.ssh/authorized_keys" "/home/runner/.ssh/config" "/home/runner/.ssh/known_hosts" |
| 229 | + #Generate-Keys |
| 230 | + echo "yes" | ssh-keygen -N "" -t "ecdsa" -b 521 -f "/etc/ssh/ssh_host_ecdsa_key" |
| 231 | + #cp "/etc/ssh/ssh_host_ecdsa_key" "/home/runner/.ssh/id_ecdsa" ; cp "/etc/ssh/ssh_host_ecdsa_key" "/root/.ssh/id_ecdsa" |
| 232 | + #cp "/etc/ssh/ssh_host_ecdsa_key.pub" "/home/runner/.ssh/id_ecdsa.pub" ; cp "/etc/ssh/ssh_host_ecdsa_key.pub" "root/.ssh/id_ecdsa.pub" |
| 233 | + echo "yes" | ssh-keygen -N "" -t "ed25519" -f "/etc/ssh/ssh_host_ed25519_key" |
| 234 | + #cp "/etc/ssh/ssh_host_ed25519_key" "/home/runner/.ssh/id_ed25519" ; cp "/etc/ssh/ssh_host_ed25519_key" "/root/.ssh/id_ed25519" |
| 235 | + #cp "/etc/ssh/ssh_host_ed25519_key.pub" "/home/runner/.ssh/id_ed25519.pub" ; cp "/etc/ssh/ssh_host_ed25519_key.pub" "/root/.ssh/id_ed25519.pub" |
| 236 | + echo "yes" | ssh-keygen -N "" -t "rsa" -b 4096 -f "/etc/ssh/ssh_host_rsa_key" |
| 237 | + #cp "/etc/ssh/ssh_host_rsa_key" "/home/runner/.ssh/id_rsa" ; cp "/etc/ssh/ssh_host_rsa_key" "/root/.ssh/id_rsa" |
| 238 | + #cp "/etc/ssh/ssh_host_rsa_key.pub" "/home/runner/.ssh/id_rsa.pub" ; cp "/etc/ssh/ssh_host_rsa_key.pub" "/root/.ssh/id_rsa.pub" |
| 239 | + curl -qfsSL "https://raw.githubusercontent.com/pkgforge/devscripts/refs/heads/main/Linux/sshd_config_passwordless" -o "/etc/ssh/sshd_config" |
| 240 | + #Perms |
| 241 | + chown -R "root:root" "/root/.ssh" ; chown "root:root" "/etc/ssh/authorized_keys" ; chmod 644 "/etc/ssh/authorized_keys" |
| 242 | + chown -R "runner:runner" "/home/runner/.ssh" |
| 243 | + sudo -u "runner" chmod 750 -R "/home/runner" |
| 244 | + sudo -u "runner" chmod 700 -R "/home/runner/.ssh" |
| 245 | + sudo -u "runner" chmod 600 "/home/runner/.ssh/authorized_keys" "/home/runner/.ssh/config" |
| 246 | + sudo -u "runner" chmod 644 "/home/runner/.ssh/known_hosts" |
| 247 | + systemctl enable ssh --now 2>/dev/null || true |
| 248 | +EOS |
| 249 | +EXPOSE 22 |
| 250 | +#------------------------------------------------------------------------------------# |
| 251 | + |
| 252 | +#------------------------------------------------------------------------------------# |
| 253 | +##Setup TailScale (sudo tailscale up --authkey="$TSKEY" --ssh --hostname="$TS_NAME" --accept-dns="true" --accept-risk="all" --accept-routes="false" --shields-up="false" --advertise-exit-node --reset) |
| 254 | +RUN <<EOS |
| 255 | + #Install TailScale [pkg] |
| 256 | + set +e |
| 257 | + curl -qfsSL "https://tailscale.com/install.sh" -o "./tailscale.sh" |
| 258 | + dos2unix --quiet "./tailscale.sh" |
| 259 | + bash "./tailscale.sh" -s -- -h >/dev/null 2>&1 || true ; rm -rf "./tailscale.sh" |
| 260 | + systemctl -l --type "service" --all | grep -i "tailscale" || true |
| 261 | +EOS |
| 262 | +#------------------------------------------------------------------------------------# |
| 263 | + |
| 264 | +#------------------------------------------------------------------------------------# |
| 265 | +#Start |
| 266 | +RUN <<EOS |
| 267 | + locale-gen "en_US.UTF-8" |
| 268 | +EOS |
| 269 | +ENV LANG="en_US.UTF-8" |
| 270 | +ENV LANGUAGE="en_US:en" |
| 271 | +ENV LC_ALL="en_US.UTF-8" |
| 272 | +ENTRYPOINT ["/sbin/init"] |
| 273 | +#------------------------------------------------------------------------------------# |
0 commit comments