From 1fb7f571f21326f557fa04743d84c43d7336e2b4 Mon Sep 17 00:00:00 2001 From: atheo89 Date: Wed, 12 Jun 2024 14:30:20 +0200 Subject: [PATCH] Add launch.json configuration on .vscode directory together with settings.json file --- codeserver/ubi9-python-3.9/Dockerfile | 3 ++ codeserver/ubi9-python-3.9/run-code-server.sh | 36 ++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/codeserver/ubi9-python-3.9/Dockerfile b/codeserver/ubi9-python-3.9/Dockerfile index a62c7dded..42eda0a74 100644 --- a/codeserver/ubi9-python-3.9/Dockerfile +++ b/codeserver/ubi9-python-3.9/Dockerfile @@ -44,6 +44,7 @@ COPY --chown=1001:0 utils utils/ # Create and intall the extensions though build-time on a temporary directory. Later this directory will copied on the `/opt/app-root/src/.local/share/code-server/extensions` via run-code-server.sh file when it starts up. RUN mkdir -p /opt/app-root/extensions-temp && \ code-server --install-extension /opt/app-root/bin/utils/ms-python.python-2024.2.1.vsix --extensions-dir /opt/app-root/extensions-temp && \ + code-server --install-extension /opt/app-root/bin/utils/ms-python.debugpy-2024.2.0@linux-x64.vsix --extensions-dir /opt/app-root/extensions-temp && \ code-server --install-extension /opt/app-root/bin/utils/ms-toolsai.jupyter-2023.9.100.vsix --extensions-dir /opt/app-root/extensions-temp # Install NGINX to proxy code-server and pass probes check @@ -113,6 +114,8 @@ COPY --chown=1001:0 run-code-server.sh run-nginx.sh ./ ENV SHELL /bin/bash +ENV PYTHONPATH=/opt/app-root/bin/python3 + WORKDIR /opt/app-root/src USER 1001 diff --git a/codeserver/ubi9-python-3.9/run-code-server.sh b/codeserver/ubi9-python-3.9/run-code-server.sh index 9b4e3acf3..5a606ff4b 100755 --- a/codeserver/ubi9-python-3.9/run-code-server.sh +++ b/codeserver/ubi9-python-3.9/run-code-server.sh @@ -16,29 +16,55 @@ fi # Initilize access logs for culling echo '[{"id":"code-server","name":"code-server","last_activity":"'$(date -Iseconds)'","execution_state":"running","connections":1}]' > /var/log/nginx/codeserver.access.log -# Directory for settings file -user_dir="/opt/app-root/src/.local/share/code-server/User/" +# Add "/opt/app-root/src/.vscode/" directory to set default interpreter also for Run & Debug +user_dir="/opt/app-root/src/.vscode/" settings_filepath="${user_dir}settings.json" +launch_filepath="${user_dir}launch.json" + +json_launch_settings='{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "python": "/opt/app-root/bin/python3" + } + ] +}' json_settings='{ "python.defaultInterpreterPath": "/opt/app-root/bin/python3" -}' + }' # Check if User directory exists if [ ! -d "$user_dir" ]; then echo "Debug: User directory not found, creating '$user_dir'..." mkdir -p "$user_dir" + echo "$json_launch_settings" > "$launch_filepath" + echo "Debug: '$launch_filepath' file created." echo "$json_settings" > "$settings_filepath" echo "Debug: '$settings_filepath' file created." else echo "Debug: User directory already exists." - # Add settings.json if not present - if [ ! -f "$settings_filepath" ]; then + # Add settings.json and launch.json if not present + if [ ! -f "$launch_filepath" ]; then + echo "Debug: '$launch_filepath' file not found, creating..." + echo "$json_launch_settings" > "$launch_filepath" + echo "Debug: '$launch_filepath' file created." + elif [ ! -f "$settings_filepath" ]; then echo "Debug: '$settings_filepath' file not found, creating..." echo "$json_settings" > "$settings_filepath" echo "Debug: '$settings_filepath' file created." else + echo "Debug: '$launch_filepath' file already exists." echo "Debug: '$settings_filepath' file already exists." + fi fi