feat: refactor tool_code.py to use sys.executable and update Dockerfile for diskcache2 installation

This commit is contained in:
CaptainB 2025-06-24 13:35:02 +08:00
parent 4a6d8c9067
commit 3a91562289
2 changed files with 7 additions and 7 deletions

View File

@ -11,7 +11,7 @@ from diskcache import Cache
from maxkb.const import BASE_DIR
from maxkb.const import PROJECT_DIR
python_directory = '/opt/maxkb-app/sandbox/py3/bin/python'
python_directory = sys.executable
class ToolExecutor:
@ -45,6 +45,7 @@ try:
import sys
path_to_exclude = '/opt/py3/lib/python3.11/site-packages'
sys.path = [p for p in sys.path if p != path_to_exclude]
sys.path.append('/opt/maxkb-app/sandbox/python-packages')
env = dict(os.environ)
for key in list(env.keys()):
if key in os.environ and (key.startswith('MAXKB') or key.startswith('POSTGRES') or key.startswith('PG')):
@ -93,4 +94,4 @@ except Exception as e:
@staticmethod
def _exec(_code):
return subprocess.run([sys.executable, '-c', _code], text=True, capture_output=True)
return subprocess.run([python_directory, '-c', _code], text=True, capture_output=True)

View File

@ -28,7 +28,9 @@ RUN python3 -m venv /opt/py3 && \
. /opt/py3/bin/activate && \
if [ "$(uname -m)" = "x86_64" ]; then sed -i 's/^torch.*/torch = {version = "2.7.1+cpu", source = "pytorch"}/g' pyproject.toml; fi && \
poetry install && \
export MAXKB_CONFIG_TYPE=ENV && python3 /opt/maxkb-app/apps/manage.py compilemessages
export MAXKB_CONFIG_TYPE=ENV && python3 /opt/maxkb-app/apps/manage.py compilemessages && \
export PIP_TARGET=/opt/maxkb-app/sandbox/python-packages && \
pip install diskcache2 requests pymysql psycopg2-binary
FROM ghcr.io/1panel-dev/maxkb-base:python3.11-pg17.4
ARG DOCKER_IMAGE_TAG=dev \
@ -75,10 +77,7 @@ RUN chmod 755 /opt/maxkb-app/installer/*.sh && \
useradd --no-create-home --home /opt/maxkb-app/sandbox sandbox -g root && \
chown -R sandbox:root /opt/maxkb-app/sandbox && \
chmod g-x /usr/local/bin/* /usr/bin/* /bin/* /usr/sbin/* /sbin/* /usr/lib/postgresql/17/bin/* && \
chmod g+x /usr/local/bin/python* && \
python3 -m venv /opt/maxkb-app/sandbox/py3 && \
. /opt/maxkb-app/sandbox/py3/bin/activate && \
/opt/maxkb-app/sandbox/py3/bin/pip install diskcache2
chmod g+x /usr/local/bin/python*
EXPOSE 8080
VOLUME /opt/maxkb