Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions docker_gui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,31 @@
docker build -f docker_gui/gui_linux.Dockerfile -t labnow/gui:selkies docker_gui
```

基础镜像假设满足以下条件:
构建使用两个基础镜像:

- 基于 Ubuntu。
- 已包含 Node.js 最新 LTS。
- 已包含 Python >= 3.13。
- `BASE_IMG_BUILD_WEB=node`:基于 Ubuntu,包含 Node.js 和 npm。
- `BASE_IMG_BUILD=rust`:基于 Ubuntu,包含可用的 Rust/Cargo 工具链。
- `BASE_IMG=base`:运行镜像,包含 `script-utils.sh` 等项目基础工具。

构建过程会安装 Selkies 运行期系统依赖,默认克隆 Selkies `main` 分支最新源码,并安装到 `/opt/selkies`。
默认使用源码构建方式,只保留运行期需要的 Python venv、web dashboard 产物和少量 addon 产物,构建依赖会在同一层内清理。
默认克隆 Selkies `main`:Node 阶段按上游 `scripts/ci/build-web.sh` 构建前端,Rust 阶段先构建上游锁定的静态codec依赖,再构建原生服务端并将前端嵌入二进制;随后构建输入 interposer 和 fake-udev addon。构建依赖留在中间阶段,不进入运行镜像。

如需固定某个 branch、tag 或 commit,可以使用:
如需固定源码 branch、tag 或 commit,可以使用:

```bash
docker build -f docker_gui/gui_linux.Dockerfile \
--build-arg ARG_SELKIES_REF=main \
-t labnow/gui:selkies docker_gui
```

如需使用其他构建基础镜像,可分别覆盖前端和后端镜像:

```bash
docker build -f docker_gui/gui_linux.Dockerfile \
--build-arg BASE_IMG_BUILD_WEB=node \
--build-arg BASE_IMG_BUILD=rust \
-t labnow/gui:selkies docker_gui
```

如需回退到官方 portable release 包,可以使用:

```bash
Expand Down Expand Up @@ -65,7 +73,7 @@ docker run --rm -p 8080:8080 \
| `SELKIES_ENABLE_BASIC_AUTH` | `false` | 是否启用 Selkies 内置 Basic Auth。 |
| `SELKIES_BASIC_AUTH_USER` | 空 | Basic Auth 用户名。 |
| `SELKIES_BASIC_AUTH_PASSWORD` | 空 | Basic Auth 密码。 |
| `SELKIES_ENCODER` | `x264enc` | 视频编码器。 |
| `SELKIES_ENCODER` | `h264enc` | 视频编码器。 |
| `SELKIES_ENABLE_RESIZE` | `false` | 是否允许 Selkies 按浏览器窗口调整分辨率。 |
| `SELKIES_STUN_HOST` | `stun.l.google.com` | STUN 服务器地址。 |
| `SELKIES_STUN_PORT` | `19302` | STUN 服务器端口。 |
Expand All @@ -80,7 +88,7 @@ docker run --rm -p 8080:8080 \
也可以直接传递 `selkies-gstreamer-run` 参数:

```bash
docker run --rm -p 8080:8080 labnow/gui:selkies --encoder=vp8enc --enable_resize=true
docker run --rm -p 8080:8080 labnow/gui:selkies --encoder=vp8enc --enable-resize=true
```

## 关于 Connection failed
Expand Down
78 changes: 49 additions & 29 deletions docker_gui/gui_linux.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,71 +1,91 @@
# Distributed under the terms of the Modified BSD License.

ARG BASE_NAMESPACE
ARG BASE_IMG_BUILD="node"
ARG BASE_IMG_BUILD="rust"
ARG BASE_IMG_BUILD_WEB="node"
ARG BASE_IMG="base"
ARG ARG_SELKIES_INSTALL_METHOD=source
ARG ARG_SELKIES_REF=main


# Stage 1: build selkies from source
FROM ${BASE_NAMESPACE:+$BASE_NAMESPACE/}${BASE_IMG_BUILD} AS builder
# Stage 1: build the web client with Node.js
FROM ${BASE_NAMESPACE:+$BASE_NAMESPACE/}${BASE_IMG_BUILD_WEB} AS web-builder

ARG ARG_SELKIES_INSTALL_METHOD=source
ARG ARG_SELKIES_REF=main

