Skip to content

Commit fed215c

Browse files
committed
update
1 parent 2123aaf commit fed215c

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

docker.nix

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,31 @@ def timeout_handler(signum, frame):
172172
signal.signal(signal.SIGALRM, timeout_handler)
173173
signal.alarm(200) # 200 second timeout
174174
175-
# Execute user code
176-
try:
177-
exec(open('$1').read()) if len(sys.argv) > 1 else exec(sys.stdin.read())
178-
except Exception as e:
179-
print(f'Error: {e}', file=sys.stderr)
180-
sys.exit(1)
175+
# Handle different argument patterns
176+
if len(sys.argv) == 1:
177+
# No arguments, read from stdin
178+
try:
179+
exec(sys.stdin.read())
180+
except EOFError:
181+
# No input, start interactive mode
182+
import code
183+
code.interact()
184+
elif len(sys.argv) == 2 and sys.argv[1] == '--version':
185+
# Handle --version flag
186+
print(f'Python {sys.version.split()[0]}')
187+
elif len(sys.argv) == 2 and sys.argv[1].startswith('-'):
188+
# Handle other flags like -c, -m, etc.
189+
exec('${pythonWithPackages}/bin/python3.12 "$@"')
190+
else:
191+
# Execute file or code
192+
try:
193+
if len(sys.argv) > 1 and not sys.argv[1].startswith('-'):
194+
exec(open(sys.argv[1]).read())
195+
else:
196+
exec('${pythonWithPackages}/bin/python3.12 "$@"')
197+
except Exception as e:
198+
print(f'Error: {e}', file=sys.stderr)
199+
sys.exit(1)
181200
finally:
182201
signal.alarm(0) # Cancel timeout
183202
" "$@"
@@ -321,6 +340,9 @@ finally:
321340
chmod +x $out/setup-gurobi.sh
322341
chmod +x $out/verify-gurobi.sh
323342
343+
# Create python3 symlink
344+
ln -s ${pythonWithPackages}/bin/python3.12 $out/bin/python3
345+
324346
# Create user and group files
325347
cat > $out/etc/passwd.d/python-user << 'EOF'
326348
python-user:x:1000:1000:Python User:/home/python-user:/bin/bash
@@ -409,12 +431,12 @@ in
409431
"LOGNAME=python-user"
410432
"MAIL="
411433
];
412-
# Use secure Python interpreter with user setup
413-
Cmd = [ "bash" "-c" "cat /etc/passwd.d/python-user >> /etc/passwd && cat /etc/group.d/python-user >> /etc/group && cat /etc/shadow.d/python-user >> /etc/shadow && python -c 'print(\"Python secure environment ready\")'" ];
434+
# Use secure Python interpreter
435+
Cmd = [ "${pythonWithPackages}/bin/python3.12" "-c" "print('Python secure environment ready')" ];
414436
# Set security parameters - use non-root user
415437
User = "1000:1000";
416438
# Additional security settings
417-
ReadOnlyRootfs = true;
439+
ReadOnlyRootfs = false; # 暂时设为 false 以确保启动成功
418440
# Disable privileged mode
419441
Privileged = false;
420442
# Set resource limits

0 commit comments

Comments
 (0)