fix: 优化 Docker 构建流程并修复 Ventoy 资源路径

- Dockerfile: 合并 RUN 层减少镜像层数,使用 COPY --chmod 简化权限设置
- init.sh: 指定数据目录为 /etc/one-kvm 确保路径一致
- package-docker.sh: 从 libs/ventoy-img-rs/resources 复制资源并自动解压 xz 文件
- README.md: 修正 docker run 示例格式
This commit is contained in:
mofeng-git
2025-12-28 19:11:48 +08:00
parent d143d158e4
commit 61323a7664
4 changed files with 30 additions and 37 deletions

View File

@@ -49,10 +49,11 @@ One-KVM 是一个用 Rust 编写的开放轻量的 IP-KVM基于 IP 的键盘
```bash ```bash
docker run -d --privileged \ docker run -d --privileged \
--name one-kvm \
-v /dev:/dev \ -v /dev:/dev \
-v /sys/kernel/config:/sys/kernel/config \ -v /sys/kernel/config:/sys/kernel/config \
--net=host \ --net=host \
siletwind0/one-kvm silentwind0/one-kvm
``` ```
访问 http://IP:8080 访问 http://IP:8080

View File

@@ -8,7 +8,7 @@ FROM debian:12-slim
ARG TARGETPLATFORM ARG TARGETPLATFORM
# Install runtime dependencies only (matches build environment) # Install runtime dependencies and create directories
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
# Runtime libraries # Runtime libraries
libasound2 \ libasound2 \
@@ -38,39 +38,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libxcb1 \ libxcb1 \
# Utilities # Utilities
ca-certificates \ ca-certificates \
&& rm -rf /var/lib/apt/lists/* # Intel Media SDK (x86_64 only, ignored on other archs)
$([ "$TARGETPLATFORM" = "linux/amd64" ] && echo "libmfx1") \
# Intel Media SDK runtime for x86_64 only && rm -rf /var/lib/apt/lists/* \
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ && mkdir -p /etc/one-kvm/ventoy
apt-get update && \
apt-get install -y --no-install-recommends libmfx1 && \
rm -rf /var/lib/apt/lists/*; \
fi
# Create directories
RUN mkdir -p /etc/one-kvm/ventoy
# Copy init script # Copy init script
COPY init.sh /init.sh COPY --chmod=755 init.sh /init.sh
# Copy binaries (these are placed by the build script) # Copy binaries (these are placed by the build script)
COPY one-kvm /usr/bin/one-kvm COPY --chmod=755 one-kvm ttyd gostc easytier-core /usr/bin/
COPY ttyd /usr/bin/ttyd
COPY gostc /usr/bin/gostc
COPY easytier-core /usr/bin/easytier-core
# Copy ventoy resources if they exist # Copy ventoy resources if they exist
COPY ventoy/ /etc/one-kvm/ventoy/ COPY ventoy/ /etc/one-kvm/ventoy/
# Set permissions and verify
RUN chmod +x /init.sh /usr/bin/one-kvm /usr/bin/ttyd /usr/bin/gostc /usr/bin/easytier-core && \
/usr/bin/one-kvm --help
# Expose ports
EXPOSE 8080 8443
# Data volume
VOLUME ["/etc/one-kvm"]
# Entrypoint # Entrypoint
CMD ["/init.sh"] CMD ["/init.sh"]

View File

@@ -6,7 +6,7 @@ set -e
# Start one-kvm with default options # Start one-kvm with default options
# Additional options can be passed via environment variables # Additional options can be passed via environment variables
EXTRA_ARGS="" EXTRA_ARGS="-d /etc/one-kvm"
# Enable HTTPS if requested # Enable HTTPS if requested
if [ "${ENABLE_HTTPS:-false}" = "true" ]; then if [ "${ENABLE_HTTPS:-false}" = "true" ]; then

View File

@@ -232,12 +232,24 @@ build_for_platform() {
# Copy init script # Copy init script
cp "$PROJECT_ROOT/build/init.sh" "$staging/init.sh" cp "$PROJECT_ROOT/build/init.sh" "$staging/init.sh"
# Copy ventoy resources if they exist # Copy ventoy resources (decompress xz files if needed)
if [ -d "$PROJECT_ROOT/res/ventoy" ]; then local ventoy_src="$PROJECT_ROOT/libs/ventoy-img-rs/resources"
cp -r "$PROJECT_ROOT/res/ventoy/"* "$staging/ventoy/" 2>/dev/null || true if [ -d "$ventoy_src" ]; then
echo_info "Copying Ventoy resources..."
# Copy boot.img directly
if [ -f "$ventoy_src/boot.img" ]; then
cp "$ventoy_src/boot.img" "$staging/ventoy/"
fi
# Decompress xz files
if [ -f "$ventoy_src/core.img.xz" ]; then
xz -dk "$ventoy_src/core.img.xz" -c > "$staging/ventoy/core.img"
fi
if [ -f "$ventoy_src/ventoy.disk.img.xz" ]; then
xz -dk "$ventoy_src/ventoy.disk.img.xz" -c > "$staging/ventoy/ventoy.disk.img"
fi
else
echo_warn "Ventoy resources not found at $ventoy_src"
fi fi
# Ensure ventoy dir exists (even if empty) for COPY command
touch "$staging/ventoy/.keep"
# Copy Dockerfile # Copy Dockerfile
cp "$PROJECT_ROOT/build/Dockerfile.runtime" "$staging/Dockerfile" cp "$PROJECT_ROOT/build/Dockerfile.runtime" "$staging/Dockerfile"