From 72ddd9822c3e92b22ab9abb70c78330ebc1b7528 Mon Sep 17 00:00:00 2001 From: kqjy Date: Fri, 3 Apr 2026 12:31:11 +0800 Subject: [PATCH] Add docker support for rust integration --- .dockerignore | 2 ++ Dockerfile | 11 ++++++++--- docker-entrypoint.sh | 5 +++-- myfsio_core/src/storage.rs | 2 +- run.py | 3 ++- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.dockerignore b/.dockerignore index ba575da..90ccb45 100644 --- a/.dockerignore +++ b/.dockerignore @@ -11,3 +11,5 @@ htmlcov logs data tmp +myfsio_core/target +myfsio-engine/target diff --git a/Dockerfile b/Dockerfile index a50ec8b..cdf37c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,7 @@ RUN apt-get update \ ENV PATH="/root/.cargo/bin:${PATH}" COPY requirements.txt ./ + RUN pip install --no-cache-dir -r requirements.txt COPY . . @@ -21,15 +22,18 @@ RUN pip install --no-cache-dir maturin \ && cd myfsio_core \ && maturin build --release \ && pip install target/wheels/*.whl \ + && cd ../myfsio-engine \ + && cargo build --release \ + && cp target/release/myfsio-server /usr/local/bin/myfsio-server \ && cd .. \ - && rm -rf myfsio_core/target \ + && rm -rf myfsio_core/target myfsio-engine/target \ && pip uninstall -y maturin \ && rustup self uninstall -y RUN chmod +x docker-entrypoint.sh RUN mkdir -p /app/data \ - && useradd -m -u 1000 myfsio \ + && useradd -m -u 1000 myfsio \ && chown -R myfsio:myfsio /app USER myfsio @@ -37,7 +41,8 @@ USER myfsio EXPOSE 5000 5100 ENV APP_HOST=0.0.0.0 \ FLASK_ENV=production \ - FLASK_DEBUG=0 + FLASK_DEBUG=0 \ + ENGINE=rust HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD python -c "import requests; requests.get('http://localhost:5000/myfsio/health', timeout=2)" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 08c3a3a..f61f458 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,5 +1,6 @@ #!/bin/sh set -e -# Run both services using the python runner in production mode -exec python run.py --prod +ENGINE="${ENGINE:-rust}" + +exec python run.py --prod --engine "$ENGINE" diff --git a/myfsio_core/src/storage.rs b/myfsio_core/src/storage.rs index cb80dae..76d7ade 100644 --- a/myfsio_core/src/storage.rs +++ b/myfsio_core/src/storage.rs @@ -125,7 +125,7 @@ pub fn delete_index_entry(py: Python<'_>, path: &str, entry_name: &str) -> PyRes fs::write(&path_owned, serialized) .map_err(|e| PyIOError::new_err(format!("Failed to write index: {}", e)))?; - Ok(false) + Ok(true) }) } diff --git a/run.py b/run.py index 51a7006..6aebccf 100644 --- a/run.py +++ b/run.py @@ -77,6 +77,7 @@ def _serve_granian(target: str, port: int, config: Optional[AppConfig] = None) - def _find_rust_binary() -> Optional[Path]: candidates = [ + Path("/usr/local/bin/myfsio-server"), Path(__file__).parent / "myfsio-engine" / "target" / "release" / "myfsio-server.exe", Path(__file__).parent / "myfsio-engine" / "target" / "release" / "myfsio-server", Path(__file__).parent / "myfsio-engine" / "target" / "debug" / "myfsio-server.exe", @@ -270,7 +271,7 @@ if __name__ == "__main__": parser.add_argument("--ui-port", type=int, default=5100) parser.add_argument("--prod", action="store_true", help="Run in production mode using Granian") parser.add_argument("--dev", action="store_true", help="Force development mode (Flask dev server)") - parser.add_argument("--engine", choices=["python", "rust"], default="python", help="API engine: python (Flask) or rust (myfsio-engine)") + parser.add_argument("--engine", choices=["python", "rust"], default=os.getenv("ENGINE", "python"), help="API engine: python (Flask) or rust (myfsio-engine)") parser.add_argument("--check-config", action="store_true", help="Validate configuration and exit") parser.add_argument("--show-config", action="store_true", help="Show configuration summary and exit") parser.add_argument("--reset-cred", action="store_true", help="Reset admin credentials and exit")