Skip to content

Commit 01ed704

Browse files
committed
feat: update Dockerfile to set up Python virtual environment and adjust memory settings for builds
1 parent 05f1bbb commit 01ed704

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

apps/common/utils/tool_code.py

Lines changed: 5 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 = sys.executable
14+
python_directory = '/opt/maxkb-app/sandbox/py3/bin/python'
1515

1616

1717
class ToolExecutor:
@@ -42,6 +42,9 @@ def exec_code(self, code_str, keywords):
4242
_exec_code = f"""
4343
try:
4444
import os
45+
import sys
46+
path_to_exclude = '/opt/py3/lib/python3.11/site-packages'
47+
sys.path = [p for p in sys.path if p != path_to_exclude]
4548
env = dict(os.environ)
4649
for key in list(env.keys()):
4750
if key in os.environ and (key.startswith('MAXKB') or key.startswith('POSTGRES') or key.startswith('PG')):
@@ -90,4 +93,4 @@ def _exec_sandbox(self, _code, _id):
9093

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

installer/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ FROM node:18-alpine3.18 AS web-build
33
COPY ui ui
44
RUN cd ui && \
55
npm install && \
6-
npm run build-only && \
7-
npm run build-only-chat && \
6+
NODE_OPTIONS="--max-old-space-size=4096" npm run build-only && \
7+
NODE_OPTIONS="--max-old-space-size=4096" npm run build-only-chat && \
88
rm -rf ./node_modules
99
FROM ghcr.io/1panel-dev/maxkb-base:python3.11-pg17.4 AS stage-build
1010

@@ -75,7 +75,8 @@ RUN chmod 755 /opt/maxkb-app/installer/*.sh && \
7575
useradd --no-create-home --home /opt/maxkb-app/sandbox sandbox -g root && \
7676
chown -R sandbox:root /opt/maxkb-app/sandbox && \
7777
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*
78+
chmod g+x /usr/local/bin/python* && \
79+
python3 -m venv /opt/maxkb-app/sandbox/py3 && . /opt/maxkb-app/sandbox/py3/bin/activate && pip install diskcache2
7980

8081
EXPOSE 8080
8182
VOLUME /opt/maxkb

0 commit comments

Comments
 (0)