Skip to content

Commit 626f62e

Browse files
Merge branch 'main' into release-3.1.1
2 parents 4651229 + badbc01 commit 626f62e

File tree

13 files changed

+152
-75
lines changed

13 files changed

+152
-75
lines changed

build_artifacts/v2/v2.7/v2.7.0/dirs/etc/sagemaker-ui/sagemaker_ui_post_startup.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ echo "Successfully removed the ~/.aws/config file"
8989
aws configure set credential_source EcsContainer
9090
echo "Successfully configured default profile"
9191

92+
# Add region configuration using REGION_NAME environment variable
93+
aws configure set region "${REGION_NAME}"
94+
echo "Successfully configured region to ${REGION_NAME}"
95+
9296
# add SparkMonitor and Connection Magic entrypoint
9397
NB_USER=sagemaker-user
9498

build_artifacts/v3/v3.2/v3.2.0/dirs/etc/sagemaker-ui/sagemaker_ui_post_startup.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ echo "Successfully removed the ~/.aws/config file"
6565
aws configure set credential_source EcsContainer
6666
echo "Successfully configured default profile"
6767

68+
# Add region configuration using REGION_NAME environment variable
69+
aws configure set region "${REGION_NAME}"
70+
echo "Successfully configured region to ${REGION_NAME}"
71+
6872
# add SparkMonitor and Connection Magic entrypoint
6973
NB_USER=sagemaker-user
7074

template/v2/dirs/etc/sagemaker-ui/libmgmt/install-lib.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22
set -eux
3-
3+
PROJECT_DIR=${SMUS_PROJECT_DIR:-"$HOME/src"}
44
# Check if the .libs.json file exists
5-
if [ -e $1/.libs.json ]; then
6-
lib_config_json=`cat $1/.libs.json`
5+
if [ -e $PROJECT_DIR/.libs.json ]; then
6+
lib_config_json=`cat $PROJECT_DIR/.libs.json`
77

88
apply_change_to_space=`echo $lib_config_json | jq -r '.ApplyChangeToSpace'`
99
# Extract conda channels from the config, add `-c ` before each channel and join the strings

template/v2/dirs/etc/sagemaker-ui/sagemaker_ui_post_startup.sh

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ echo "Successfully removed the ~/.aws/config file"
6262
aws configure set credential_source EcsContainer
6363
echo "Successfully configured default profile"
6464

65+
# Add region configuration using REGION_NAME environment variable
66+
aws configure set region "${REGION_NAME}"
67+
echo "Successfully configured region to ${REGION_NAME}"
68+
6569
# add SparkMonitor and Connection Magic entrypoint
6670
NB_USER=sagemaker-user
6771

@@ -134,8 +138,8 @@ case "$auth_mode" in
134138
;;
135139
esac
136140

