Skip to content

Commit 3a91562

Browse files
committed
feat: refactor tool_code.py to use sys.executable and update Dockerfile for diskcache2 installation
1 parent 4a6d8c9 commit 3a91562

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

apps/common/utils/tool_code.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from maxkb.const import BASE_DIR
1212
from maxkb.const import PROJECT_DIR
1313

14-
python_directory = '/opt/maxkb-app/sandbox/py3/bin/python'
14+
python_directory = sys.executable
1515

1616

1717
class ToolExecutor:
@@ -45,6 +45,7 @@ def exec_code(self, code_str, keywords):
4545
import sys
4646
path_to_exclude = '/opt/py3/lib/python3.11/site-packages'
4747
sys.path = [p for p in sys.path if p != path_to_exclude]
48+
sys.path.append('/opt/maxkb-app/sandbox/python-packages')
4849
env = dict(os.environ)
4950
for key in list(env.keys()):
5051
if key in os.environ and (key.startswith('MAXKB') or key.startswith('POSTGRES') or key.startswith('PG')):
@@ -93,4 +94,4 @@ def _exec_sandbox(self, _code, _id):
9394

9495
@staticmethod
9596
def _exec(_code):
96-
return subprocess.run([sys.executable, '-c', _code], text=True, capture_output=True)
97+
return subprocess.run([python_directory, '-c', _code], text=True, capture_output=True)

installer/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ RUN python3 -m venv /opt/py3 && \
2828
. /opt/py3/bin/activate && \
2929
if [ "$(uname -m)" = "x86_64" ]; then sed -i 's/^torch.*/torch = {version = "2.7.1+cpu", source = "pytorch"}/g' pyproject.toml; fi && \
3030
poetry install && \
31-
export MAXKB_CONFIG_TYPE=ENV && python3 /opt/maxkb-app/apps/manage.py compilemessages
31+
export MAXKB_CONFIG_TYPE=ENV && python3 /opt/maxkb-app/apps/manage.py compilemessages && \
32+
export PIP_TARGET=/opt/maxkb-app/sandbox/python-packages && \
33+
pip install diskcache2 requests pymysql psycopg2-binary
3234

3335
FROM ghcr.io/1panel-dev/maxkb-base:python3.11-pg17.4
3436
ARG DOCKER_IMAGE_TAG=dev \
@@ -75,10 +77,7 @@ RUN chmod 755 /opt/maxkb-app/installer/*.sh && \
7577
useradd --no-create-home --home /opt/maxkb-app/sandbox sandbox -g root && \
7678
chown -R sandbox:root /opt/maxkb-app/sandbox && \
7779
chmod g-x /usr/local/bin/* /usr/bin/* /bin/* /usr/sbin/* /sbin/* /usr/lib/postgresql/17/bin/* && \
78-
chmod g+x /usr/local/bin/python* && \
79-
python3 -m venv /opt/maxkb-app/sandbox/py3 && \
80-
. /opt/maxkb-app/sandbox/py3/bin/activate && \
81-
/opt/maxkb-app/sandbox/py3/bin/pip install diskcache2
80+
chmod g+x /usr/local/bin/python*
8281

8382
EXPOSE 8080
8483
VOLUME /opt/maxkb

0 commit comments

Comments
 (0)