|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | +#------------------------------------------------------------------------------------# |
| 3 | +# Usage: https://github.com/pkgforge/devscripts/blob/main/Github/Runners/README.md |
| 4 | +# |
| 5 | +FROM ubuntu:latest |
| 6 | +#FROM ubuntu:jammy |
| 7 | +#------------------------------------------------------------------------------------# |
| 8 | +##Base Deps |
| 9 | +ENV DEBIAN_FRONTEND="noninteractive" |
| 10 | +RUN <<EOS |
| 11 | + #Base |
| 12 | + apt-get update -y |
| 13 | + 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 tree unzip util-linux xz-utils wget zip" |
| 14 | + #Install |
| 15 | + apt-get update -y -qq |
| 16 | + for pkg in $packages; do DEBIAN_FRONTEND="noninteractive" apt install -y --ignore-missing "$pkg"; done |
| 17 | + #Install_Re |
| 18 | + for pkg in $packages; do DEBIAN_FRONTEND="noninteractive" apt install -y --ignore-missing "$pkg"; done |
| 19 | + #unminimize : https://wiki.ubuntu.com/Minimal |
| 20 | + yes | unminimize |
| 21 | + #Python |
| 22 | + apt-get install python3 -y |
| 23 | + #Test |
| 24 | + python --version 2>/dev/null ; python3 --version 2>/dev/null |
| 25 | + #Install pip: |
| 26 | + #python3 -m ensurepip --upgrade ; pip3 --version |
| 27 | + #curl -qfsSL "https://bootstrap.pypa.io/get-pip.py" -o "$SYSTMP/get-pip.py" && python3 "$SYSTMP/get-pip.py" |
| 28 | + packages="libxslt-dev lm-sensors pciutils procps python3-distro python-dev-is-python3 python3-lxml python3-netifaces python3-pip python3-venv sysfsutils virt-what" |
| 29 | + for pkg in $packages; do DEBIAN_FRONTEND="noninteractive" apt install -y --ignore-missing "$pkg"; done |
| 30 | + pip install --break-system-packages --upgrade pip || pip install --upgrade pip |
| 31 | + #Misc |
| 32 | + pip install ansi2txt --break-system-packages --force-reinstall --upgrade |
| 33 | + #pipx |
| 34 | + pip install pipx --upgrade 2>/dev/null |
| 35 | + pip install pipx --upgrade --break-system-packages 2>/dev/null |
| 36 | +EOS |
| 37 | +#------------------------------------------------------------------------------------# |
| 38 | +##Systemd installation |
| 39 | +RUN <<EOS |
| 40 | + #SystemD |
| 41 | + apt-get update -y |
| 42 | + packages="dbus iptables iproute2 libsystemd0 kmod systemd systemd-sysv udev" |
| 43 | + for pkg in $packages; do apt install -y --ignore-missing "$pkg"; done |
| 44 | + ##Prevents journald from reading kernel messages from /dev/kmsg |
| 45 | + # echo "ReadKMsg=no" >> "/etc/systemd/journald.conf" |
| 46 | + #Disable systemd services/units that are unnecessary within a container. |
| 47 | + #systemctl mask "systemd-udevd.service" |
| 48 | + #systemctl mask "systemd-udevd-kernel.socket" |
| 49 | + #systemctl mask "systemd-udevd-control.socket" |
| 50 | + #systemctl mask "systemd-modules-load.service" |
| 51 | + #systemctl mask "sys-kernel-debug.mount" |
| 52 | + #systemctl mask "sys-kernel-tracing.mount" |
| 53 | + #Housekeeping |
| 54 | + apt-get clean -y |
| 55 | + rm -rf "/lib/systemd/system/getty.target" 2>/dev/null |
| 56 | + rm -rf "/lib/systemd/system/systemd"*udev* 2>/dev/null |
| 57 | + rm -rf "/usr/share/doc/"* 2>/dev/null |
| 58 | + rm -rf "/usr/share/local/"* 2>/dev/null |
| 59 | + rm -rf "/usr/share/man/"* 2>/dev/null |
| 60 | + rm -rf "/var/cache/debconf/"* 2>/dev/null |
| 61 | + rm -rf "/var/lib/apt/lists/"* 2>/dev/null |
| 62 | + rm -rf "/var/log/"* 2>/dev/null |
| 63 | + rm -rf "/var/tmp/"* 2>/dev/null |
| 64 | + rm -rf "/tmp/"* 2>/dev/null |
| 65 | +EOS |
| 66 | +# Make use of stopsignal (instead of sigterm) to stop systemd containers. |
| 67 | +STOPSIGNAL SIGRTMIN+3 |
| 68 | +#------------------------------------------------------------------------------------# |
| 69 | + |
| 70 | +#------------------------------------------------------------------------------------# |
| 71 | +##Create User + Setup Perms |
| 72 | +RUN <<EOS |
| 73 | + #Add runner |
| 74 | + useradd --create-home "runner" |
| 75 | + #Set password |
| 76 | + echo "runner:runneradmin" | chpasswd |
| 77 | + #Add runner to sudo |
| 78 | + usermod -aG "sudo" "runner" |
| 79 | + usermod -aG "sudo" "root" |
| 80 | + #Passwordless sudo for runner |
| 81 | + echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" >> "/etc/sudoers" |
| 82 | + #Remove preconfigured admin user |
| 83 | + userdel -r "admin" 2>/dev/null || true |
| 84 | +EOS |
| 85 | +##Change Default shell for runner to bash |
| 86 | +RUN <<EOS |
| 87 | + #Check current shell |
| 88 | + grep runner "/etc/passwd" |
| 89 | + #Change to bash |
| 90 | + usermod --shell "/bin/bash" "runner" 2>/dev/null |
| 91 | + curl -qfsSL "https://raw.githubusercontent.com/pkgforge/devscripts/refs/heads/main/Linux/.bashrc" -o "/etc/bash.bashrc" |
| 92 | + dos2unix --quiet "/etc/bash.bashrc" 2>/dev/null |
| 93 | + ln --symbolic --force "/etc/bash.bashrc" "/home/runner/.bashrc" 2>/dev/null |
| 94 | + ln --symbolic --force "/etc/bash.bashrc" "/root/.bashrc" 2>/dev/null |
| 95 | + ln --symbolic --force "/etc/bash.bashrc" "/etc/bash/bashrc" 2>/dev/null |
| 96 | + #Recheck |
| 97 | + grep runner "/etc/passwd" |
| 98 | +EOS |
| 99 | +#------------------------------------------------------------------------------------# |
| 100 | + |
| 101 | +#------------------------------------------------------------------------------------# |
| 102 | +##Install Docker |
| 103 | +RUN <<EOS |
| 104 | + #Install Docker |
| 105 | + rm -rf "/var/lib/apt/lists/"* |
| 106 | + cd "$(mktemp -d)" >/dev/null 2>&1 |
| 107 | + curl -qfsSL "https://get.docker.com" -o "./get-docker.sh" && sh "./get-docker.sh" |
| 108 | + cd - >/dev/null 2>&1 |
| 109 | + #Add runner to docker |
| 110 | + usermod -aG "docker" "runner" |
| 111 | + #Add Docker Completions |
| 112 | + curl -qfsSL "https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker" > "/etc/bash_completion.d/docker.sh" |
| 113 | + #Confiure Docker Opts |
| 114 | + #Remove Hardlimit |
| 115 | + sed -i 's/ulimit -Hn/# ulimit -Hn/g' "/etc/init.d/docker" |
| 116 | + #Install Additional Deps |
| 117 | + packages="btrfs-progs fuse-overlayfs fuse3 kmod libfuse3-dev zfs-dkms" |
| 118 | + for pkg in $packages; do apt install -y --ignore-missing "$pkg"; done |
| 119 | +EOS |
| 120 | +#------------------------------------------------------------------------------------# |
| 121 | + |
| 122 | +#------------------------------------------------------------------------------------# |
| 123 | +##Addons |
| 124 | +RUN <<EOS |
| 125 | + #Addons |
| 126 | + ##https://github.com/pkgforge/devscripts/blob/main/Linux/install_bins_curl.sh |
| 127 | + curl -qfsSL "https://github.com/pkgforge/devscripts/blob/main/Linux/install_bins_curl.sh" -o "./tools.sh" |
| 128 | + dos2unix --quiet "./tools.sh" && chmod +x "./tools.sh" |
| 129 | + bash "./tools.sh" 2>/dev/null || true ; rm -rf "./tools.sh" |
| 130 | +EOS |
| 131 | +#------------------------------------------------------------------------------------# |
| 132 | + |
| 133 | +#------------------------------------------------------------------------------------# |
| 134 | +##Build Tools |
| 135 | +RUN <<EOS |
| 136 | + apt update -y |
| 137 | + 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" |
| 138 | + for pkg in $packages; do apt install -y --ignore-missing "$pkg"; done |
| 139 | + apt install python3 -y |
| 140 | +EOS |
| 141 | +#------------------------------------------------------------------------------------# |
| 142 | + |
| 143 | +#------------------------------------------------------------------------------------# |
| 144 | +##Display & x11 :: https://github.com/puppeteer/puppeteer/issues/8148 |
| 145 | +RUN <<EOS |
| 146 | + #x11 & display server |
| 147 | + echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections |
| 148 | + apt update -y |
| 149 | + 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" |
| 150 | + for pkg in $packages; do DEBIAN_FRONTEND="noninteractive" apt install -y --ignore-missing "$pkg"; done |
| 151 | + #Re |
| 152 | + echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections |
| 153 | + apt update -y |
| 154 | + 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" |
| 155 | + for pkg in $packages; do DEBIAN_FRONTEND="noninteractive" apt install -y --ignore-missing "$pkg"; done |
| 156 | + #Configure |
| 157 | + touch "/root/.Xauthority" |
| 158 | + sudo -u "runner" touch "/home/runner/.Xauthority" |
| 159 | + #To start: (-ac --> disable access control restrictions) |
| 160 | + #Xvfb -ac ":0" & |
| 161 | + # export DISPLAY=":0" && google-chrome |
| 162 | +EOS |
| 163 | +#------------------------------------------------------------------------------------# |
| 164 | + |
| 165 | +#------------------------------------------------------------------------------------# |
| 166 | +##This is no longer needed because replaced docker with podman |
| 167 | +##Docker systemctl https://github.com/gdraheim/docker-systemctl-replacement |
| 168 | +RUN <<EOS |
| 169 | +#systemctl |
| 170 | +#System has not been booted with systemd as init system (PID 1). Can't operate. |
| 171 | +#Failed to connect to bus: Host is down |
| 172 | +#Replace with patched |
| 173 | + apt-get install python3 -y |
| 174 | +# curl -qfsSL "https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl3.py" -o "$(which systemctl)" |
| 175 | + mkdir -p "/var/run/dbus" ; dbus-daemon --config-file="/usr/share/dbus-1/system.conf" --print-address |
| 176 | +EOS |
| 177 | +#------------------------------------------------------------------------------------# |
| 178 | + |
| 179 | +#------------------------------------------------------------------------------------# |
| 180 | +##Enable SSH & SSH Service |
| 181 | +RUN <<EOS |
| 182 | + ##Install SSH |
| 183 | + set +e |
| 184 | + apt-get update -y && apt-get install openssh-server ssh -y |
| 185 | + #Config |
| 186 | + mkdir -p "/run/sshd" ; mkdir -p "/etc/ssh" ; touch "/var/log/auth.log" "/var/log/btmp" 2>/dev/null || true |
| 187 | + mkdir -p "/root/.ssh" ; chown "root:root" "/root/.ssh" |
| 188 | + #touch "/etc/ssh/authorized_keys" "/root/.ssh/authorized_keys" "/root/.ssh/config" "/root/.ssh/known_hosts" |
| 189 | + mkdir -p "/home/runner/.ssh" ; chown "runner:runner" "/home/runner/.ssh" |
| 190 | + touch "/etc/ssh/authorized_keys" "/home/runner/.ssh/authorized_keys" "/home/runner/.ssh/config" "/home/runner/.ssh/known_hosts" |
| 191 | + #Generate-Keys |
| 192 | + echo "yes" | ssh-keygen -N "" -t "ecdsa" -b 521 -f "/etc/ssh/ssh_host_ecdsa_key" |
| 193 | + #cp "/etc/ssh/ssh_host_ecdsa_key" "/home/runner/.ssh/id_ecdsa" ; cp "/etc/ssh/ssh_host_ecdsa_key" "/root/.ssh/id_ecdsa" |
| 194 | + #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" |
| 195 | + echo "yes" | ssh-keygen -N "" -t "ed25519" -f "/etc/ssh/ssh_host_ed25519_key" |
| 196 | + #cp "/etc/ssh/ssh_host_ed25519_key" "/home/runner/.ssh/id_ed25519" ; cp "/etc/ssh/ssh_host_ed25519_key" "/root/.ssh/id_ed25519" |
| 197 | + #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" |
| 198 | + echo "yes" | ssh-keygen -N "" -t "rsa" -b 4096 -f "/etc/ssh/ssh_host_rsa_key" |
| 199 | + #cp "/etc/ssh/ssh_host_rsa_key" "/home/runner/.ssh/id_rsa" ; cp "/etc/ssh/ssh_host_rsa_key" "/root/.ssh/id_rsa" |
| 200 | + #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" |
| 201 | + curl -qfsSL "https://raw.githubusercontent.com/pkgforge/devscripts/refs/heads/main/Linux/sshd_config_passwordless" -o "/etc/ssh/sshd_config" |
| 202 | + #Perms |
| 203 | + chown -R "root:root" "/root/.ssh" ; chown "root:root" "/etc/ssh/authorized_keys" ; chmod 644 "/etc/ssh/authorized_keys" |
| 204 | + chown -R "runner:runner" "/home/runner/.ssh" |
| 205 | + sudo -u "runner" chmod 750 -R "/home/runner" |
| 206 | + sudo -u "runner" chmod 700 -R "/home/runner/.ssh" |
| 207 | + sudo -u "runner" chmod 600 "/home/runner/.ssh/authorized_keys" "/home/runner/.ssh/config" |
| 208 | + sudo -u "runner" chmod 644 "/home/runner/.ssh/known_hosts" |
| 209 | + systemctl enable ssh --now 2>/dev/null || true |
| 210 | +EOS |
| 211 | +EXPOSE 22 |
| 212 | +#------------------------------------------------------------------------------------# |
| 213 | + |
| 214 | +#------------------------------------------------------------------------------------# |
| 215 | +##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) |
| 216 | +RUN <<EOS |
| 217 | + #Install TailScale [pkg] |
| 218 | + set +e |
| 219 | + curl -qfsSL "https://tailscale.com/install.sh" -o "./tailscale.sh" |
| 220 | + dos2unix --quiet "./tailscale.sh" |
| 221 | + bash "./tailscale.sh" -s -- -h >/dev/null 2>&1 || true ; rm -rf "./tailscale.sh" |
| 222 | + systemctl -l --type "service" --all | grep -i "tailscale" || true |
| 223 | +EOS |
| 224 | +#------------------------------------------------------------------------------------# |
| 225 | + |
| 226 | +#------------------------------------------------------------------------------------# |
| 227 | +##Install Podman |
| 228 | +RUN <<EOS |
| 229 | + #Install Podman |
| 230 | + VERSION="$(grep -oP 'VERSION_ID="\K[^"]+' "/etc/os-release")" |
| 231 | + echo "deb http://download.opensuse.org/repositories/home:/alvistack/xUbuntu_${VERSION}/ /" | tee "/etc/apt/sources.list.d/home:alvistack.list" |
| 232 | + curl -fsSL "https://download.opensuse.org/repositories/home:alvistack/xUbuntu_${VERSION}/Release.key" | gpg --dearmor | tee "/etc/apt/trusted.gpg.d/home_alvistack.gpg" >/dev/null |
| 233 | + apt update -y -qq ; apt install podman -y 2>/dev/null || true |
| 234 | + apt-get install containernetworking-plugins podman-netavark -y 2>/dev/null || true |
| 235 | + systemctl enable podman --now 2>/dev/null || true |
| 236 | +EOS |
| 237 | +#------------------------------------------------------------------------------------# |
| 238 | + |
| 239 | +#------------------------------------------------------------------------------------# |
| 240 | +#Start |
| 241 | +RUN <<EOS |
| 242 | + locale-gen "en_US.UTF-8" |
| 243 | +EOS |
| 244 | +ENV LANG="en_US.UTF-8" |
| 245 | +ENV LANGUAGE="en_US:en" |
| 246 | +ENV LC_ALL="en_US.UTF-8" |
| 247 | +ENTRYPOINT ["/sbin/init"] |
| 248 | +#------------------------------------------------------------------------------------# |
0 commit comments