137-
# Checks if the project is using Git or Non-Git storage
138-
is_non_git_storage() {
141+
# Checks if the project is using Git or S3 storage
142+
is_s3_storage() {
139143
getProjectDefaultEnvResponse=$(sagemaker-studio project get-project-default-environment --domain-id "$dataZoneDomainId" --project-id "$dataZoneProjectId" --profile DomainExecutionRoleCreds)
140144
gitConnectionArn=$(echo "$getProjectDefaultEnvResponse" | jq -r '.provisionedResources[] | select(.name=="gitConnectionArn") | .value')
141145
codeRepositoryName=$(echo "$getProjectDefaultEnvResponse" | jq -r '.provisionedResources[] | select(.name=="codeRepositoryName") | .value')
@@ -149,7 +153,26 @@ is_non_git_storage() {
149153

150154
echo "Checking Project Storage Type"
151155

152-
if ! is_non_git_storage; then
156+
# Execute once to store the result
157+
is_s3_storage
158+
is_s3_storage_flag=$? # 0 if S3 storage, 1 if Git
159+
160+
if [ "$is_s3_storage_flag" -eq 0 ]; then
161+
export SMUS_PROJECT_DIR="$HOME/shared"
162+
echo "Project is using S3 storage, project directory set to: $SMUS_PROJECT_DIR"
163+
else
164+
export SMUS_PROJECT_DIR="$HOME/src"
165+
echo "Project is using Git storage, project directory set to: $SMUS_PROJECT_DIR"
166+
fi
167+
168+
if grep -q "^SMUS_PROJECT_DIR=" ~/.bashrc; then
169+
echo "SMUS_PROJECT_DIR is defined in the env"
170+
else
171+
echo SMUS_PROJECT_DIR="$SMUS_PROJECT_DIR" >> ~/.bashrc
172+
echo readonly SMUS_PROJECT_DIR >> ~/.bashrc
173+
fi
174+
175+
if [ $is_s3_storage_flag -ne 0 ]; then
153176
# Creating a directory where the repository will be cloned
154177
mkdir -p "$HOME/src"
155178

@@ -190,7 +213,7 @@ if [ "${SAGEMAKER_APP_TYPE_LOWERCASE}" = "jupyterlab" ]; then
190213
trap 'write_status_to_file "error" "An unexpected error occurred. Please stop and restart your space to retry."' ERR
191214

192215
# Install conda and pip dependencies if lib mgmt config existing
193-
bash /etc/sagemaker-ui/libmgmt/install-lib.sh $HOME/src
216+
bash /etc/sagemaker-ui/libmgmt/install-lib.sh
194217

195218
# Install sm-spark-cli
196219
bash /etc/sagemaker-ui/workflows/sm-spark-cli-install.sh

template/v2/dirs/etc/sagemaker-ui/workflows/docker-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ x-airflow-common: &airflow-common
3939
DataZoneDomainRegion: ${DZ_DOMAIN_REGION}
4040
ProjectS3Path: ${DZ_PROJECT_S3PATH}
4141
volumes:
42-
- /home/sagemaker-user/${HOME_FOLDER_NAME}/workflows/dags:/usr/local/airflow/dags
42+
- /home/sagemaker-user/${PROJECT_DIR}/workflows/dags:/usr/local/airflow/dags
4343
- /home/sagemaker-user/.workflows_setup/plugins:/usr/local/airflow/plugins
4444
- /home/sagemaker-user/.workflows_setup/requirements:/usr/local/airflow/requirements
4545
- /home/sagemaker-user/.workflows_setup/startup:/usr/local/airflow/startup
46-
- /home/sagemaker-user/src:/home/sagemaker-user/src:rw
46+
- ${MOUNT_DIR}:/home/sagemaker-user/src:rw
4747
- /home/sagemaker-user/jobs:/home/sagemaker-user/jobs:rw
4848
depends_on: &airflow-common-depends-on
4949
postgres:

template/v2/dirs/etc/sagemaker-ui/workflows/start-workflows-container.sh

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
11
#!/bin/bash
22
set -eu
33

4+
# Get project directory based on storage type
5+
PROJECT_DIR=${SMUS_PROJECT_DIR:-"$HOME/src"}
6+
if [ -z "$SMUS_PROJECT_DIR" ]; then
7+
MOUNT_DIR=$PROJECT_DIR
8+
else
9+
MOUNT_DIR=$(readlink -f "$PROJECT_DIR") # get the symlink source
10+
fi
11+
12+
# Datazone project metadata
13+
RESOURCE_METADATA_FILE=/opt/ml/metadata/resource-metadata.json
14+
SM_DOMAIN_ID=$(jq -r ".DomainId" < $RESOURCE_METADATA_FILE)
15+
AWS_ACCOUNT_ID=$(jq -r '.ExecutionRoleArn | split(":")[4]' < $RESOURCE_METADATA_FILE)
16+
ECR_ACCOUNT_ID=058264401727
17+
DZ_DOMAIN_ID=$(jq -r '.AdditionalMetadata.DataZoneDomainId' < $RESOURCE_METADATA_FILE)
18+
DZ_PROJECT_ID=$(jq -r '.AdditionalMetadata.DataZoneProjectId' < $RESOURCE_METADATA_FILE)
19+
DZ_ENV_ID=$(jq -r '.AdditionalMetadata.DataZoneEnvironmentId' < $RESOURCE_METADATA_FILE)
20+
DZ_DOMAIN_REGION=$(jq -r '.AdditionalMetadata.DataZoneDomainRegion' < $RESOURCE_METADATA_FILE)
21+
DZ_ENDPOINT=$(jq -r '.AdditionalMetadata.DataZoneEndpoint' < $RESOURCE_METADATA_FILE)
22+
DZ_PROJECT_S3PATH=$(jq -r '.AdditionalMetadata.ProjectS3Path' < $RESOURCE_METADATA_FILE)
23+
24+
# Workflows paths in JL
25+
WORKFLOW_DAG_PATH="${PROJECT_DIR}/workflows/dags"
26+
WORKFLOW_CONFIG_PATH="${PROJECT_DIR}/workflows/config"
27+
WORKFLOW_DB_DATA_PATH="$HOME/.workflows_setup/db-data"
28+
WORKFLOW_REQUIREMENTS_PATH="$HOME/.workflows_setup/requirements/"
29+
WORKFLOW_PLUGINS_PATH="$HOME/.workflows_setup/plugins"
30+
WORKFLOW_STARTUP_PATH="$HOME/.workflows_setup/startup/"
31+
WORKFLOW_ARTIFACTS_SOURCE_DIR="/etc/sagemaker-ui/workflows"
32+
WORKFLOW_PLUGINS_SOURCE_PATH="${WORKFLOW_ARTIFACTS_SOURCE_DIR}/plugins/*.whl"
33+
WORKFLOW_REQUIREMENTS_SOURCE_PATH="${WORKFLOW_ARTIFACTS_SOURCE_DIR}/requirements/requirements.txt"
34+
WORKFLOW_AIRFLOW_REQUIREMENTS_SOURCE_PATH="/etc/sagemaker-ui/workflows/requirements/requirements.txt"
35+
WORKFLOW_OUTPUT_PATH="$HOME/jobs"
36+
USER_REQUIREMENTS_FILE="${WORKFLOW_CONFIG_PATH}/requirements.txt"
37+
USER_PLUGINS_FOLDER="${WORKFLOW_CONFIG_PATH}/plugins"
38+
USER_STARTUP_FILE="${WORKFLOW_CONFIG_PATH}/startup.sh"
39+
40+
441
handle_workflows_startup_error() {
542
local step=$1
643
local detailed_status=""
@@ -33,34 +70,8 @@ handle_workflows_startup_error() {
3370
exit 1
3471
}
3572

36-
RESOURCE_METADATA_FILE=/opt/ml/metadata/resource-metadata.json
37-
SM_DOMAIN_ID=$(jq -r ".DomainId" < $RESOURCE_METADATA_FILE)
38-
HOME_FOLDER_NAME=src
39-
AWS_ACCOUNT_ID=$(jq -r '.ExecutionRoleArn | split(":")[4]' < $RESOURCE_METADATA_FILE)
40-
ECR_ACCOUNT_ID=058264401727
41-
DZ_DOMAIN_ID=$(jq -r '.AdditionalMetadata.DataZoneDomainId' < $RESOURCE_METADATA_FILE)
42-
DZ_PROJECT_ID=$(jq -r '.AdditionalMetadata.DataZoneProjectId' < $RESOURCE_METADATA_FILE)
43-
DZ_ENV_ID=$(jq -r '.AdditionalMetadata.DataZoneEnvironmentId' < $RESOURCE_METADATA_FILE)
44-
DZ_DOMAIN_REGION=$(jq -r '.AdditionalMetadata.DataZoneDomainRegion' < $RESOURCE_METADATA_FILE)
45-
DZ_ENDPOINT=$(jq -r '.AdditionalMetadata.DataZoneEndpoint' < $RESOURCE_METADATA_FILE)
46-
DZ_PROJECT_S3PATH=$(jq -r '.AdditionalMetadata.ProjectS3Path' < $RESOURCE_METADATA_FILE)
47-
WORKFLOW_DAG_PATH="/home/sagemaker-user/${HOME_FOLDER_NAME}/workflows/dags"
48-
WORKFLOW_CONFIG_PATH="/home/sagemaker-user/${HOME_FOLDER_NAME}/workflows/config"
49-
WORKFLOW_DB_DATA_PATH="/home/sagemaker-user/.workflows_setup/db-data"
50-
WORKFLOW_REQUIREMENTS_PATH="/home/sagemaker-user/.workflows_setup/requirements/"
51-
WORKFLOW_PLUGINS_PATH="/home/sagemaker-user/.workflows_setup/plugins"
52-
WORKFLOW_STARTUP_PATH="/home/sagemaker-user/.workflows_setup/startup/"
53-
WORKFLOW_ARTIFACTS_SOURCE_DIR="/etc/sagemaker-ui/workflows"
54-
WORKFLOW_PLUGINS_SOURCE_PATH="${WORKFLOW_ARTIFACTS_SOURCE_DIR}/plugins/*.whl"
55-
WORKFLOW_REQUIREMENTS_SOURCE_PATH="${WORKFLOW_ARTIFACTS_SOURCE_DIR}/requirements/requirements.txt"
56-
WORKFLOW_AIRFLOW_REQUIREMENTS_SOURCE_PATH="/etc/sagemaker-ui/workflows/requirements/requirements.txt"
57-
WORKFLOW_OUTPUT_PATH="/home/sagemaker-user/jobs"
58-
USER_REQUIREMENTS_FILE="${WORKFLOW_CONFIG_PATH}/requirements.txt"
59-
USER_PLUGINS_FOLDER="${WORKFLOW_CONFIG_PATH}/plugins"
60-
USER_STARTUP_FILE="${WORKFLOW_CONFIG_PATH}/startup.sh"
61-
6273
# Create status log file if it doesn't exist
63-
WORKFLOW_HEALTH_PATH="/home/sagemaker-user/.workflows_setup/health"
74+
WORKFLOW_HEALTH_PATH="$HOME/.workflows_setup/health"
6475
mkdir -p $WORKFLOW_HEALTH_PATH
6576
if [ ! -f "${WORKFLOW_HEALTH_PATH}/status.json" ]; then
6677
echo "Creating status file"
@@ -171,7 +182,8 @@ cp -n "/etc/sagemaker-ui/workflows/sample_dag.py" "${WORKFLOW_DAG_PATH}/"
171182
# Log into ECR repository
172183
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ECR_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com
173184

174-
HOME_FOLDER_NAME=$HOME_FOLDER_NAME \
185+
PROJECT_DIR=$(basename $PROJECT_DIR) \
186+
MOUNT_DIR=$MOUNT_DIR \
175187
ECR_ACCOUNT_ID=$ECR_ACCOUNT_ID \
176188
ACCOUNT_ID=$AWS_ACCOUNT_ID \
177189
DZ_DOMAIN_ID=$DZ_DOMAIN_ID \

template/v3/dirs/etc/sagemaker-ui/libmgmt/install-lib.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22
set -eux
3-
3+
PROJECT_DIR=${SMUS_PROJECT_DIR:-"$HOME/src"}
44
# Check if the .libs.json file exists
5-
if [ -e $1/.libs.json ]; then
6-
lib_config_json=`cat $1/.libs.json`
5+
if [ -e $PROJECT_DIR/.libs.json ]; then
6+
lib_config_json=`cat $PROJECT_DIR/.libs.json`
77

88
apply_change_to_space=`echo $lib_config_json | jq -r '.ApplyChangeToSpace'`
99
# Extract conda channels from the config, add `-c ` before each channel and join the strings

template/v3/dirs/etc/sagemaker-ui/sagemaker_ui_post_startup.sh

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ echo "Successfully removed the ~/.aws/config file"
6262
aws configure set credential_source EcsContainer
6363
echo "Successfully configured default profile"
6464

65+
# Add region configuration using REGION_NAME environment variable
66+
aws configure set region "${REGION_NAME}"
67+
echo "Successfully configured region to ${REGION_NAME}"
68+
6569
# add SparkMonitor and Connection Magic entrypoint
6670
NB_USER=sagemaker-user
6771

@@ -101,7 +105,6 @@ else
101105
echo "Successfully configured DomainExecutionRoleCreds profile"
102106
fi
103107

104-
105108
# Run AWS CLI command to get the username from DataZone User Profile.
106109
if [ ! -z "$dataZoneEndPoint" ]; then
107110
response=$( aws datazone get-user-profile --endpoint-url "$dataZoneEndPoint" --domain-identifier "$dataZoneDomainId" --user-identifier "$dataZoneUserId" --region "$dataZoneDomainRegion" )
@@ -135,8 +138,8 @@ case "$auth_mode" in
135138
;;
136139
esac
137140

138-
# Checks if the project is using Git or Non-Git storage
139-
is_non_git_storage() {
141+
# Checks if the project is using Git or S3 storage
142+
is_s3_storage() {
140143
getProjectDefaultEnvResponse=$(sagemaker-studio project get-project-default-environment --domain-id "$dataZoneDomainId" --project-id "$dataZoneProjectId" --profile DomainExecutionRoleCreds)
141144
gitConnectionArn=$(echo "$getProjectDefaultEnvResponse" | jq -r '.provisionedResources[] | select(.name=="gitConnectionArn") | .value')
142145
codeRepositoryName=$(echo "$getProjectDefaultEnvResponse" | jq -r '.provisionedResources[] | select(.name=="codeRepositoryName") | .value')
@@ -150,7 +153,26 @@ is_non_git_storage() {
150153

151154
echo "Checking Project Storage Type"
152155

153-
if ! is_non_git_storage; then
156+
# Execute once to store the result
157+
is_s3_storage
158+
is_s3_storage_flag=$? # 0 if S3 storage, 1 if Git
159+
160+
if [ "$is_s3_storage_flag" -eq 0 ]; then
161+
export SMUS_PROJECT_DIR="$HOME/shared"
162+
echo "Project is using S3 storage, project directory set to: $SMUS_PROJECT_DIR"
163+
else
164+
export SMUS_PROJECT_DIR="$HOME/src"
165+
echo "Project is using Git storage, project directory set to: $SMUS_PROJECT_DIR"
166+
fi
167+
168+
if grep -q "^SMUS_PROJECT_DIR=" ~/.bashrc; then
169+
echo "SMUS_PROJECT_DIR is defined in the env"
170+
else
171+
echo SMUS_PROJECT_DIR="$SMUS_PROJECT_DIR" >> ~/.bashrc
172+
echo readonly SMUS_PROJECT_DIR >> ~/.bashrc
173+
fi
174+
175+
if [ $is_s3_storage_flag -ne 0 ]; then
154176
# Creating a directory where the repository will be cloned
155177
mkdir -p "$HOME/src"
156178

@@ -191,7 +213,7 @@ if [ "${SAGEMAKER_APP_TYPE_LOWERCASE}" = "jupyterlab" ]; then
191213
trap 'write_status_to_file "error" "An unexpected error occurred. Please stop and restart your space to retry."' ERR
192214

193215
# Install conda and pip dependencies if lib mgmt config existing
194-
bash /etc/sagemaker-ui/libmgmt/install-lib.sh $HOME/src
216+
bash /etc/sagemaker-ui/libmgmt/install-lib.sh
195217

196218
# Install sm-spark-cli
197219
bash /etc/sagemaker-ui/workflows/sm-spark-cli-install.sh

0 commit comments

Comments
 (0)