Skip to content

Commit

Permalink
Merge pull request #556 from atheo89/python-path
Browse files Browse the repository at this point in the history
Fix issue with Run and Debug on code-server workbench
  • Loading branch information
openshift-merge-bot[bot] committed Jun 13, 2024
2 parents 4d4841f + 1fb7f57 commit 2c36c11
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
3 changes: 3 additions & 0 deletions codeserver/ubi9-python-3.9/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected] --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
Expand Down Expand Up @@ -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
Expand Down
36 changes: 31 additions & 5 deletions codeserver/ubi9-python-3.9/run-code-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2c36c11

Please sign in to comment.