diff --git a/compose/.env.example b/compose/.env.example index 7e57f68..fb104df 100644 --- a/compose/.env.example +++ b/compose/.env.example @@ -72,6 +72,19 @@ MLKJ_INTEGRATION_SECRET=replace-with-a-random-value PRINT_CLIENT_SHARED_TOKEN=replace-with-a-random-value PRINT_DEFAULT_TARGET_CLIENT_ID=farm-workstation-001 PRINT_ALLOWED_CLIENT_ID=farm-workstation-001 +PRINT_EXTERNAL_TOOLS_HOST_PATH=/srv/ai-soulmate/runtime/external-tools-production-20260416 +PRINT_LOCAL_PROFILES_HOST_PATH=/srv/ai-soulmate/runtime/u1-profiles +PRINT_SLICER_TIMEOUT_SECONDS=900 +PRINT_SLICER_CMD_TEMPLATE=python /app/scripts/slice_with_orca.py {input_path} {output_dir} {material} {height} +PRINT_ORCA_SLICER_BINARY=/app/external-tools/bin/Snapmaker_Orca_Linux_AppImage_Ubuntu2404_V2.3.0_Beta.AppImage +PRINT_ORCA_APPIMAGE_EXTRACT_AND_RUN=true +PRINT_ORCA_PRINTER_PROFILE=/app/external-tools/bin/squashfs-root/resources/profiles/Snapmaker/machine/Snapmaker U1 (0.4 nozzle).json +PRINT_ORCA_MATERIAL_PROFILE_MAP={"default":"/app/external-tools/bin/squashfs-root/resources/profiles/Snapmaker/filament/Snapmaker PLA @U1.json","PLA":"/app/external-tools/bin/squashfs-root/resources/profiles/Snapmaker/filament/Snapmaker PLA @U1.json","PLA_WHITE":"/app/external-tools/bin/squashfs-root/resources/profiles/Snapmaker/filament/Snapmaker PLA @U1.json"} +PRINT_ORCA_HEIGHT_PROFILE_MAP={"default":"/app/local-profiles/u1-compatible-generic-process.json"} +PRINT_ORCA_DEFAULT_TOOL_COMMAND=T0 +PRINT_ORCA_TOOL_COMMAND_MAP={"PLA":"T0","PLA_WHITE":"T0"} +PRINT_ORCA_FIRST_LAYER_BED_TEMPERATURE_MAP={"PLA":"65","PLA_WHITE":"65"} +PRINT_ORCA_BED_TEMPERATURE_MAP={"PLA":"60","PLA_WHITE":"60"} OSS_PUBLIC_ENDPOINT=http://127.0.0.1:9000 CORS_ALLOWED_ORIGINS=http://localhost:8080,http://127.0.0.1:8080 diff --git a/compose/docker-compose.backend.yml b/compose/docker-compose.backend.yml index 75180e6..0671518 100644 --- a/compose/docker-compose.backend.yml +++ b/compose/docker-compose.backend.yml @@ -17,6 +17,17 @@ services: PRINT_CLIENT_SHARED_TOKEN: ${PRINT_CLIENT_SHARED_TOKEN:?PRINT_CLIENT_SHARED_TOKEN is required} PRINT_DEFAULT_TARGET_CLIENT_ID: ${PRINT_DEFAULT_TARGET_CLIENT_ID:?PRINT_DEFAULT_TARGET_CLIENT_ID is required} PRINT_ALLOWED_CLIENT_ID: ${PRINT_ALLOWED_CLIENT_ID:?PRINT_ALLOWED_CLIENT_ID is required} + PRINT_SLICER_TIMEOUT_SECONDS: ${PRINT_SLICER_TIMEOUT_SECONDS:?PRINT_SLICER_TIMEOUT_SECONDS is required} + PRINT_SLICER_CMD_TEMPLATE: ${PRINT_SLICER_CMD_TEMPLATE:?PRINT_SLICER_CMD_TEMPLATE is required} + PRINT_ORCA_SLICER_BINARY: ${PRINT_ORCA_SLICER_BINARY:?PRINT_ORCA_SLICER_BINARY is required} + PRINT_ORCA_APPIMAGE_EXTRACT_AND_RUN: ${PRINT_ORCA_APPIMAGE_EXTRACT_AND_RUN:?PRINT_ORCA_APPIMAGE_EXTRACT_AND_RUN is required} + PRINT_ORCA_PRINTER_PROFILE: ${PRINT_ORCA_PRINTER_PROFILE:?PRINT_ORCA_PRINTER_PROFILE is required} + PRINT_ORCA_MATERIAL_PROFILE_MAP: ${PRINT_ORCA_MATERIAL_PROFILE_MAP:?PRINT_ORCA_MATERIAL_PROFILE_MAP is required} + PRINT_ORCA_HEIGHT_PROFILE_MAP: ${PRINT_ORCA_HEIGHT_PROFILE_MAP:?PRINT_ORCA_HEIGHT_PROFILE_MAP is required} + PRINT_ORCA_DEFAULT_TOOL_COMMAND: ${PRINT_ORCA_DEFAULT_TOOL_COMMAND:?PRINT_ORCA_DEFAULT_TOOL_COMMAND is required} + PRINT_ORCA_TOOL_COMMAND_MAP: ${PRINT_ORCA_TOOL_COMMAND_MAP:?PRINT_ORCA_TOOL_COMMAND_MAP is required} + PRINT_ORCA_FIRST_LAYER_BED_TEMPERATURE_MAP: ${PRINT_ORCA_FIRST_LAYER_BED_TEMPERATURE_MAP:?PRINT_ORCA_FIRST_LAYER_BED_TEMPERATURE_MAP is required} + PRINT_ORCA_BED_TEMPERATURE_MAP: ${PRINT_ORCA_BED_TEMPERATURE_MAP:?PRINT_ORCA_BED_TEMPERATURE_MAP is required} OSS_PROVIDER: minio OSS_ENDPOINT: http://minio:9000 OSS_BUCKET_NAME: ${MINIO_BUCKET:?MINIO_BUCKET is required} @@ -50,6 +61,8 @@ services: volumes: - backend_uploads:/app/uploads - backend_logs:/app/logs + - ${PRINT_EXTERNAL_TOOLS_HOST_PATH:?PRINT_EXTERNAL_TOOLS_HOST_PATH is required}:/app/external-tools:ro + - ${PRINT_LOCAL_PROFILES_HOST_PATH:?PRINT_LOCAL_PROFILES_HOST_PATH is required}:/app/local-profiles:ro healthcheck: test: - CMD diff --git a/docs/LOCAL-SLICER-RUNTIME.md b/docs/LOCAL-SLICER-RUNTIME.md new file mode 100644 index 0000000..72a7ea5 --- /dev/null +++ b/docs/LOCAL-SLICER-RUNTIME.md @@ -0,0 +1,43 @@ +# 本地 U1 切片运行时 + +本地部署使用从生产环境**只读复制并校验**的 `external-tools` 运行时。生产服务器未被修改,二进制包不提交到 Git。 + +## 校验记录 + +- 归档:`external-tools-production-20260416.tar.gz` +- 归档 SHA256:`820a4cea7f6e0914846c8dac61be803b1116c44f25205c3048a7762a8475e3af` +- 本地运行时:`/srv/ai-soulmate/runtime/external-tools-production-20260416` +- AppRun SHA256:`951984442c0b416fd14714ac5f271f427d84566f533ec43fe719598875e3fb6c` +- AppImage SHA256:`d3676edc0e5385deb537a44e87496a4c7b631007884bad5234dcc4f5c8d8b09b` +- U1 profile 数量:`73` + +## U1 配置 + +- 机器:`Snapmaker/machine/Snapmaker U1 (0.4 nozzle).json` +- 白色 PLA:`Snapmaker/filament/Snapmaker PLA @U1.json` +- 官方工艺:`Snapmaker/process/0.20 Standard @Snapmaker U1 (0.4 nozzle).json` +- 本地工艺:`/app/local-profiles/u1-compatible-generic-process.json` +- 切片器:`/app/external-tools/bin/Snapmaker_Orca_Linux_AppImage_Ubuntu2404_V2.3.0_Beta.AppImage` + +Compose 将运行时挂载为 `/app/external-tools:ro`,将本地派生过程挂载为 `/app/local-profiles:ro`。生产式调用必须设置 `APPIMAGE_EXTRACT_AND_RUN=true`;直接调用 `AppRun` 已验证会失败。官方 U1 工艺在当前 Orca CLI 版本中返回 `127`,因此本地先使用通用 Snapmaker 工艺并将兼容机型改为 U1;这不修改原始 profile。 + +## 部署要求 + +服务器上完成解压后,运行: + +```bash +./scripts/prepare-u1-local-profile.sh + +./scripts/configure-backend-env.sh \ + compose/.env \ + /srv/ai-soulmate/sources/ai-soulmate-server \ + 192.168.3.102 \ + farm-workstation-001 + +docker compose --env-file compose/.env \ + -f compose/docker-compose.backend.yml config --quiet +``` + +准备脚本只读取外部工具中的通用 Snapmaker 工艺,并生成 `/srv/ai-soulmate/runtime/u1-profiles/u1-compatible-generic-process.json`。该文件不包含生产密钥,也不提交到 Git。 + +不要把运行时目录、归档或任何生产密钥提交到 Git。首次真实打印前,客户端应保持 `download_only` 或 `upload_only`,确认 G-code 后再单独批准启动。 diff --git a/scripts/configure-backend-env.sh b/scripts/configure-backend-env.sh index fa40906..00277c3 100755 --- a/scripts/configure-backend-env.sh +++ b/scripts/configure-backend-env.sh @@ -102,6 +102,19 @@ ensure_secret MLKJ_INTEGRATION_SECRET ensure_secret PRINT_CLIENT_SHARED_TOKEN set_value PRINT_DEFAULT_TARGET_CLIENT_ID "$client_id" set_value PRINT_ALLOWED_CLIENT_ID "$client_id" +set_value PRINT_EXTERNAL_TOOLS_HOST_PATH /srv/ai-soulmate/runtime/external-tools-production-20260416 +set_value PRINT_LOCAL_PROFILES_HOST_PATH /srv/ai-soulmate/runtime/u1-profiles +set_value PRINT_SLICER_TIMEOUT_SECONDS 900 +set_value PRINT_SLICER_CMD_TEMPLATE 'python /app/scripts/slice_with_orca.py {input_path} {output_dir} {material} {height}' +set_value PRINT_ORCA_SLICER_BINARY /app/external-tools/bin/Snapmaker_Orca_Linux_AppImage_Ubuntu2404_V2.3.0_Beta.AppImage +set_value PRINT_ORCA_APPIMAGE_EXTRACT_AND_RUN true +set_value PRINT_ORCA_PRINTER_PROFILE '/app/external-tools/bin/squashfs-root/resources/profiles/Snapmaker/machine/Snapmaker U1 (0.4 nozzle).json' +set_value PRINT_ORCA_MATERIAL_PROFILE_MAP '{"default":"/app/external-tools/bin/squashfs-root/resources/profiles/Snapmaker/filament/Snapmaker PLA @U1.json","PLA":"/app/external-tools/bin/squashfs-root/resources/profiles/Snapmaker/filament/Snapmaker PLA @U1.json","PLA_WHITE":"/app/external-tools/bin/squashfs-root/resources/profiles/Snapmaker/filament/Snapmaker PLA @U1.json"}' +set_value PRINT_ORCA_HEIGHT_PROFILE_MAP '{"default":"/app/local-profiles/u1-compatible-generic-process.json"}' +set_value PRINT_ORCA_DEFAULT_TOOL_COMMAND T0 +set_value PRINT_ORCA_TOOL_COMMAND_MAP '{"PLA":"T0","PLA_WHITE":"T0"}' +set_value PRINT_ORCA_FIRST_LAYER_BED_TEMPERATURE_MAP '{"PLA":"65","PLA_WHITE":"65"}' +set_value PRINT_ORCA_BED_TEMPERATURE_MAP '{"PLA":"60","PLA_WHITE":"60"}' set_value OSS_PUBLIC_ENDPOINT "http://${public_host}:9000" set_value CORS_ALLOWED_ORIGINS "http://${public_host},http://${public_host}:8080,http://${public_host}:8081,http://localhost:8080,http://127.0.0.1:8080" diff --git a/scripts/prepare-u1-local-profile.sh b/scripts/prepare-u1-local-profile.sh new file mode 100755 index 0000000..1f0d0a9 --- /dev/null +++ b/scripts/prepare-u1-local-profile.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +runtime_directory="${1:-/srv/ai-soulmate/runtime/external-tools-production-20260416}" +profile_directory="${2:-/srv/ai-soulmate/runtime/u1-profiles}" +source_profile="$runtime_directory/bin/squashfs-root/resources/profiles/Snapmaker/process/0.20 Standard @Snapmaker (0.4 nozzle).json" +target_profile="$profile_directory/u1-compatible-generic-process.json" + +if ! command -v python3 >/dev/null 2>&1; then + printf 'Required command is unavailable: python3\n' >&2 + exit 1 +fi +if [[ ! -f "$source_profile" ]]; then + printf 'Generic Snapmaker process profile not found: %s\n' "$source_profile" >&2 + exit 1 +fi + +install -d -m 0750 "$profile_directory" +temporary_profile="$(mktemp "$profile_directory/.u1-compatible-generic-process.XXXXXX")" +trap 'rm -f "$temporary_profile"' EXIT + +python3 - "$source_profile" "$temporary_profile" <<'PY' +import json +import sys + +source_path, target_path = sys.argv[1:] +with open(source_path, encoding="utf-8") as source_file: + profile = json.load(source_file) + +if profile.get("type") != "process": + raise SystemExit("source profile is not a process profile") + +profile.pop("inherits", None) +profile["name"] = "0.20 Standard @Snapmaker U1 (local compatibility)" +profile["setting_id"] = "LOCAL_U1_COMPAT_GENERIC" +profile["compatible_printers"] = ["Snapmaker U1 (0.4 nozzle)"] +profile.pop("compatible_printers_condition", None) + +with open(target_path, "w", encoding="utf-8") as target_file: + json.dump(profile, target_file, ensure_ascii=False, indent=2) + target_file.write("\n") +PY + +chmod 0640 "$temporary_profile" +mv -f "$temporary_profile" "$target_profile" +trap - EXIT + +printf 'U1 local process profile prepared: %s\n' "$target_profile" +sha256sum "$target_profile"