diff --git a/.dockerignore b/.dockerignore index cce3f836..b114a631 100644 --- a/.dockerignore +++ b/.dockerignore @@ -21,3 +21,7 @@ /*.pkg.tar.zst /*.egg-info /*kvmd-*.tar.gz +kvmd-launcher.bin +kvmd-launcher.build +kvmd-launcher.dist +kvmd-launcher.onefile-build \ No newline at end of file diff --git a/.gitignore b/.gitignore index 96074115..eb0e280c 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,8 @@ kvmd_config/ __pycache__/ kvmd_data/run/kvmd/* .vscode/ +kvmd-launcher.bin +kvmd-launcher.build +kvmd-launcher.dist +kvmd-launcher.onefile-build +ustreamer/ diff --git a/Makefile b/Makefile index b4c6cc73..4941bf4c 100644 --- a/Makefile +++ b/Makefile @@ -285,12 +285,12 @@ run-stage-0: run-build-dev: $(DOCKER) buildx build -t registry.cn-hangzhou.aliyuncs.com/silentwind/kvmd:dev \ --platform linux/amd64,linux/arm64,linux/arm/v7 \ - --build-arg CACHEBUST=$(date +%s) \ + --build-arg CACHEBUST=$(date +%s) --allow security.insecure \ -f build/Dockerfile . \ --push $(DOCKER) buildx build -t silentwind0/kvmd:dev \ --platform linux/amd64,linux/arm64,linux/arm/v7 \ - --build-arg CACHEBUST=$(date +%s) \ + --build-arg CACHEBUST=$(date +%s) --allow security.insecure \ -f build/Dockerfile . \ --push @@ -351,16 +351,16 @@ run-nogpio: testenv && $(if $(CMD),$(CMD),python -m kvmd.apps.kvmd --run) \ " nuitka: - python -m nuitka kvmd-test.py --standalone --onefile --no-deployment-flag=self-execution --include-module=\ - kvmd.plugins.auth.htpasswd,kvmd.plugins.auth.http,kvmd.plugins.auth.ldap,\ - kvmd.plugins.auth.pam,kvmd.plugins.auth.radius,\ - kvmd.plugins.hid.ch9329,kvmd.plugins.hid.bt,kvmd.plugins.hid.otg,\ - kvmd.plugins.atx.disabled,kvmd.plugins.atx.gpio,\ - kvmd.plugins.msd.disabled,kvmd.plugins.msd.otg,\ - kvmd.plugins.ugpio.gpio,kvmd.plugins.ugpio.wol,kvmd.plugins.ugpio.cmd,\ - kvmd.plugins.ugpio.ipmi,kvmd.plugins.ugpio.anelpwr,kvmd.plugins.ugpio.cmdret,\ - kvmd.plugins.ugpio.extron,kvmd.plugins.ugpio.ezcoo,kvmd.plugins.ugpio.hidrelay,\ - kvmd.plugins.ugpio.hue,kvmd.plugins.ugpio.locator,kvmd.plugins.ugpio.noyito,\ - kvmd.plugins.ugpio.otgconf,kvmd.plugins.ugpio.pway,kvmd.plugins.ugpio.pwm,\ - kvmd.plugins.ugpio.servo,kvmd.plugins.ugpio.tesmart,kvmd.plugins.ugpio.xh_hk4401,\ - passlib.handlers.sha1_crypt,pygments.formatters.terminal \ No newline at end of file + python3.11 -m nuitka kvmd-launcher.py --standalone --onefile --no-deployment-flag=self-execution --include-module=\ +kvmd.plugins.auth.htpasswd,kvmd.plugins.auth.http,kvmd.plugins.auth.ldap,\ +kvmd.plugins.auth.pam,kvmd.plugins.auth.radius,\ +kvmd.plugins.hid.ch9329,kvmd.plugins.hid.bt,kvmd.plugins.hid.otg,\ +kvmd.plugins.atx.disabled,kvmd.plugins.atx.gpio,\ +kvmd.plugins.msd.disabled,kvmd.plugins.msd.otg,\ +kvmd.plugins.ugpio.gpio,kvmd.plugins.ugpio.wol,kvmd.plugins.ugpio.cmd,\ +kvmd.plugins.ugpio.ipmi,kvmd.plugins.ugpio.anelpwr,kvmd.plugins.ugpio.cmdret,\ +kvmd.plugins.ugpio.extron,kvmd.plugins.ugpio.ezcoo,kvmd.plugins.ugpio.hidrelay,\ +kvmd.plugins.ugpio.hue,kvmd.plugins.ugpio.locator,kvmd.plugins.ugpio.noyito,\ +kvmd.plugins.ugpio.otgconf,kvmd.plugins.ugpio.pway,kvmd.plugins.ugpio.pwm,\ +kvmd.plugins.ugpio.servo,kvmd.plugins.ugpio.tesmart,kvmd.plugins.ugpio.xh_hk4401,\ +passlib.handlers.sha1_crypt,pygments.formatters.terminal \ No newline at end of file diff --git a/build/Dockerfile b/build/Dockerfile index d87119a0..850c8eee 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,38 +1,82 @@ -FROM silentwind0/kvmd-stage-0 AS builder - -FROM python:3.12.0rc2-slim-bookworm - -LABEL maintainer="mofeng654321@hotmail.com" - -COPY --from=builder /tmp/lib/* /tmp/lib/ -COPY --from=builder /tmp/ustreamer/ustreamer /tmp/ustreamer/ustreamer-dump /usr/bin/janus /usr/bin/ -COPY --from=builder /tmp/wheel/*.whl /tmp/wheel/ -COPY --from=builder /tmp/ustreamer/libjanus_ustreamer.so /usr/lib/ustreamer/janus/ -COPY --from=builder /usr/lib/janus/transports/* /usr/lib/janus/transports/ +# syntax = docker/dockerfile:experimental +FROM python:3.12.8-slim-bookworm AS builder ARG TARGETARCH -ENV PYTHONDONTWRITEBYTECODE=1 -ENV PYTHONUNBUFFERED=1 -ENV TZ=Asia/Shanghai +RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.list.d/debian.sources \ + && apt-get update \ + && apt-get install -y --no-install-recommends build-essential libssl-dev libffi-dev python3-dev libevent-dev libjpeg-dev \ + libbsd-dev libudev-dev git pkg-config wget curl libmicrohttpd-dev libjansson-dev libssl-dev libsofia-sip-ua-dev \ + libopus-dev libogg-dev libcurl4-openssl-dev liblua5.3-dev libconfig-dev libopus-dev libtool automake autoconf \ + libx264-dev libyuv-dev libasound2-dev libspeex-dev libspeexdsp-dev libopus-dev libgpiod-dev libsystemd-dev \ + libglib2.0-dev libwebsockets-dev libsrtp2-dev libnice-dev patchelf libxkbcommon0 sudo iproute2 iptables libusb-dev \ + && rm -rf /var/lib/apt/lists/* -RUN cp /tmp/lib/* /lib/*-linux-*/ \ - && pip install --no-cache-dir --root-user-action=ignore --disable-pip-version-check /tmp/wheel/*.whl \ - && pip install --no-cache-dir --root-user-action=ignore --disable-pip-version-check pyfatfs \ - && rm -rf /tmp/lib /tmp/wheel +COPY build/cargo_config /tmp/config + +RUN --security=insecure pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \ + && if [ ${TARGETARCH} = arm ]; then \ + mkdir -p /root/.cargo \ + && chmod 777 /root/.cargo && mount -t tmpfs none /root/.cargo \ + && export RUSTUP_DIST_SERVER="https://mirrors.tuna.tsinghua.edu.cn/rustup" \ + #&& export RUSTUP_UPDATE_ROOT="https://mirrors.ustc.edu.cn/rust-static/rustup" \ + && wget https://sh.rustup.rs -O /root/rustup-init.sh \ + && sh /root/rustup-init.sh -y \ + && export PATH=$PATH:/root/.cargo/bin \ + && cp /tmp/config /root/.cargo/config.toml; \ + fi \ + && pip install cryptography + +RUN pip install --no-cache-dir --root-user-action=ignore --disable-pip-version-check build nuitka \ + && pip install --no-cache-dir aiofiles aiohttp appdirs asn1crypto async_lru async-timeout bottle cffi chardet click colorama \ + dbus_next gpiod hidapi idna mako marshmallow more-itertools multidict netifaces packaging passlib pillow ply psutil pycparser \ + pyelftools pyghmi pygments pyparsing pyotp qrcode requests semantic-version setproctitle setuptools six spidev \ + tabulate urllib3 wrapt xlib yarl pyserial pyyaml zstandard supervisor + +RUN git clone --depth=1 https://github.com/meetecho/janus-gateway.git /tmp/janus-gateway \ + && cd /tmp/janus-gateway \ + && bash autogen.sh \ + && ./configure --enable-static --enable-websockets --enable-plugin-audiobridge \ + --disable-data-channels --disable-rabbitmq --disable-mqtt --disable-all-plugins --disable-all-loggers \ + --prefix=/usr \ + && make && make install + +RUN sed --in-place --expression 's|^#include "refcount.h"$|#include "../refcount.h"|g' /usr/include/janus/plugins/plugin.h \ + && git clone --depth=1 https://github.com/mofeng-git/ustreamer /tmp/ustreamer \ + && make clean -C /tmp/ustreamer \ + && make WITH_GPIO=1 WITH_JANUS=1 WITH_PYTHON=1 WITH_LIBX264=1 WITH_SETPROCTITLE=0 -C /tmp/ustreamer install + +COPY kvmd /One-KVM/kvmd +COPY kvmd-launcher.py /One-KVM/ + +RUN bash -c "cd /One-KVM && ls && python3 -m nuitka kvmd-launcher.py --standalone --onefile \ +--show-progress --no-deployment-flag=self-execution --include-module=\ +kvmd.plugins.auth.htpasswd,kvmd.plugins.auth.http,kvmd.plugins.auth.ldap,\ +kvmd.plugins.auth.pam,kvmd.plugins.auth.radius,\ +kvmd.plugins.hid.ch9329,kvmd.plugins.hid.bt,kvmd.plugins.hid.otg,\ +kvmd.plugins.atx.disabled,kvmd.plugins.atx.gpio,\ +kvmd.plugins.msd.disabled,kvmd.plugins.msd.otg,\ +kvmd.plugins.ugpio.gpio,kvmd.plugins.ugpio.wol,kvmd.plugins.ugpio.cmd,\ +kvmd.plugins.ugpio.ipmi,kvmd.plugins.ugpio.anelpwr,kvmd.plugins.ugpio.cmdret,\ +kvmd.plugins.ugpio.extron,kvmd.plugins.ugpio.ezcoo,kvmd.plugins.ugpio.hidrelay,\ +kvmd.plugins.ugpio.hue,kvmd.plugins.ugpio.locator,kvmd.plugins.ugpio.noyito,\ +kvmd.plugins.ugpio.otgconf,kvmd.plugins.ugpio.pway,kvmd.plugins.ugpio.pwm,\ +kvmd.plugins.ugpio.servo,kvmd.plugins.ugpio.tesmart,kvmd.plugins.ugpio.xh_hk4401,\ +passlib.handlers.sha1_crypt,pygments.formatters.terminal" + +COPY kvmd_data /One-KVM/kvmd_data +RUN cp /usr/local/bin/ustreamer /usr/local/bin/ustreamer-dump /One-KVM/kvmd_data/usr/bin \ + && cd /One-KVM && python3 -m kvmd.apps.kvmd -m -c kvmd_data/etc/kvmd/main.yaml + +FROM debian:stable-slim + +COPY --from=builder /One-KVM/kvmd_data kvmd_data +COPY --from=builder /One-KVM/kvmd-launcher.bin kvmd-launcher.bin RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.list.d/debian.sources \ && apt-get update \ - && apt-get install -y --no-install-recommends libxkbcommon-x11-0 nginx tesseract-ocr tesseract-ocr-eng tesseract-ocr-chi-sim iptables sudo curl kmod \ - libmicrohttpd12 libjansson4 libssl3 libsofia-sip-ua0 libglib2.0-0 libopus0 libogg0 libcurl4 libconfig9 libusrsctp2 libwebsockets17 libnss3 libasound2 nano \ + && apt-get install -y libxkbcommon0 sudo iproute2 iptables nano \ && rm -rf /var/lib/apt/lists/* -RUN if [ ${TARGETARCH} = arm ]; then ARCH=armhf; elif [ ${TARGETARCH} = arm64 ]; then ARCH=aarch64; elif [ ${TARGETARCH} = amd64 ]; then ARCH=x86_64; fi \ - && curl https://github.com/tsl0922/ttyd/releases/download/1.7.7/ttyd.$ARCH -L -o /usr/local/bin/ttyd \ - && chmod +x /usr/local/bin/ttyd \ - && ln -sf /usr/share/tesseract-ocr/*/tessdata /usr/share/tessdata - - -COPY . /One-KVM - -ENTRYPOINT ["bash"] \ No newline at end of file +ENTRYPOINT [ "/kvmd-launcher.bin" ] +#RUN cd /One-KVM && /One-KVM/kvmd-launcher.bin \ No newline at end of file diff --git a/build/Dockerfile-backup b/build/Dockerfile-backup new file mode 100644 index 00000000..d87119a0 --- /dev/null +++ b/build/Dockerfile-backup @@ -0,0 +1,38 @@ +FROM silentwind0/kvmd-stage-0 AS builder + +FROM python:3.12.0rc2-slim-bookworm + +LABEL maintainer="mofeng654321@hotmail.com" + +COPY --from=builder /tmp/lib/* /tmp/lib/ +COPY --from=builder /tmp/ustreamer/ustreamer /tmp/ustreamer/ustreamer-dump /usr/bin/janus /usr/bin/ +COPY --from=builder /tmp/wheel/*.whl /tmp/wheel/ +COPY --from=builder /tmp/ustreamer/libjanus_ustreamer.so /usr/lib/ustreamer/janus/ +COPY --from=builder /usr/lib/janus/transports/* /usr/lib/janus/transports/ + +ARG TARGETARCH + +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 +ENV TZ=Asia/Shanghai + +RUN cp /tmp/lib/* /lib/*-linux-*/ \ + && pip install --no-cache-dir --root-user-action=ignore --disable-pip-version-check /tmp/wheel/*.whl \ + && pip install --no-cache-dir --root-user-action=ignore --disable-pip-version-check pyfatfs \ + && rm -rf /tmp/lib /tmp/wheel + +RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.list.d/debian.sources \ + && apt-get update \ + && apt-get install -y --no-install-recommends libxkbcommon-x11-0 nginx tesseract-ocr tesseract-ocr-eng tesseract-ocr-chi-sim iptables sudo curl kmod \ + libmicrohttpd12 libjansson4 libssl3 libsofia-sip-ua0 libglib2.0-0 libopus0 libogg0 libcurl4 libconfig9 libusrsctp2 libwebsockets17 libnss3 libasound2 nano \ + && rm -rf /var/lib/apt/lists/* + +RUN if [ ${TARGETARCH} = arm ]; then ARCH=armhf; elif [ ${TARGETARCH} = arm64 ]; then ARCH=aarch64; elif [ ${TARGETARCH} = amd64 ]; then ARCH=x86_64; fi \ + && curl https://github.com/tsl0922/ttyd/releases/download/1.7.7/ttyd.$ARCH -L -o /usr/local/bin/ttyd \ + && chmod +x /usr/local/bin/ttyd \ + && ln -sf /usr/share/tesseract-ocr/*/tessdata /usr/share/tessdata + + +COPY . /One-KVM + +ENTRYPOINT ["bash"] \ No newline at end of file diff --git a/build/Dockerfile-stage-0 b/build/Dockerfile-stage-0 deleted file mode 100644 index df9f5505..00000000 --- a/build/Dockerfile-stage-0 +++ /dev/null @@ -1,70 +0,0 @@ -# syntax = docker/dockerfile:experimental -FROM python:3.12.0rc2-slim-bookworm AS builder - -ARG TARGETARCH - -RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.list.d/debian.sources \ - && apt-get update \ - && apt-get install -y --no-install-recommends build-essential libssl-dev libffi-dev python3-dev libevent-dev libjpeg-dev \ - libbsd-dev libudev-dev git pkg-config wget curl libmicrohttpd-dev libjansson-dev libssl-dev libsofia-sip-ua-dev libglib2.0-dev \ - libopus-dev libogg-dev libcurl4-openssl-dev liblua5.3-dev libconfig-dev libopus-dev libtool automake autoconf meson cmake \ - libx264-dev libyuv-dev libasound2-dev libspeex-dev libspeexdsp-dev libopus-dev \ - && rm -rf /var/lib/apt/lists/* - -COPY build/cargo_config /tmp/config - -RUN --security=insecure pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \ - && if [ ${TARGETARCH} = arm ]; then \ - mkdir -p /root/.cargo \ - && chmod 777 /root/.cargo && mount -t tmpfs none /root/.cargo \ - && export RUSTUP_DIST_SERVER="https://mirrors.tuna.tsinghua.edu.cn/rustup" \ - #&& export RUSTUP_UPDATE_ROOT="https://mirrors.ustc.edu.cn/rust-static/rustup" \ - && wget https://sh.rustup.rs -O /root/rustup-init.sh \ - && sh /root/rustup-init.sh -y \ - && export PATH=$PATH:/root/.cargo/bin \ - && cp /tmp/config /root/.cargo/config.toml; \ - fi \ - && pip wheel --wheel-dir=/tmp/wheel/ cryptography - -RUN pip install --no-cache-dir --root-user-action=ignore --disable-pip-version-check build \ - && pip wheel --wheel-dir=/tmp/wheel/ aiofiles aiohttp appdirs asn1crypto async_lru async-timeout bottle cffi chardet click colorama \ - dbus_next gpiod hidapi idna mako marshmallow more-itertools multidict netifaces packaging passlib pillow ply psutil pycparser \ - pyelftools pyghmi pygments pyparsing pyotp qrcode requests semantic-version setproctitle setuptools six spidev \ - tabulate urllib3 wrapt xlib yarl pyserial pyyaml zstandard supervisor - -RUN git clone --depth=1 https://gitlab.freedesktop.org/libnice/libnice /tmp/libnice \ - && cd /tmp/libnice \ - && meson --prefix=/usr build && ninja -C build && ninja -C build install - -RUN curl https://github.com/cisco/libsrtp/archive/v2.2.0.tar.gz -L -o /tmp/libsrtp-2.2.0.tar.gz \ - && cd /tmp \ - && tar xfv libsrtp-2.2.0.tar.gz \ - && cd libsrtp-2.2.0 \ - && ./configure --prefix=/usr --enable-openssl \ - && make shared_library && make install - -RUN git clone --depth=1 https://libwebsockets.org/repo/libwebsockets /tmp/libwebsockets \ - && cd /tmp/libwebsockets \ - && mkdir build && cd build \ - && cmake -DLWS_MAX_SMP=1 -DLWS_WITHOUT_EXTENSIONS=0 -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" .. \ - && make && make install - -RUN git clone --depth=1 https://github.com/meetecho/janus-gateway.git /tmp/janus-gateway \ - && cd /tmp/janus-gateway \ - && sh autogen.sh \ - && ./configure --enable-static --enable-websockets --enable-plugin-audiobridge \ - --disable-data-channels --disable-rabbitmq --disable-mqtt --disable-all-plugins --disable-all-loggers \ - --prefix=/usr \ - && make && make install - -RUN sed --in-place --expression 's|^#include "refcount.h"$|#include "../refcount.h"|g' /usr/include/janus/plugins/plugin.h \ - && git clone --depth=1 https://github.com/mofeng-git/ustreamer /tmp/ustreamer \ - && make -j WITH_PYTHON=1 WITH_JANUS=1 WITH_LIBX264=1 -C /tmp/ustreamer \ - && /tmp/ustreamer/ustreamer -v - -RUN mkdir /tmp/lib \ - && cd /lib/*-linux-*/ \ - && cp libevent_core-*.so.7 libbsd.so.0 libevent_pthreads-*.so.7 libspeexdsp.so.1 libevent-*.so.7 libjpeg.so.62 libx264.so.164 libyuv.so.0 \ - libnice.so.10 /usr/lib/libsrtp2.so.1 /usr/lib/libwebsockets.so.19 \ - /tmp/lib/ \ - && cp /tmp/ustreamer/python/dist/*.whl /tmp/wheel/ \ No newline at end of file diff --git a/kvmd-launcher.py b/kvmd-launcher.py new file mode 100644 index 00000000..5ca4ae3f --- /dev/null +++ b/kvmd-launcher.py @@ -0,0 +1,11 @@ +from kvmd.apps.kvmd import main as kvmd_main +def start(): + custom_argv = [ + 'kvmd', + '-c', 'kvmd_data/etc/kvmd/main.yaml', + '--run' + ] + kvmd_main(argv=custom_argv) + +if __name__ == '__main__': + start() \ No newline at end of file diff --git a/kvmd_data/etc/kvmd/override.yaml b/kvmd_data/etc/kvmd/override.yaml index a2c368b2..4ee138dd 100644 --- a/kvmd_data/etc/kvmd/override.yaml +++ b/kvmd_data/etc/kvmd/override.yaml @@ -77,7 +77,6 @@ kvmd: - "--unix-rm" - "--unix-mode=777" - "--exit-on-parent-death" - - "--process-name-prefix={process_name_prefix}" - "--notify-parent" - "--no-log-colors" - "--jpeg-sink=kvmd::ustreamer::jpeg" @@ -86,72 +85,7 @@ kvmd: unix: kvmd_data/run/kvmd/ustreamer.sock - gpio: - drivers: - wol_server1: - type: wol - mac: 2c:56:dc:db:7c:1e - short_press: - type: cmd - cmd: [kvmd_data/etc/kvmd/atx.sh, short] - long_press: - type: cmd - cmd: [kvmd_data/etc/kvmd/atx.sh, long] - reset_press: - type: cmd - cmd: [kvmd_data/etc/kvmd/atx.sh, reset] - input1: - type: cmd - cmd: [kvmd_data/etc/kvmd/kvm_input.sh, 1] - input2: - type: cmd - cmd: [kvmd_data/etc/kvmd/kvm_input.sh, 2] - scheme: - wol_server1: - driver: wol_server1 - pin: 0 - mode: output - switch: false - short_button: - driver: short_press - pin: 0 - mode: output - switch: false - long_button: - driver: long_press - pin: 0 - mode: output - switch: false - reset_button: - driver: reset_press - pin: 0 - mode: output - switch: false - input1-button: - driver: input1 - pin: 0 - mode: output - switch: false - input2-button: - driver: input2 - pin: 0 - mode: output - switch: false - view: - header: - title: 高级功能 - table: - - ["#电源管理"] - - ["#短按(开/关机):", short_button|按下] - - ["#长按(强制关机):", long_button|按下] - - ["#重启:", reset_button|按下] - - [] - - ["#网络唤醒"] - - ["#被控机设备", wol_server1|网络唤醒] - - [] - - ["#KVM 切换"] - - ["#HDMI 1", input1-button|切换] - - ["#HDMI 2", input2-button|切换] + ipmi: auth: file: kvmd_data/etc/kvmd/ipmipasswd