SHELL ["/bin/bash", "--login", "-o", "pipefail", "-c"]

COPY work /opt/utils/

RUN set -eux && chmod +x /opt/utils/*.sh \
&& source /opt/utils/script-utils.sh \
&& source /opt/utils/script-setup-gui.sh \
&& install_apt /opt/utils/install_list_selkies.apt \
&& if [ "${ARG_SELKIES_INSTALL_METHOD}" = "release" ] ; then \
setup_selkies_from_release ; \
&& if [ "${ARG_SELKIES_INSTALL_METHOD}" = "source" ]; then \
setup_selkies_web_build_dependencies \
&& checkout_selkies_source "${ARG_SELKIES_REF}" /tmp/selkies-src \
&& setup_selkies_web_from_source /tmp/selkies-src ; \
else \
export VER_SELKIES_REF="${ARG_SELKIES_REF}" ; \
setup_selkies_build_dependencies && setup_selkies_from_source ; \
mkdir -p /tmp/selkies-src ; \
fi


# Stage 2: build the Selkies server with Rust
FROM ${BASE_NAMESPACE:+$BASE_NAMESPACE/}${BASE_IMG_BUILD} AS builder

ARG ARG_SELKIES_INSTALL_METHOD=source

SHELL ["/bin/bash", "--login", "-o", "pipefail", "-c"]

COPY work /opt/utils/
COPY --from=web-builder /tmp/selkies-src /tmp/selkies-src

RUN set -eux && chmod +x /opt/utils/*.sh \
&& source /opt/utils/script-utils.sh \
&& source /opt/utils/script-setup-gui.sh \
&& mkdir -p /opt/selkies \
&& if [ "${ARG_SELKIES_INSTALL_METHOD}" = "release" ]; then \
apt-get -qq update -yq --fix-missing \
&& apt-get -qq install -yq --no-install-recommends curl jq \
&& setup_selkies_from_release ; \
else \
setup_selkies_build_dependencies \
&& setup_selkies_from_source /tmp/selkies-src ; \
fi \
&& mv /opt/utils/docker-entrypoint.sh /opt/selkies/docker-entrypoint.sh \
&& mv /opt/utils/install_list_selkies.apt /opt/selkies/ \
&& chmod +x /opt/selkies/docker-entrypoint.sh \
## Cache the published capture-stack wheels for the patched Selkies dependency range.
&& cd / \
&& pip wheel --no-cache-dir --only-binary=:all: \
'pixelflux' 'pcmflux' -w /opt/selkies
&& cp /opt/utils/docker-entrypoint.sh /opt/selkies/docker-entrypoint.sh \
&& cp /opt/utils/install_list_selkies.apt /opt/selkies/ \
&& chmod +x /opt/selkies/docker-entrypoint.sh


# Stage 2: runtime image
# Stage 3: runtime image
FROM ${BASE_NAMESPACE:+$BASE_NAMESPACE/}${BASE_IMG}

LABEL maintainer="postmaster@labnow.ai"

SHELL ["/bin/bash", "--login", "-o", "pipefail", "-c"]

COPY --from=builder /opt/selkies /opt/selkies

RUN set -eux && cd /opt/selkies \
&& source /opt/utils/script-utils.sh \
&& install_apt /opt/selkies/install_list_selkies.apt \
&& pip install --no-cache-dir ./*.whl \
&& if [ -f /opt/selkies/lib/selkies_joystick_interposer.so ]; then \
ln -sf /opt/selkies/lib/selkies_joystick_interposer.so /usr/lib/selkies_joystick_interposer.so ; \
&& if [ -f /opt/selkies/lib/selkies_input_interposer.so ]; then \
ln -sf /opt/selkies/lib/selkies_input_interposer.so /usr/lib/selkies_input_interposer.so \
&& ln -sf /opt/selkies/lib/selkies_input_interposer.so /usr/lib/selkies_joystick_interposer.so ; \
fi \
&& if [ -f /opt/selkies/lib/selkies_v4l2_interposer.so ]; then \
ln -sf /opt/selkies/lib/selkies_v4l2_interposer.so /usr/lib/selkies_v4l2_interposer.so ; \
fi \
&& if [ -f /opt/selkies/lib/libudev.so.1.0.0-fake ]; then \
ln -sf /opt/selkies/lib/libudev.so.1.0.0-fake /usr/lib/libudev.so.1.0.0-fake \
ln -sf /opt/selkies/lib/libudev.so.1.0.0-fake /usr/lib/libudev.so.1.0.0-fake \
&& ln -sf /opt/selkies/lib/libudev.so.1.0.0-fake /usr/lib/libudev.so.1 \
&& ln -sf /opt/selkies/lib/libudev.so.1.0.0-fake /usr/lib/libudev.so ; \
fi \
&& rm -f /opt/selkies/*.whl \
&& list_installed_packages && install__clean
&& install__clean

ENV PATH=/opt/selkies:/opt/conda/bin:${PATH}

EXPOSE 8080
WORKDIR /opt/selkies

# '-c' option make bash commands are read from string.
# If there are arguments after the string, they are assigned to the positional parameters, starting with $0.
# '-o pipefail' prevents errors in a pipeline from being masked.
# If any command in a pipeline fails, that return code will be used as the return code of the whole pipeline.
# '--login': make bash first reads and executes commands from the file /etc/profile, if that file exists.
# After that, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.
SHELL ["/bin/bash", "--login", "-o", "pipefail", "-c"]
ENTRYPOINT ["/opt/selkies/docker-entrypoint.sh"]
14 changes: 11 additions & 3 deletions docker_gui/work/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,16 @@ fi
#
# Selkies args
#
if command -v selkies-gstreamer >/dev/null 2>&1; then
default_encoder="x264enc"
else
default_encoder="h264enc"
fi

args=(
"--addr=${SELKIES_ADDR:-0.0.0.0}"
"--port=${SELKIES_PORT:-8080}"
"--web-root=${SELKIES_WEB_ROOT:-/opt/selkies/share/selkies-web}"

"--encoder=${SELKIES_ENCODER:-x264enc}"
"--encoder=${SELKIES_ENCODER:-$default_encoder}"

"--stun-host=${SELKIES_STUN_HOST:-stun.l.google.com}"
"--stun-port=${SELKIES_STUN_PORT:-19302}"
Expand All @@ -122,6 +126,10 @@ args=(
"--enable-resize=${SELKIES_ENABLE_RESIZE}"
)

if [ -n "${SELKIES_WEB_ROOT:-}" ]; then
args+=("--web-root=${SELKIES_WEB_ROOT}")
fi

#
# HTTPS
#
Expand Down
8 changes: 6 additions & 2 deletions docker_gui/work/install_list_selkies.apt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ libxtst6 % X Test extension for injecting re
libxkbcommon0 libxkbcommon-dev % Keyboard layout processing and keycode translation for remote input.

% 5. Wayland Compatibility Layer
wayland-protocols libwayland-egl1 % Wayland display protocols and EGL hardware-accelerated rendering contexts.
libwayland-client0 libwayland-server0 libwayland-egl1 % Wayland client/server protocols and EGL contexts.

% 6. Audio Server Infrastructure
pulseaudio libpulse0 % Virtual audio daemon and client library to intercept container audio streams.
Expand All @@ -36,5 +36,9 @@ libyuv0 % Essential YUV video scaling and c
% 10. Control Plane & Language Bindings
python3-gi python3-gst-1.0 % Python bindings for GObject and GStreamer to orchestrate media pipelines.

% 11. System Level Essentials
% 11. Rust Selkies capture and rendering libraries
libdrm2 libgbm1 libinput10 libudev1 libva2 libva-drm2 % Runtime libraries used by pixelflux and the compositor.
libxcb1 libxcb-shm0 libxcb-xfixes0 % XCB shared-memory and cursor capture.

% 12. System Level Essentials
libatomic1 % Atomic operations for thread-safe C/C++ audio/video processing.
101 changes: 43 additions & 58 deletions docker_gui/work/script-setup-gui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@

source /opt/utils/script-utils.sh

setup_selkies_build_dependencies() {
setup_selkies_web_build_dependencies() {
apt-get -qq update -yq --fix-missing && apt-get -qq install -yq --no-install-recommends \
build-essential cmake g++ gcc git libxkbcommon-dev make pkg-config python3-dev python3-venv ;
ca-certificates git ;
}

cleanup_selkies_build_dependencies() {
apt-get purge -y --auto-remove \
build-essential cmake g++ gcc git libxkbcommon-dev make pkg-config python3-dev \
python3-venv \
&& rm -rf /tmp/selkies-src /root/.cache /root/.npm /var/tmp/* ;
setup_selkies_build_dependencies() {
apt-get -qq update -yq --fix-missing && apt-get -qq install -yq --no-install-recommends \
bison build-essential ca-certificates clang cmake curl git libclang-dev libdav1d-dev \
libde265-dev libdrm-dev libegl-dev libgbm-dev libgles-dev libinput-dev libopus-dev \
libpixman-1-dev libpulse-dev libudev-dev libva-dev libwayland-dev libxcb-shm0-dev libxcb-xfixes0-dev \
libxcb1-dev libxkbcommon-dev meson nasm ninja-build pkg-config xz-utils ;
}

setup_selkies_from_release() {
Expand All @@ -37,38 +38,14 @@ setup_selkies_from_release() {

setup_selkies_web_from_source() {
local src_dir="${1:-/tmp/selkies-src}"
local web_dir="${2:-/opt/selkies/share/selkies-web}"

echo "--> Building Selkies web dashboard..." \
&& cd "${src_dir}/addons/selkies-web-core" \
&& npm install \
&& npm run build \
&& cd "${src_dir}/addons/selkies-dashboard" \
&& cp ../selkies-web-core/dist/selkies-core.js src/ \
&& npm install \
&& npm run build \
&& mkdir -pv "${web_dir}/src" "${web_dir}/nginx" \
&& cp -arf dist/* "${web_dir}/" \
&& cp -f ../selkies-web-core/dist/selkies-core.js "${web_dir}/src/" \
&& cp -f ../universal-touch-gamepad/universalTouchGamepad.js "${web_dir}/src/" \
&& cp -arf ../selkies-web-core/dist/jsdb "${web_dir}/" \
&& cp -arf ../selkies-web-core/nginx/* "${web_dir}/nginx/" \
&& rm -rf "${src_dir}"/addons/*/node_modules /root/.npm /tmp/npm-* ;
}

