This commit is contained in:
Operator
2026-10-17 10:40:52 +00:00
parent 0257ee37dd
commit 61a62e658a
10 changed files with 637 additions and 556 deletions

View File

@@ -1,31 +1,55 @@
FROM alpine:3.22
RUN apk add --no-cache \
openssh-server \
docker-cli \
docker-cli-compose \
&& addgroup -g 1001 docker-host \
&& adduser -D -s /bin/sh operator \
&& adduser operator docker-host \
&& passwd -d operator \
&& mkdir -p /home/operator/.ssh \
&& ssh-keygen -A
RUN printf '%s\n' \
'PasswordAuthentication no' \
'KbdInteractiveAuthentication no' \
'PubkeyAuthentication yes' \
'PermitRootLogin no' \
>> /etc/ssh/sshd_config
COPY entrypoint.sh /entrypoint.sh
COPY gpuctl /usr/local/bin/gpuctl
RUN sed -i 's/\r$//' /usr/local/bin/gpuctl \
&& chmod +x /entrypoint.sh /usr/local/bin/gpuctl
RUN chmod +x /entrypoint.sh /usr/local/bin/gpuctl
EXPOSE 22
FROM alpine:3.22
RUN apk add --no-cache \
openssh-server \
docker-cli \
docker-cli-compose \
git \
curl \
wget \
bash \
jq \
vim \
less \
htop \
nano \
iproute2 \
bind-tools \
tcpdump \
procps \
util-linux \
tree \
file \
ca-certificates \
tzdata \
&& addgroup -g 1001 docker-host \
&& adduser -D -s /bin/bash operator \
&& adduser operator docker-host \
&& passwd -d operator \
&& mkdir -p /home/operator/.ssh \
&& ssh-keygen -A
RUN printf '%s\n' \
'PasswordAuthentication no' \
'KbdInteractiveAuthentication no' \
'PubkeyAuthentication yes' \
'PermitRootLogin no' \
>> /etc/ssh/sshd_config
COPY entrypoint.sh /entrypoint.sh
COPY gpuctl /usr/local/bin/gpuctl
COPY scripts/ /usr/local/lib/scripts/
RUN sed -i 's/\r$//' \
/entrypoint.sh \
/usr/local/bin/gpuctl \
/usr/local/lib/scripts/*.sh \
&& chmod +x \
/entrypoint.sh \
/usr/local/bin/gpuctl \
/usr/local/lib/scripts/*.sh
EXPOSE 22
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -1,10 +1,87 @@
#!/bin/sh
set -e
cp /mounted-authorized-keys /home/operator/.ssh/authorized_keys
chown -R operator:operator /home/operator/.ssh
chmod 700 /home/operator/.ssh
chmod 600 /home/operator/.ssh/authorized_keys
exec /usr/sbin/sshd -D -e
#!/bin/sh
set -eu
# ------------------------------------------------------------
# Configuration
# ------------------------------------------------------------
HOST_PROJECT_PATH="${HOST_PROJECT_PATH:-}"
SSH_ROLE="${SSH_ROLE:-}"
SSH_PORT="${SSH_PORT:-22}"
if [ -z "$HOST_PROJECT_PATH" ]; then
echo "ERROR: HOST_PROJECT_PATH is not set." >&2
exit 1
fi
if [ -z "$SSH_ROLE" ]; then
echo "ERROR: SSH_ROLE is not set." >&2
exit 1
fi
case "$SSH_ROLE" in
main)
EXPECTED_PORT="22"
;;
companion)
EXPECTED_PORT="2222"
;;
*)
echo "ERROR: unknown SSH_ROLE: $SSH_ROLE" >&2
echo "Expected: main or companion" >&2
exit 1
;;
esac
# ------------------------------------------------------------
# SSH authorized keys
# ------------------------------------------------------------
cp /project/ssh/authorized_keys /home/operator/.ssh/authorized_keys
chown -R operator:operator /home/operator/.ssh
chmod 700 /home/operator/.ssh
chmod 600 /home/operator/.ssh/authorized_keys
# ------------------------------------------------------------
# Interactive shell environment
# ------------------------------------------------------------
cat > /etc/profile.d/gpu-node.sh <<EOF
export HOST_PROJECT_PATH='$HOST_PROJECT_PATH'
export SSH_ROLE='$SSH_ROLE'
export SSH_PORT='$SSH_PORT'
EOF
chmod 644 /etc/profile.d/gpu-node.sh
# ------------------------------------------------------------
# Export for processes started by sshd
# ------------------------------------------------------------
export HOST_PROJECT_PATH
export SSH_ROLE
export SSH_PORT
echo "SSH role: $SSH_ROLE"
echo "Host project path: $HOST_PROJECT_PATH"
echo "SSH port: $SSH_PORT"
# ------------------------------------------------------------
# Start SSH
# ------------------------------------------------------------
exec /usr/sbin/sshd -D -e -p "$SSH_PORT"

View File

@@ -1,247 +1,139 @@
#!/bin/sh
set -eu
PROJECT_DIR="/project"
get_host_project_dir() {
docker inspect gpu-node-ssh \
--format '{{range .Mounts}}{{if eq .Destination "/project"}}{{.Source}}{{end}}{{end}}'
}
show_status() {
docker ps \
--filter "name=gpu-node-" \
--format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
}
start_llama() {
MODEL="${1:-model.gguf}"
shift || true
cd "$PROJECT_DIR"
HOST_PROJECT_DIR="$(get_host_project_dir)"
if [ -z "$HOST_PROJECT_DIR" ]; then
echo "ERROR: cannot determine host project directory"
exit 1
fi
EXTRA_ARGS="$*"
echo "Starting llama..."
echo "Model: $MODEL"
echo "Models: $HOST_PROJECT_DIR/gpu/llama_models"
if [ -n "$EXTRA_ARGS" ]; then
echo "Extra args: $EXTRA_ARGS"
fi
LLAMA_MODELS_HOST="$HOST_PROJECT_DIR/gpu/llama_models" \
LLAMA_MODEL="$MODEL" \
LLAMA_EXTRA_ARGS="$EXTRA_ARGS" \
docker compose \
--profile llama \
up -d \
--force-recreate \
llama
echo
docker ps \
--filter "name=gpu-node-llama" \
--format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
}
start_comfy() {
cd "$PROJECT_DIR"
HOST_PROJECT_DIR="$(get_host_project_dir)"
if [ -z "$HOST_PROJECT_DIR" ]; then
echo "ERROR: cannot determine host project directory"
exit 1
fi
EXTRA_ARGS="$*"
echo "Starting ComfyUI..."
echo "Directory: $HOST_PROJECT_DIR/gpu/comfy"
if [ -n "$EXTRA_ARGS" ]; then
echo "Extra args: $EXTRA_ARGS"
fi
COMFY_BASE_HOST="$HOST_PROJECT_DIR/gpu/comfy" \
COMFY_RUN_HOST="$HOST_PROJECT_DIR/gpu/comfy/run" \
COMFY_EXTRA_ARGS="$EXTRA_ARGS" \
docker compose \
--profile comfy \
up -d \
--force-recreate \
comfyui
echo
docker ps \
--filter "name=gpu-node-comfyui" \
--format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
}
stop_service() {
SERVICE="$1"
case "$SERVICE" in
llama)
docker stop gpu-node-llama 2>/dev/null || true
;;
comfy)
docker stop gpu-node-comfyui 2>/dev/null || true
;;
tailscale)
docker stop gpu-node-tailscale 2>/dev/null || true
;;
ssh)
docker stop gpu-node-ssh 2>/dev/null || true
;;
*)
echo "Unknown service: $SERVICE"
exit 1
;;
esac
}
restart_service() {
SERVICE="$1"
case "$SERVICE" in
llama)
docker restart gpu-node-llama
;;
comfy)
docker restart gpu-node-comfyui
;;
tailscale)
docker restart gpu-node-tailscale
;;
ssh)
docker restart gpu-node-ssh
;;
*)
echo "Unknown service: $SERVICE"
exit 1
;;
esac
}
logs_service() {
SERVICE="$1"
case "$SERVICE" in
llama)
docker logs -f gpu-node-llama
;;
comfy)
docker logs -f gpu-node-comfyui
;;
tailscale)
docker logs -f gpu-node-tailscale
;;
ssh)
docker logs -f gpu-node-ssh
;;
*)
echo "Unknown service: $SERVICE"
exit 1
;;
esac
}
case "${1:-}" in
status)
show_status
;;
start)
case "${2:-}" in
llama)
shift 2
start_llama "$@"
;;
comfy)
shift 2
start_comfy "$@"
;;
*)
echo "Usage:"
echo " gpuctl start llama [model.gguf] [extra args...]"
echo " gpuctl start comfy [extra args...]"
exit 1
;;
esac
;;
stop)
if [ -z "${2:-}" ]; then
echo "Usage: gpuctl stop <service>"
exit 1
fi
stop_service "$2"
;;
restart)
if [ -z "${2:-}" ]; then
echo "Usage: gpuctl restart <service>"
exit 1
fi
restart_service "$2"
;;
logs)
if [ -z "${2:-}" ]; then
echo "Usage: gpuctl logs <service>"
exit 1
fi
logs_service "$2"
;;
*)
echo "GPU node controller"
echo
echo "Usage:"
echo " gpuctl status"
echo " gpuctl start llama [model.gguf] [extra args...]"
echo " gpuctl start comfy [extra args...]"
echo " gpuctl stop <service>"
echo " gpuctl restart <service>"
echo " gpuctl logs <service>"
exit 1
;;
#!/bin/sh
set -eu
GPuctl_LIB="/usr/local/lib/scripts"
. "$GPuctl_LIB/common.sh"
. "$GPuctl_LIB/status.sh"
. "$GPuctl_LIB/gpu.sh"
. "$GPuctl_LIB/llama.sh"
. "$GPuctl_LIB/comfy.sh"
show_usage() {
cat <<'EOF'
Usage:
gpuctl status
gpuctl gpu
gpuctl update
gpuctl sleep
gpuctl wake
gpuctl start llama [model.gguf] [extra args...]
gpuctl start comfy [extra args...]
gpuctl comfy models list [type]
gpuctl comfy models queue
gpuctl comfy models add <URL> <type>
gpuctl comfy models rm <filename> [type]
gpuctl stop <service>
gpuctl restart <service>
gpuctl logs <service>
EOF
}
case "${1:-}" in
status)
show_status
;;
gpu)
show_gpu
;;
update)
if [ "$#" -ne 1 ]; then
echo "Usage: gpuctl update" >&2
exit 1
fi
update_ssh
;;
sleep)
if [ "$#" -ne 1 ]; then
echo "Usage: gpuctl sleep" >&2
exit 1
fi
sleep_mode
;;
wake)
if [ "$#" -ne 1 ]; then
echo "Usage: gpuctl wake" >&2
exit 1
fi
wake_mode
;;
start)
case "${2:-}" in
llama)
shift 2
start_llama "$@"
;;
comfy)
shift 2
start_comfy "$@"
;;
*)
show_usage
exit 1
;;
esac
;;
comfy)
shift
comfy_command "$@"
;;
llama)
shift
llama_command "$@"
;;
stop)
if [ "$#" -ne 2 ]; then
echo "Usage: gpuctl stop <service>" >&2
exit 1
fi
stop_service "$2"
;;
restart)
if [ "$#" -ne 2 ]; then
echo "Usage: gpuctl restart <service>" >&2
exit 1
fi
restart_service "$2"
;;
logs)
if [ "$#" -ne 2 ]; then
echo "Usage: gpuctl logs <service>" >&2
exit 1
fi
logs_service "$2"
;;
*)
show_usage
exit 1
;;
esac