Skip to content

Commit

Permalink
Add jar/zip support (#2280)
Browse files Browse the repository at this point in the history
* Add jar/zip support

* Use content type to decision the unzip

* Remove the message header file not found

* Use extension

* move sleep after extension check
  • Loading branch information
showpune authored Dec 21, 2023
1 parent 62a867f commit c3e6e90
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions builders/container-apps-internal-registry-demo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ RUN set -eux; \
sudo \
curl \
unzip \
grep \
; \
rm -rf /var/lib/apt/lists/*

Expand Down
26 changes: 23 additions & 3 deletions builders/container-apps-internal-registry-demo/startup-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ file_upload_endpoint="$FILE_UPLOAD_CONTAINER_URL/$FILE_UPLOAD_BLOB_NAME"

temp_app_source_dir="/tmp/appsource"
temp_app_source_path="$temp_app_source_dir/$FILE_UPLOAD_BLOB_NAME"
temp_app_header_path="$temp_app_source_dir/header.txt"
mkdir $temp_app_source_dir

# List all the environment variables and filter the environment variable with prefix "ACA_CLOUD_BUILD_USER_ENV_", then write them to folder "/platform/env",
Expand All @@ -25,21 +26,40 @@ done

# write environment variable CORRELATION_ID to folder "/platform/env",
if [ -n "$CORRELATION_ID" ]; then
echo "$CORRELATION_ID" > "$build_env_dir/CORRELATION_ID"
echo -n "$CORRELATION_ID" > "$build_env_dir/CORRELATION_ID"
fi

file_extension=""
while [[ ! -f "$temp_app_source_path" || ! "$(file $temp_app_source_path)" =~ "compressed data" ]]
do
echo "Waiting for app source to be uploaded. Please upload the app source to the endpoint specified in the Build resource's 'uploadEndpoint' property."
curl -H "$auth_header" -H "$version_header" -H "$date_header" -X GET "$file_upload_endpoint" -o "$temp_app_source_path" -s
curl -H "$auth_header" -H "$version_header" -H "$date_header" -X GET "$file_upload_endpoint" -o "$temp_app_source_path" -D "$temp_app_header_path" -s
if [[ -f "$temp_app_header_path" ]]; then
file_extension=$(grep -i x-ms-meta-FileExtension "$temp_app_header_path" | cut -d ' ' -f2)
# Check if the original file extension is .jar, .war, .zip or .tar.gz
if [[ "$file_extension" =~ ".tar.gz"
|| "$file_extension" =~ ".jar"
|| "$file_extension" =~ ".war"
|| "$file_extension" =~ ".zip" ]]; then
break
fi
fi
sleep 5
done

# Extract app code to CNB_APP_DIR directory.
echo "Found app source at '$temp_app_source_path'. Extracting to $CNB_APP_DIR"
mkdir -p $CNB_APP_DIR
cd $CNB_APP_DIR
tar -xzf "$temp_app_source_path"

if [[ "$file_extension" =~ ".jar"
|| "$file_extension" =~ ".war"
|| "$file_extension" =~ ".zip" ]]; then
unzip -qq "$temp_app_source_path"
else
# Keep compatibility with old logic
tar -xzf "$temp_app_source_path"
fi

fileCount=$(ls | wc -l)
if [ "$fileCount" = "1" ]; then
Expand Down

0 comments on commit c3e6e90

Please sign in to comment.