This commit is contained in:
ub
2026-02-06 06:35:16 +08:00
commit 5cf3fa0318
5 changed files with 134 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
workspace/
config/

21
docker-compose.yaml Normal file
View File

@@ -0,0 +1,21 @@
---
services:
code-server:
image: lscr.io/linuxserver/code-server:latest
container_name: code-server
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Shanghai
- PASSWORD=Kx123456
- SUDO_PASSWORD=Kx123456
volumes:
- ./config:/config
- ./init.d:/init.d
- ./workspace:/workspace
- /var/run/user/1000/docker.sock:/run/docker.sock
ports:
- 58333:8443
- 58322:22
restart: unless-stopped
privileged: true

2
init.d/authorized_keys Normal file
View File

@@ -0,0 +1,2 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIh0ZZCv7q3jX+pjA4t5CucxQgSDXTXgjAcShGmjL4O/ yangwolves@foxmail.com
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKpPemt8CCVs1Z886O/mdHnT5QUy5y+OHIr3N65u8Mob yangwolves@foxmail.com

50
init.d/init.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/sh -e
# This is the first program launched at container start.
# We don't know where our binaries are and we cannot guarantee
# that the default PATH can access them.
# So this script needs to be entirely self-contained until it has
# at least /command, /usr/bin and /bin in its PATH.
addpath () {
x="$1"
IFS=:
set -- $PATH
IFS=
while test "$#" -gt 0 ; do
if test "$1" = "$x" ; then
return
fi
shift
done
PATH="${x}:$PATH"
}
if test -z "$PATH" ; then
PATH=/bin
fi
addpath /bin
addpath /usr/bin
addpath /command
export PATH
/usr/sbin/sshd -D &
# Wait for the Docker readiness notification, if any
if read _ 2>/dev/null <&3 ; then
exec 3<&-
fi
# Now we're good: s6-overlay-suexec is accessible via PATH, as are
# all our binaries.
# Run preinit as root, then run stage0 as the container's user (can be
# root, can be a normal user).
exec s6-overlay-suexec \
' /package/admin/s6-overlay-3.2.1.0/libexec/preinit' \
'' \
/package/admin/s6-overlay-3.2.1.0/libexec/stage0 \
"$@"

59
init.d/run.sh Executable file
View File

@@ -0,0 +1,59 @@
#!/bin/bash
set -euo pipefail
apt update
apt install -y openssh-server vim ca-certificates curl gnupg
# Install Docker CLI only (docker-ce-cli) from official Docker repo.
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
ARCH="$(dpkg --print-architecture)"
. /etc/os-release
echo "deb [arch=${ARCH} signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu ${VERSION_CODENAME} stable" \
>/etc/apt/sources.list.d/docker.list
apt update
apt install -y docker-ce-cli
mkdir -p /run/sshd
# Configure sshd: allow root login, disable password auth.
mkdir -p /etc/ssh/sshd_config.d
cat >/etc/ssh/sshd_config.d/99-codex.conf <<'EOF'
PermitRootLogin yes
PasswordAuthentication no
ChallengeResponseAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
EOF
# Copy authorized_keys for root from init directory if present.
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
if [[ -f "${SCRIPT_DIR}/authorized_keys" ]]; then
mkdir -p /root/.ssh
install -m 600 "${SCRIPT_DIR}/authorized_keys" /root/.ssh/authorized_keys
fi
cp init.sh /init
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
# Configure system-wide proxy for this container.
PROXY_URL="http://10.8.0.1:7890"
cat >/etc/apt/apt.conf.d/99proxy <<EOF
Acquire::http::Proxy "${PROXY_URL}";
Acquire::https::Proxy "${PROXY_URL}";
EOF
cat >/etc/profile.d/proxy.sh <<EOF
export http_proxy="${PROXY_URL}"
export https_proxy="${PROXY_URL}"
export no_proxy="localhost,127.0.0.1"
EOF
# Configure git proxy if git is available.
if command -v git >/dev/null 2>&1; then
git config --system http.proxy "${PROXY_URL}"
git config --system https.proxy "${PROXY_URL}"
fi