setup_selkies_python_from_source() {
local src_dir="${1:-/tmp/selkies-src}"
local dist_dir="/tmp/selkies-dist"

echo "--> Building Selkies Python package..." \
&& mkdir -p "${dist_dir}" \
echo "--> Building Selkies web client..." \
&& cd "${src_dir}" \
&& pip install --no-cache-dir --upgrade pip setuptools wheel build \
&& python3 -m build --outdir "${dist_dir}" \
&& cp -r "${dist_dir}"/*.whl /opt/selkies/ \
&& echo "--> Installing Selkies Python package..." \
&& pip install --no-cache-dir "${dist_dir}"/*.whl \
&& rm -rf "${dist_dir}" ;
&& test -f scripts/ci/build-web.sh \
&& sh scripts/ci/build-web.sh \
&& test -f dist/web/index.html \
&& rm -rf web/selkies-web-core/node_modules web/selkies-dashboard/node_modules \
web/universal-touch-gamepad/node_modules /root/.npm /tmp/npm-* ;
}

setup_selkies_addons_from_source() {
Expand All @@ -77,27 +54,25 @@ setup_selkies_addons_from_source() {

mkdir -p "${lib_dir}"

if [ -f "${src_dir}/addons/js-interposer/joystick_interposer.c" ]; then
echo "--> Building Selkies joystick interposer..." \
&& gcc -shared -fPIC -ldl -o "${lib_dir}/selkies_joystick_interposer.so" \
"${src_dir}/addons/js-interposer/joystick_interposer.c" ;
if [ -f "${src_dir}/addons/input-interposer/input_interposer.c" ]; then
echo "--> Building Selkies input interposer..." \
&& gcc -shared -fPIC -o "${lib_dir}/selkies_input_interposer.so" \
"${src_dir}/addons/input-interposer/input_interposer.c" -ldl -pthread \
&& ln -sf selkies_input_interposer.so "${lib_dir}/selkies_joystick_interposer.so" ;
fi

if [ -f "${src_dir}/addons/fake-udev/Makefile" ]; then
echo "--> Building Selkies fake udev..." \
&& make -C "${src_dir}/addons/fake-udev" \
&& mv "${src_dir}/addons/fake-udev/libudev.so.1.0.0-fake" "${lib_dir}/" ;
&& cp "${src_dir}/addons/fake-udev/libudev.so.1.0.0-fake" "${lib_dir}/" ;
fi
}

setup_selkies_runtime_wrapper() {
cat > /opt/selkies/selkies-gstreamer-run <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
if command -v selkies-gstreamer &>/dev/null; then
exec selkies-gstreamer "$@"
fi
exec selkies "$@"
exec /opt/selkies/selkies "$@"
EOF
chmod +x /opt/selkies/selkies-gstreamer-run \
&& ln -sf /opt/selkies/selkies-gstreamer-run /usr/local/bin/selkies-gstreamer-run ;
Expand All @@ -118,20 +93,30 @@ checkout_selkies_source() {
}

setup_selkies_from_source() {
# ref: https://github.com/linuxserver/docker-baseimage-selkies/blob/master/Dockerfile
local ref="${VER_SELKIES_REF:-${VER_SELKIES:-main}}"
local src_dir="/tmp/selkies-src"

echo "Cloning Selkies source at ${ref}" \
&& rm -rf /opt/selkies "${src_dir}" \
&& mkdir -pv /opt/selkies/share \
&& checkout_selkies_source "${ref}" "${src_dir}" \
&& setup_selkies_web_from_source "${src_dir}" /opt/selkies/share/selkies-web \
&& setup_selkies_python_from_source "${src_dir}" \
local src_dir="${1:-/tmp/selkies-src}"
local pkg_dir="/tmp/selkies-package"
local codec_dir="/opt/selkies-codecs"
local cargo_bin cargo_home rustup_home
cargo_bin="$(command -v cargo)" || {
echo "Rust/Cargo is required in the Selkies build image" >&2
return 1
}
cargo_home="${CARGO_HOME:-$(dirname "$(dirname "${cargo_bin}")")}"
rustup_home="${RUSTUP_HOME:-$(rustup show home 2>/dev/null || printf /opt/rust/rustup)}"

echo "Building Selkies server from ${src_dir}" \
&& rm -rf /opt/selkies "${pkg_dir}" "${codec_dir}" \
&& mkdir -pv /opt/selkies \
&& cd "${src_dir}" \
&& sh infra/packaging/codecs.sh "${codec_dir}" "${src_dir}/crates/pixelflux" \
&& SELKIES_CODECS="${codec_dir}" CARGO_HOME="${cargo_home}" RUSTUP_HOME="${rustup_home}" \
SELKIES_VERSION="${SELKIES_VERSION:-0.0.0}" \
sh infra/packaging/server.sh "${pkg_dir}" \
&& install -m 755 "${pkg_dir}/usr/bin/selkies" /opt/selkies/selkies \
&& setup_selkies_addons_from_source "${src_dir}" \
&& setup_selkies_runtime_wrapper \
&& git -C "${src_dir}" rev-parse HEAD > /opt/selkies/version_info.txt \
&& rm -rf /tmp/selkies-src /root/.cache /root/.npm /var/tmp/* ;
&& rm -rf "${pkg_dir}" "${codec_dir}" /root/.cache /root/.npm /var/tmp/* ;

[ -x /opt/selkies/selkies-gstreamer-run ] && echo "@ Version of Selkies-GStreamer $(cat /opt/selkies/version_info.txt)" || return 1 ;
[ -x /opt/selkies/selkies-gstreamer-run ] && echo "@ Selkies version $(cat /opt/selkies/version_info.txt)" || return 1 ;
}
3 changes: 2 additions & 1 deletion docker_hermes/hermes.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ RUN set -eux \
### ---------- Frontend build (web + ui-tui) ----------
RUN set -eux \
## ---------- Node dependencies + Playwright (cached on manifests) ----------
&& npm install --include=dev --prefer-offline --no-audit --fetch-retries=5 \
&& PNPM_VERSION="$(node -p "require('./pm/lock.json').packages.pnpm.version")" \
&& npx --yes "pnpm@${PNPM_VERSION}" install --frozen-lockfile --prod=false --prefer-offline \
&& npm install -g playwright && playwright install --with-deps chromium --only-shell \
&& npm cache clean --force \
&& (cd web && npm run build) \
Expand Down
Loading
Loading