Skip to content

Commit 32b0bcc

Browse files
authored
Split code editor extension installation for different environments (#916)
1 parent d4ead74 commit 32b0bcc

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

template/v3/Dockerfile

Lines changed: 16 additions & 4 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}"; \
101-
done < /etc/code-editor/extensions.txt
101+
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.90.0/file/amazonwebservices.amazon-q-vscode-1.90.0.vsix

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

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

4-
EFS_MOUNT_POINT="/opt/amazon/sagemaker"
5-
EBS_MOUNT_POINT="/home/sagemaker-user"
4+
CONTAINER_SAGEMAKER_METADATA_PATH="/opt/amazon/sagemaker"
5+
EBS_MOUNT_PATH="/home/sagemaker-user"
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+
persistent_ebs_server_data_folder="${EBS_MOUNT_PATH}/sagemaker-code-editor-server-data"
8+
container_server_data_folder="${CONTAINER_SAGEMAKER_METADATA_PATH}/sagemaker-ui-code-editor-server-data"
99

1010
override_machine_settings() {
1111
# create a new settings file with preset defaults or merge the defaults into the existing settings file
1212
local settings_relative_path="data/Machine"
1313
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}"
14+
local persistent_machine_settings_file="${persistent_ebs_server_data_folder}/${settings_file_path_suffix}"
15+
local default_machine_settings_file="${container_server_data_folder}/${settings_file_path_suffix}"
1616

1717
if [ ! -f "$persistent_machine_settings_file" ]; then
1818
# copy settings file to EBS if it doesn't exist in EBS
19-
mkdir -p "${persistent_settings_folder}/${settings_relative_path}"
19+
mkdir -p "${persistent_ebs_server_data_folder}/${settings_relative_path}"
2020
cp "$default_machine_settings_file" "$persistent_machine_settings_file"
2121
echo "Created persistent settings file with default settings at $persistent_machine_settings_file"
2222
else
@@ -29,19 +29,19 @@ override_machine_settings() {
2929
copy_user_settings() {
3030
local settings_relative_path="data/User"
3131
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}"
32+
local persistent_user_settings_file="${persistent_ebs_server_data_folder}/${settings_file_path_suffix}"
33+
local default_user_settings_file="${container_server_data_folder}/${settings_file_path_suffix}"
3434
if [ ! -f "$persistent_user_settings_file" ]; then
3535
# copy user settings file to EBS if it doesn't exist in EBS
36-
mkdir -p "${persistent_settings_folder}/${settings_relative_path}"
36+
mkdir -p "${persistent_ebs_server_data_folder}/${settings_relative_path}"
3737
cp "$default_user_settings_file" "$persistent_user_settings_file"
3838
echo "Created persistent settings file with default settings at $persistent_user_settings_file"
3939
fi
4040
}
4141

4242
install_prepackaged_extensions() {
43-
local prepackaged_extensions_dir="${default_settings_folder}/extensions"
44-
local persistent_extensions_dir="${persistent_settings_folder}/extensions"
43+
local prepackaged_extensions_dir="${container_server_data_folder}/extensions"
44+
local persistent_extensions_dir="${persistent_ebs_server_data_folder}/extensions"
4545

4646
# if extensions directory doesn't exist then this is the first time opening the app
4747
if [ ! -d "${persistent_extensions_dir}" ]; then
@@ -95,8 +95,8 @@ if [ -n "$SAGEMAKER_APP_TYPE_LOWERCASE" ]; then
9595
sagemaker-code-editor --host 0.0.0.0 --port 8888 \
9696
--without-connection-token \
9797
--base-path "/$SAGEMAKER_APP_TYPE_LOWERCASE/default" \
98-
--server-data-dir $persistent_settings_folder \
99-
--extensions-dir ${persistent_settings_folder}/extensions \
98+
--server-data-dir $persistent_ebs_server_data_folder \
99+
--extensions-dir ${persistent_ebs_server_data_folder}/extensions \
100100
--user-data-dir /opt/amazon/sagemaker/sagemaker-code-editor-user-data
101101
else
102102
sagemaker-code-editor --host 0.0.0.0 --port 8888 \

0 commit comments

Comments
 (0)