Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. # Force using Bash to ensure the source command is available
  17. SHELL := /bin/bash
  18. # Environment variable definitions
  19. VENV := .venv
  20. PYTHON := $(VENV)/bin/python
  21. UV := uv
  22. ACTIVATE_SCRIPT := $(VENV)/bin/activate
  23. SYS_PYTHON := python3
  24. PYTHONPATH := $(shell pwd)
  25. .PHONY: all setup ensure_env ensure_uv start stop restart build clean test logs
  26. all: setup start
  27. # 🌱 Initialize environment + install dependencies
  28. setup: ensure_env ensure_uv
  29. @echo "📦 Installing dependencies with uv..."
  30. @$(UV) sync --python 3.11
  31. source $(ACTIVATE_SCRIPT) && \
  32. export PYTHONPATH=$(PYTHONPATH)
  33. @$(UV) pip install -r executor_manager/requirements.txt
  34. @echo "✅ Setup complete."
  35. # 🔑 Ensure .env exists (copy from .env.example on first run)
  36. ensure_env:
  37. @if [ ! -f ".env" ]; then \
  38. if [ -f ".env.example" ]; then \
  39. echo "📝 Creating .env from .env.example..."; \
  40. cp .env.example .env; \
  41. else \
  42. echo "⚠️ Warning: .env.example not found, creating empty .env"; \
  43. touch .env; \
  44. fi; \
  45. else \
  46. echo "✅ .env already exists."; \
  47. fi
  48. # 🔧 Ensure uv is executable (install using system Python)
  49. ensure_uv:
  50. @if ! command -v $(UV) >/dev/null 2>&1; then \
  51. echo "🛠️ Installing uv using system Python..."; \
  52. $(SYS_PYTHON) -m pip install -q --upgrade pip; \
  53. $(SYS_PYTHON) -m pip install -q uv || (echo "⚠️ uv install failed, check manually" && exit 1); \
  54. fi
  55. # 🐳 Service control (using safer variable loading)
  56. start:
  57. @echo "🚀 Starting services..."
  58. source $(ACTIVATE_SCRIPT) && \
  59. export PYTHONPATH=$(PYTHONPATH) && \
  60. [ -f .env ] && source .env || true && \
  61. bash scripts/start.sh
  62. stop:
  63. @echo "🛑 Stopping services..."
  64. source $(ACTIVATE_SCRIPT) && \
  65. bash scripts/stop.sh
  66. restart: stop start
  67. @echo "🔁 Restarting services..."
  68. build:
  69. @echo "🔧 Building base sandbox images..."
  70. @if [ -f .env ]; then \
  71. source .env && \
  72. echo "🐍 Building base sandbox image for Python ($$SANDBOX_BASE_PYTHON_IMAGE)..." && \
  73. docker build -t "$$SANDBOX_BASE_PYTHON_IMAGE" ./sandbox_base_image/python && \
  74. echo "⬢ Building base sandbox image for Nodejs ($$SANDBOX_BASE_NODEJS_IMAGE)..." && \
  75. docker build -t "$$SANDBOX_BASE_NODEJS_IMAGE" ./sandbox_base_image/nodejs; \
  76. else \
  77. echo "⚠️ .env file not found, skipping build."; \
  78. fi
  79. test:
  80. @echo "🧪 Running sandbox security tests..."
  81. source $(ACTIVATE_SCRIPT) && \
  82. export PYTHONPATH=$(PYTHONPATH) && \
  83. $(PYTHON) tests/sandbox_security_tests_full.py
  84. logs:
  85. @echo "📋 Showing logs from api-server and executor-manager..."
  86. docker compose logs -f
  87. # 🧹 Clean all containers and volumes
  88. clean:
  89. @echo "🧹 Cleaning all containers and volumes..."
  90. @docker compose down -v || true
  91. @if [ -f .env ]; then \
  92. source .env && \
  93. for i in $$(seq 0 $$((SANDBOX_EXECUTOR_MANAGER_POOL_SIZE - 1))); do \
  94. echo "🧹 Deleting sandbox_python_$$i..." && \
  95. docker rm -f sandbox_python_$$i 2>/dev/null || true && \
  96. echo "🧹 Deleting sandbox_nodejs_$$i..." && \
  97. docker rm -f sandbox_nodejs_$$i 2>/dev/null || true; \
  98. done; \
  99. else \
  100. echo "⚠️ .env not found, skipping container cleanup"; \
  101. fi