1
1
#! /bin/bash
2
2
set -e
3
3
4
- EFS_MOUNT_POINT =" /opt/amazon/sagemaker"
4
+ SERVICE_DIRECTORY =" /opt/amazon/sagemaker"
5
5
EBS_MOUNT_POINT=" /home/sagemaker-user"
6
6
7
7
persistent_settings_folder=" ${EBS_MOUNT_POINT} /sagemaker-code-editor-server-data"
8
- default_settings_folder=" ${EFS_MOUNT_POINT } /sagemaker-code-editor-server-data"
8
+ default_settings_folder=" ${SERVICE_DIRECTORY } /sagemaker-code-editor-server-data"
9
9
10
10
override_machine_settings () {
11
11
# create a new settings file with preset defaults or merge the defaults into the existing settings file
@@ -39,6 +39,27 @@ copy_user_settings() {
39
39
fi
40
40
}
41
41
42
+ merge_prepackaged_extensions () {
43
+ local extensions_metadata_relative_path=" /extensions"
44
+ local default_extensions_metadata_file=" ${default_settings_folder} /${extensions_metadata_relative_path} /extensions.json"
45
+ local persistent_extensions_metadata_file=" ${persistent_settings_folder} /${extensions_metadata_relative_path} /extensions.json"
46
+ local obsolete_file=" ${persistent_settings_folder} /${extensions_metadata_relative_path} /.obsolete"
47
+ if [ ! -f " $persistent_extensions_metadata_file " ]; then
48
+ # copy settings file to EBS if it doesn't exist in EBS
49
+ mkdir -p " ${persistent_settings_folder} /${extensions_metadata_relative_path} "
50
+ echo " []" > $persistent_extensions_metadata_file
51
+ echo " Created persistent extensions metadata file with default settings at $persistent_extensions_metadata_file "
52
+ else
53
+ # if it does exist then merge settings
54
+ echo " File already exists: ${persistent_extensions_metadata_file} . Overwriting extensions with pre-packaged extensions."
55
+ fi
56
+
57
+ if [ -f " $obsolete_file " ]; then
58
+ rm $obsolete_file
59
+ fi
60
+ python3 /usr/local/bin/merge-extensions-util.py " $persistent_extensions_metadata_file " " $default_extensions_metadata_file "
61
+ }
62
+
42
63
eval " $( micromamba shell hook --shell=bash) "
43
64
44
65
# Activate conda environment 'base', which is the default environment for sagemaker-distribution
@@ -49,17 +70,18 @@ if [ -n "$SAGEMAKER_APP_TYPE_LOWERCASE" ]; then
49
70
# SAGEMAKER_APP_TYPE is set, indicating the server is running within a SageMaker app.
50
71
override_machine_settings
51
72
copy_user_settings
73
+ merge_prepackaged_extensions
52
74
# Configure the base url to be `/<app-type-in-lower-case>/default`.
53
75
sagemaker-code-editor --host 0.0.0.0 --port 8888 \
54
76
--without-connection-token \
55
77
--base-path " /$SAGEMAKER_APP_TYPE_LOWERCASE /default" \
56
78
--server-data-dir $persistent_settings_folder \
57
- --extensions-dir /opt/amazon/sagemaker/sagemaker-code-editor-server-data /extensions \
79
+ --extensions-dir $persistent_settings_folder /extensions \
58
80
--user-data-dir /opt/amazon/sagemaker/sagemaker-code-editor-user-data
59
81
else
60
82
sagemaker-code-editor --host 0.0.0.0 --port 8888 \
61
83
--without-connection-token \
62
84
--server-data-dir /opt/amazon/sagemaker/sagemaker-code-editor-server-data \
63
85
--extension-dir /opt/amazon/sagemaker/sagemaker-code-editor-server-data/extensions \
64
86
--user-data-dir /opt/amazon/sagemaker/sagemaker-code-editor-user-data
65
- fi
87
+ fi
0 commit comments