Skip to content

Commit d4ead74

Browse files
sdharani91dharsrin
andauthored
Split code editor extension installation for different environments (#958)
Co-authored-by: Dharani Srinivasan <[email protected]>
1 parent 6fbb068 commit d4ead74

File tree

4 files changed

+63
-18
lines changed

4 files changed

+63
-18
lines changed

template/v2/Dockerfile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ RUN apt-get update && apt-get upgrade -y && \
8383
rm -rf q q.zip && \
8484
echo "source /usr/local/bin/_activate_current_env.sh" | tee --append /etc/profile && \
8585
# CodeEditor - create server, user data dirs
86-
mkdir -p /opt/amazon/sagemaker/sagemaker-code-editor-server-data /opt/amazon/sagemaker/sagemaker-code-editor-user-data \
87-
&& chown $MAMBA_USER:$MAMBA_USER /opt/amazon/sagemaker/sagemaker-code-editor-server-data /opt/amazon/sagemaker/sagemaker-code-editor-user-data && \
86+
mkdir -p /opt/amazon/sagemaker/sagemaker-code-editor-server-data /opt/amazon/sagemaker/sagemaker-ui-code-editor-server-data /opt/amazon/sagemaker/sagemaker-code-editor-user-data \
87+
&& chown $MAMBA_USER:$MAMBA_USER /opt/amazon/sagemaker/sagemaker-code-editor-server-data /opt/amazon/sagemaker/sagemaker-ui-code-editor-server-data /opt/amazon/sagemaker/sagemaker-code-editor-user-data && \
8888
# create dir to store user data files
8989
mkdir -p /opt/amazon/sagemaker/user-data \
9090
&& chown $MAMBA_USER:$MAMBA_USER /opt/amazon/sagemaker/user-data && \
@@ -94,11 +94,15 @@ COPY dirs/ ${DIRECTORY_TREE_STAGE_DIR}/
9494
RUN rsync -a ${DIRECTORY_TREE_STAGE_DIR}/ / && \
9595
rm -rf ${DIRECTORY_TREE_STAGE_DIR} && \
9696
# CodeEditor - download the extensions
97-
mkdir -p /etc/code-editor/extensions && \
97+
mkdir -p /etc/code-editor/extensions /etc/code-editor/extensions-sagemaker-ui && \
9898
while IFS= read -r url || [ -n "$url" ]; do \
9999
echo "Downloading extension from ${url}..." && \
100100
wget --no-check-certificate -P /etc/code-editor/extensions "${url}"; \
101101
done < /etc/code-editor/extensions.txt
102+
while IFS= read -r url || [ -n "$url" ]; do \
103+
echo "Downloading sagemaker-ui extension from ${url}..." && \
104+
wget --no-check-certificate -P /etc/code-editor/extensions-sagemaker-ui "${url}"; \
105+
done < /etc/code-editor/extensions-sagemaker-ui.txt
102106

103107
USER $MAMBA_USER
104108
COPY --chown=$MAMBA_USER:$MAMBA_USER $ENV_IN_FILENAME *.in /tmp/
@@ -147,9 +151,17 @@ RUN if [[ -z $ARG_BASED_ENV_IN_FILENAME ]] ; \
147151
echo "Installing extension ${ext}..."; \
148152
sagemaker-code-editor --install-extension "${ext}" --extensions-dir "${extensionloc}" --server-data-dir /opt/amazon/sagemaker/sagemaker-code-editor-server-data --user-data-dir /opt/amazon/sagemaker/sagemaker-code-editor-user-data; \
149153
done \
154+
# Install sagemaker-ui extensions
155+
&& extensionloc_ui=/opt/amazon/sagemaker/sagemaker-ui-code-editor-server-data/extensions && mkdir -p "${extensionloc_ui}" \
156+
&& for ext in /etc/code-editor/extensions-sagemaker-ui/*.vsix; do \
157+
echo "Installing sagemaker-ui extension ${ext}..."; \
158+
sagemaker-code-editor --install-extension "${ext}" --extensions-dir "${extensionloc_ui}" --server-data-dir /opt/amazon/sagemaker/sagemaker-ui-code-editor-server-data --user-data-dir /opt/amazon/sagemaker/sagemaker-code-editor-user-data; \
159+
done \
150160
# Copy the settings
151161
&& cp /etc/code-editor/code_editor_machine_settings.json /opt/amazon/sagemaker/sagemaker-code-editor-server-data/data/Machine/settings.json && \
152162
cp /etc/code-editor/code_editor_user_settings.json /opt/amazon/sagemaker/sagemaker-code-editor-server-data/data/User/settings.json && \
163+
cp /etc/code-editor/code_editor_machine_settings.json /opt/amazon/sagemaker/sagemaker-ui-code-editor-server-data/data/Machine/settings.json && \
164+
cp /etc/code-editor/code_editor_user_settings.json /opt/amazon/sagemaker/sagemaker-ui-code-editor-server-data/data/User/settings.json && \
153165
# Install glue kernels, and move to shared directory
154166
# Also patching base kernel so Studio background code doesn't start session silently
155167
install-glue-kernels && \
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
https://open-vsx.org/api/ms-toolsai/jupyter/2024.5.0/file/ms-toolsai.jupyter-2024.5.0.vsix
2+
https://open-vsx.org/api/ms-python/python/2023.20.0/file/ms-python.python-2023.20.0.vsix
3+
https://open-vsx.org/api/amazonwebservices/aws-toolkit-vscode/3.69.0/file/amazonwebservices.aws-toolkit-vscode-3.69.0.vsix
4+
https://open-vsx.org/api/amazonwebservices/amazon-q-vscode/1.97.0/file/amazonwebservices.amazon-q-vscode-1.97.0.vsix

template/v2/dirs/usr/local/bin/start-sagemaker-ui-code-editor

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
#!/bin/bash
22
set -e
33

4-
EFS_MOUNT_POINT="/opt/amazon/sagemaker"
5-
EBS_MOUNT_POINT="/home/sagemaker-user"
4+
export PERSISTENT_VOLUME_EXTENSIONS_DIR="/home/sagemaker-user/sagemaker-code-editor-server-data/extensions"
5+
export IMAGE_EXTENSIONS_DIR="/opt/amazon/sagemaker/sagemaker-ui-code-editor-server-data/extensions"
66

7-
persistent_settings_folder="${EBS_MOUNT_POINT}/sagemaker-code-editor-server-data"
8-
default_settings_folder="${EFS_MOUNT_POINT}/sagemaker-code-editor-server-data"
7+
CONTAINER_SAGEMAKER_METADATA_PATH="/opt/amazon/sagemaker"
8+
EBS_MOUNT_PATH="/home/sagemaker-user"
9+
10+
persistent_ebs_settings_folder="${EBS_MOUNT_PATH}/sagemaker-code-editor-server-data"
11+
container_settings_folder="${CONTAINER_SAGEMAKER_METADATA_PATH}/sagemaker-ui-code-editor-server-data"
912

1013
override_machine_settings() {
1114
# create a new settings file with preset defaults or merge the defaults into the existing settings file
1215
local settings_relative_path="data/Machine"
1316
local settings_file_path_suffix="${settings_relative_path}/settings.json"
14-
local persistent_machine_settings_file="${persistent_settings_folder}/${settings_file_path_suffix}"
15-
local default_machine_settings_file="${default_settings_folder}/${settings_file_path_suffix}"
17+
local persistent_machine_settings_file="${persistent_ebs_settings_folder}/${settings_file_path_suffix}"
18+
local default_machine_settings_file="${container_settings_folder}/${settings_file_path_suffix}"
1619

1720
if [ ! -f "$persistent_machine_settings_file" ]; then
1821
# copy settings file to EBS if it doesn't exist in EBS
19-
mkdir -p "${persistent_settings_folder}/${settings_relative_path}"
22+
mkdir -p "${persistent_ebs_settings_folder}/${settings_relative_path}"
2023
cp "$default_machine_settings_file" "$persistent_machine_settings_file"
2124
echo "Created persistent settings file with default settings at $persistent_machine_settings_file"
2225
else
@@ -29,19 +32,19 @@ override_machine_settings() {
2932
copy_user_settings() {
3033
local settings_relative_path="data/User"
3134
local settings_file_path_suffix="${settings_relative_path}/settings.json"
32-
local persistent_user_settings_file="${persistent_settings_folder}/${settings_file_path_suffix}"
33-
local default_user_settings_file="${default_settings_folder}/${settings_file_path_suffix}"
35+
local persistent_user_settings_file="${persistent_ebs_settings_folder}/${settings_file_path_suffix}"
36+
local default_user_settings_file="${container_settings_folder}/${settings_file_path_suffix}"
3437
if [ ! -f "$persistent_user_settings_file" ]; then
3538
# copy user settings file to EBS if it doesn't exist in EBS
36-
mkdir -p "${persistent_settings_folder}/${settings_relative_path}"
39+
mkdir -p "${persistent_ebs_settings_folder}/${settings_relative_path}"
3740
cp "$default_user_settings_file" "$persistent_user_settings_file"
3841
echo "Created persistent settings file with default settings at $persistent_user_settings_file"
3942
fi
4043
}
4144

4245
install_prepackaged_extensions() {
43-
local prepackaged_extensions_dir="${default_settings_folder}/extensions"
44-
local persistent_extensions_dir="${persistent_settings_folder}/extensions"
46+
local prepackaged_extensions_dir="${container_settings_folder}/extensions"
47+
local persistent_extensions_dir="${persistent_ebs_settings_folder}/extensions"
4548

4649
# if extensions directory doesn't exist then this is the first time opening the app
4750
if [ ! -d "${persistent_extensions_dir}" ]; then
@@ -95,8 +98,8 @@ if [ -n "$SAGEMAKER_APP_TYPE_LOWERCASE" ]; then
9598
sagemaker-code-editor --host 0.0.0.0 --port 8888 \
9699
--without-connection-token \
97100
--base-path "/$SAGEMAKER_APP_TYPE_LOWERCASE/default" \
98-
--server-data-dir $persistent_settings_folder \
99-
--extensions-dir ${persistent_settings_folder}/extensions \
101+
--server-data-dir $persistent_ebs_settings_folder \
102+
--extensions-dir ${persistent_ebs_settings_folder}/extensions \
100103
--user-data-dir /opt/amazon/sagemaker/sagemaker-code-editor-user-data
101104
else
102105
sagemaker-code-editor --host 0.0.0.0 --port 8888 \

test/test_artifacts/v2/scripts/run_sagemaker_code_editor_tests.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sagemaker-code-editor --version
77
echo "Verified that sagemaker-code-editor is installed"
88

99
# Verify that data dirs are created and have correct ownership
10-
data_dirs=("/opt/amazon/sagemaker/sagemaker-code-editor-server-data" "/opt/amazon/sagemaker/sagemaker-code-editor-user-data")
10+
data_dirs=("/opt/amazon/sagemaker/sagemaker-code-editor-server-data" "/opt/amazon/sagemaker/sagemaker-code-editor-user-data" "opt/amazon/sagemaker/sagemaker-ui-code-editor-server-data")
1111
data_dirs_owner="sagemaker-user"
1212

1313
for dir in "${data_dirs[@]}"; do
@@ -51,6 +51,32 @@ for extension in "${installed_extensions[@]}"; do
5151
done
5252
echo "Verified that all extension folders are present in $extensions_base_dir."
5353

54+
# Check that extensions are installed correctly for SMUS
55+
extensions_base_dir="/opt/amazon/sagemaker/sagemaker-ui-code-editor-server-data/extensions"
56+
if [[ ! -d $extensions_base_dir ]]; then
57+
echo "Extension base directory $extensions_base_dir does not exist."
58+
exit 1
59+
fi
60+
61+
installed_extensions=("ms-python.python" "ms-toolsai.jupyter" "amazonwebservices.aws-toolkit-vscode")
62+
for extension in "${installed_extensions[@]}"; do
63+
# In this pattern, we're looking for versioning to follow immediately after the extension name
64+
# For ex - ms-toolsai.jupyter-2023.9.100
65+
pattern="${extension}-[0-9]*"
66+
67+
# Use the find command to search for directories matching the current pattern
68+
found_dirs=$(find "$extensions_base_dir" -maxdepth 1 -type d -name "$pattern")
69+
70+
if [[ -z $found_dirs ]]; then
71+
echo "Directory matching pattern '$pattern' does not exist in $extensions_base_dir."
72+
exit 1
73+
else
74+
echo "Directory exists for pattern '$pattern':"
75+
echo "$found_dirs"
76+
fi
77+
done
78+
echo "Verified that all extension folders are present in $extensions_base_dir."
79+
5480
# Check that settings file is copied
5581
MACHINE_SETTINGS_FILE_PATH="/opt/amazon/sagemaker/sagemaker-code-editor-server-data/data/Machine/settings.json"
5682
if [ ! -f "$MACHINE_SETTINGS_FILE_PATH" ]; then

0 commit comments

Comments
 (0)