Skip to content

Commit 4e62b86

Browse files
tejaskashTejas Kashinath
andauthored
Updating post startup script for non-git storage feature (#668)
Co-authored-by: Tejas Kashinath <[email protected]>
1 parent 4ea1781 commit 4e62b86

File tree

2 files changed

+56
-17
lines changed

2 files changed

+56
-17
lines changed

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ dataZoneDomainRegion=$(jq -r '.AdditionalMetadata.DataZoneDomainRegion' < $sourc
7979

8080
set +e
8181

82-
# Creating a directory where the repository will be cloned
83-
mkdir -p $HOME/src
84-
8582
# Remove the ~/.aws/config file to start clean when space restart
8683
rm -f /home/sagemaker-user/.aws/config
8784
echo "Successfully removed the ~/.aws/config file"
@@ -128,9 +125,6 @@ else
128125
echo "Successfully configured DomainExecutionRoleCreds profile"
129126
fi
130127

131-
echo "Starting execution of Git Cloning script"
132-
bash /etc/sagemaker-ui/git_clone.sh
133-
134128
# Run AWS CLI command to get the username from DataZone User Profile.
135129
if [ ! -z "$dataZoneEndPoint" ]; then
136130
response=$( aws datazone get-user-profile --endpoint-url "$dataZoneEndPoint" --domain-identifier "$dataZoneDomainId" --user-identifier "$dataZoneUserId" --region "$dataZoneDomainRegion" )
@@ -164,9 +158,34 @@ case "$auth_mode" in
164158
;;
165159
esac
166160

167-
# Setting up the Git identity for the user .
168-
git config --global user.email "$email"
169-
git config --global user.name "$username"
161+
# Checks if the project is using Git or Non-Git storage
162+
is_non_git_storage() {
163+
getProjectDefaultEnvResponse=$(sagemaker-studio project get-project-default-environment --domain-id "$dataZoneDomainId" --project-id "$dataZoneProjectId" --profile DomainExecutionRoleCreds)
164+
gitConnectionArn=$(echo "$getProjectDefaultEnvResponse" | jq -r '.provisionedResources[] | select(.name=="gitConnectionArn") | .value')
165+
codeRepositoryName=$(echo "$getProjectDefaultEnvResponse" | jq -r '.provisionedResources[] | select(.name=="codeRepositoryName") | .value')
166+
167+
if [ -z "$gitConnectionArn" ] && [ -z "$codeRepositoryName" ]; then
168+
return 0
169+
else
170+
return 1
171+
fi
172+
}
173+
174+
echo "Checking Project Storage Type"
175+
176+
if ! is_non_git_storage; then
177+
# Creating a directory where the repository will be cloned
178+
mkdir -p "$HOME/src"
179+
180+
echo "Starting execution of Git Cloning script"
181+
bash /etc/sagemaker-ui/git_clone.sh
182+
183+
# Setting up the Git identity for the user .
184+
git config --global user.email "$email"
185+
git config --global user.name "$username"
186+
else
187+
echo "Project is using Non-Git storage, skipping git repository setup and ~/src dir creation"
188+
fi
170189

171190
# MLFlow tracking server uses the LOGNAME environment variable to track identity. Set the LOGNAME to the username of the user associated with the space
172191
export LOGNAME=$username

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ dataZoneDomainRegion=$(jq -r '.AdditionalMetadata.DataZoneDomainRegion' < $sourc
7979

8080
set +e
8181

82-
# Creating a directory where the repository will be cloned
83-
mkdir -p $HOME/src
84-
8582
# Remove the ~/.aws/config file to start clean when space restart
8683
rm -f /home/sagemaker-user/.aws/config
8784
echo "Successfully removed the ~/.aws/config file"
@@ -128,8 +125,6 @@ else
128125
echo "Successfully configured DomainExecutionRoleCreds profile"
129126
fi
130127

131-
echo "Starting execution of Git Cloning script"
132-
bash /etc/sagemaker-ui/git_clone.sh
133128

134129
# Run AWS CLI command to get the username from DataZone User Profile.
135130
if [ ! -z "$dataZoneEndPoint" ]; then
@@ -164,9 +159,34 @@ case "$auth_mode" in
164159
;;
165160
esac
166161

167-
# Setting up the Git identity for the user .
168-
git config --global user.email "$email"
169-
git config --global user.name "$username"
162+
# Checks if the project is using Git or Non-Git storage
163+
is_non_git_storage() {
164+
getProjectDefaultEnvResponse=$(sagemaker-studio project get-project-default-environment --domain-id "$dataZoneDomainId" --project-id "$dataZoneProjectId" --profile DomainExecutionRoleCreds)
165+
gitConnectionArn=$(echo "$getProjectDefaultEnvResponse" | jq -r '.provisionedResources[] | select(.name=="gitConnectionArn") | .value')
166+
codeRepositoryName=$(echo "$getProjectDefaultEnvResponse" | jq -r '.provisionedResources[] | select(.name=="codeRepositoryName") | .value')
167+
168+
if [ -z "$gitConnectionArn" ] && [ -z "$codeRepositoryName" ]; then
169+
return 0
170+
else
171+
return 1
172+
fi
173+
}
174+
175+
echo "Checking Project Storage Type"
176+
177+
if ! is_non_git_storage; then
178+
# Creating a directory where the repository will be cloned
179+
mkdir -p "$HOME/src"
180+
181+
echo "Starting execution of Git Cloning script"
182+
bash /etc/sagemaker-ui/git_clone.sh
183+
184+
# Setting up the Git identity for the user .
185+
git config --global user.email "$email"
186+
git config --global user.name "$username"
187+
else
188+
echo "Project is using Non-Git storage, skipping git repository setup and ~/src dir creation"
189+
fi
170190

171191
# MLFlow tracking server uses the LOGNAME environment variable to track identity. Set the LOGNAME to the username of the user associated with the space
172192
export LOGNAME=$username

0 commit comments

Comments
 (0)