You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. source $(ACTIVATE_SCRIPT) && \
  31. export PYTHONPATH=$(PYTHONPATH)
  32. @$(UV) pip install -r executor_manager/requirements.txt
  33. @echo "✅ Setup complete."
  34. # 🔑 Ensure .env exists (copy from .env.example on first run)
  35. ensure_env:
  36. @if [ ! -f ".env" ]; then \
  37. if [ -f ".env.example" ]; then \
  38. echo "📝 Creating .env from .env.example..."; \
  39. cp .env.example .env; \
  40. else \
  41. echo "⚠️ Warning: .env.example not found, creating empty .env"; \
  42. touch .env; \
  43. fi; \
  44. else \
  45. echo "✅ .env already exists."; \
  46. fi
  47. # 🔧 Ensure uv is executable (install using system Python)
  48. ensure_uv:
  49. @if ! command -v $(UV) >/dev/null 2>&1; then \
  50. echo "🛠️ Installing uv using system Python..."; \
  51. $(SYS_PYTHON) -m pip install -q --upgrade pip; \
  52. $(SYS_PYTHON) -m pip install -q uv || (echo "⚠️ uv install failed, check manually" && exit 1); \
  53. fi
  54. # 🐳 Service control (using safer variable loading)
  55. start:
  56. @echo "🚀 Starting services..."
  57. source $(ACTIVATE_SCRIPT) && \
  58. export PYTHONPATH=$(PYTHONPATH) && \
  59. [ -f .env ] && source .env || true && \
  60. bash scripts/start.sh
  61. stop:
  62. @echo "🛑 Stopping services..."
  63. source $(ACTIVATE_SCRIPT) && \
  64. bash scripts/stop.sh
  65. restart: stop start
  66. @echo "🔁 Restarting services..."
  67. build:
  68. @echo "🔧 Building base sandbox images..."
  69. @if [ -f .env ]; then \
  70. source .env && \
  71. echo "🐍 Building base sandbox image for Python ($$SANDBOX_BASE_PYTHON_IMAGE)..." && \
  72. docker build -t "$$SANDBOX_BASE_PYTHON_IMAGE" ./sandbox_base_image/python && \
  73. echo "⬢ Building base sandbox image for Nodejs ($$SANDBOX_BASE_NODEJS_IMAGE)..." && \
  74. docker build -t "$$SANDBOX_BASE_NODEJS_IMAGE" ./sandbox_base_image/nodejs; \
  75. else \
  76. echo "⚠️ .env file not found, skipping build."; \
  77. fi
  78. test:
  79. @echo "🧪 Running sandbox security tests..."
  80. source $(ACTIVATE_SCRIPT) && \
  81. export PYTHONPATH=$(PYTHONPATH) && \
  82. $(PYTHON) tests/sandbox_security_tests_full.py
  83. logs:
  84. @echo "📋 Showing logs from api-server and executor-manager..."
  85. docker compose logs -f
  86. # 🧹 Clean all containers and volumes
  87. clean:
  88. @echo "🧹 Cleaning all containers and volumes..."
  89. @docker compose down -v || true
  90. @if [ -f .env ]; then \
  91. source .env && \
  92. for i in $$(seq 0 $$((SANDBOX_EXECUTOR_MANAGER_POOL_SIZE - 1))); do \
  93. echo "🧹 Deleting sandbox_python_$$i..." && \
  94. docker rm -f sandbox_python_$$i 2>/dev/null || true && \
  95. echo "🧹 Deleting sandbox_nodejs_$$i..." && \
  96. docker rm -f sandbox_nodejs_$$i 2>/dev/null || true; \
  97. done; \
  98. else \
  99. echo "⚠️ .env not found, skipping container cleanup"; \
  100. fi