diff --git a/Dockerfile b/Dockerfile index fe5b326..5c0e1f5 100755 --- a/Dockerfile +++ b/Dockerfile @@ -16,15 +16,39 @@ RUN apt-get update && \ cmake \ && rm -rf /var/lib/apt/lists/* -# Обновление pip и установка setuptools/wheel +WORKDIR /app + +# Кэшируем установку зависимостей Python +COPY requirements.txt . RUN pip install --upgrade pip && \ - pip install setuptools wheel + pip install setuptools wheel \ + pip install --no-cache-dir -r requirements.txt -# Проверка версии Python и pip -RUN python --version && pip --version +# Сборка RKLLM runtime +RUN git clone --depth 1 https://git.home/drholy/ezrknn-llm /tmp/rkllm-build && \ + cp -r /tmp/rkllm-build/rkllm-runtime/runtime/Linux/librkllm_api/aarch64/* /usr/lib && \ + cp -r /tmp/rkllm-build/rkllm-runtime/runtime/Linux/librkllm_api/include/* /usr/local/include && \ + cd /tmp/rkllm-build/rkllm-runtime/examples/rkllm_api_demo && \ + bash build-linux.sh && \ + cp ./build/build_linux_aarch64_Release/llm_demo /usr/bin/rkllm && \ + # Очистка временных файлов сборки + ldconfig && \ + rm -rf /tmp/rkllm-build && \ + apt-get purge -y git cmake build-essential libssl-dev && \ + apt-get autoremove -y && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* -RUN pip install --no-cache-dir -r requirements.txt +# Копируем приложение (исключая кэш и модели) +COPY . . -# Очистка кэша -RUN apt-get clean && \ - rm -rf /tmp/* /var/tmp/* +# Исключаем модели из образа — монтируем как volume при запуске +RUN rm -rf /app/models/* 2>/dev/null || true && \ + find /app -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true && \ + chmod +x /app/entrypoint.sh + +# Порт Gradio по умолчанию +EXPOSE 8080 + +WORKDIR /app +ENTRYPOINT ["/app/entrypoint.sh"] \ No newline at end of file diff --git a/app/entrypoint.sh b/app/entrypoint.sh index 7216a58..d59e142 100755 --- a/app/entrypoint.sh +++ b/app/entrypoint.sh @@ -1,34 +1,18 @@ #!/bin/bash -message_print() { - echo - echo "#########################################" - echo $1 - echo "#########################################" - echo -} +set -e # Автоматический выход при ошибке -cd / +echo +echo "#########################################" +echo "Starting RKLLM Gradio Server" +echo "#########################################" +echo -message_print "Changing to repository..." -git clone https://git.home/drholy/ezrknn-llm -cd ezrknn-llm/ -cp ./rkllm-runtime/runtime/Linux/librkllm_api/aarch64/* /usr/lib -cp ./rkllm-runtime/runtime/Linux/librkllm_api/include/* /usr/local/include +# Проверка наличия моделей (монтируются через volume) +if [ ! -d "/app/models" ] || [ -z "$(ls -A /app/models 2>/dev/null)" ]; then + echo "⚠️ WARNING: Models directory is empty!" + echo " Mount models volume: -v ./models:/app/models" + sleep 5 +fi -message_print "Compiling LLM runtime for Linux..." -cd ./rkllm-runtime/examples/rkllm_api_demo/ -bash build-linux.sh - -message_print "Moving rkllm to /usr/bin..." -cp ./build/build_linux_aarch64_Release/llm_demo /usr/bin/rkllm -echo "* soft nofile 16384" >> /etc/security/limits.conf -echo "* hard nofile 1048576" >> /etc/security/limits.conf - -message_print "Increasing file limit for all users (needed for LLMs to run)..." -echo "root soft nofile 16384" >> /etc/security/limits.conf -echo "root hard nofile 1048576" >> /etc/security/limits.conf -message_print "Done installing ezrknn-llm!" - -message_print "Start Gradio server" -cd /app -python rkllm_server_gradio.py \ No newline at end of file +# Запуск сервера +exec python rkllm_server_gradio.py \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 9a0028f..a5db861 100755 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,16 +1,16 @@ services: rkllm: - build: - context: . - dockerfile: Dockerfile + build: . platform: linux/arm64/v8 container_name: rkllm restart: always privileged: true volumes: - - ./app:/app - - ./ezrknn-llm:/ezrknn-llm - entrypoint: ./app/entrypoint.sh + - ./models:/app/models:ro + ulimits: + nofile: + soft: 16384 + hard: 1048576 ports: - "8080:8080" networks: