Skip to content

Commit c3e6e90

Browse files
authored
Add jar/zip support (#2280)
* 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
1 parent 62a867f commit c3e6e90

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

builders/container-apps-internal-registry-demo/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ RUN set -eux; \
3838
sudo \
3939
curl \
4040
unzip \
41+
grep \
4142
; \
4243
rm -rf /var/lib/apt/lists/*
4344

builders/container-apps-internal-registry-demo/startup-script.sh

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ file_upload_endpoint="$FILE_UPLOAD_CONTAINER_URL/$FILE_UPLOAD_BLOB_NAME"
1111

1212
temp_app_source_dir="/tmp/appsource"
1313
temp_app_source_path="$temp_app_source_dir/$FILE_UPLOAD_BLOB_NAME"
14+
temp_app_header_path="$temp_app_source_dir/header.txt"
1415
mkdir $temp_app_source_dir
1516

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

2627
# write environment variable CORRELATION_ID to folder "/platform/env",
2728
if [ -n "$CORRELATION_ID" ]; then
28-
echo "$CORRELATION_ID" > "$build_env_dir/CORRELATION_ID"
29+
echo -n "$CORRELATION_ID" > "$build_env_dir/CORRELATION_ID"
2930
fi
3031

32+
file_extension=""
3133
while [[ ! -f "$temp_app_source_path" || ! "$(file $temp_app_source_path)" =~ "compressed data" ]]
3234
do
3335
echo "Waiting for app source to be uploaded. Please upload the app source to the endpoint specified in the Build resource's 'uploadEndpoint' property."
34-
curl -H "$auth_header" -H "$version_header" -H "$date_header" -X GET "$file_upload_endpoint" -o "$temp_app_source_path" -s
36+
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
37+
if [[ -f "$temp_app_header_path" ]]; then
38+
file_extension=$(grep -i x-ms-meta-FileExtension "$temp_app_header_path" | cut -d ' ' -f2)
39+
# Check if the original file extension is .jar, .war, .zip or .tar.gz
40+
if [[ "$file_extension" =~ ".tar.gz"
41+
|| "$file_extension" =~ ".jar"
42+
|| "$file_extension" =~ ".war"
43+
|| "$file_extension" =~ ".zip" ]]; then
44+
break
45+
fi
46+
fi
3547
sleep 5
3648
done
3749

3850
# Extract app code to CNB_APP_DIR directory.
3951
echo "Found app source at '$temp_app_source_path'. Extracting to $CNB_APP_DIR"
4052
mkdir -p $CNB_APP_DIR
4153
cd $CNB_APP_DIR
42-
tar -xzf "$temp_app_source_path"
54+
55+
if [[ "$file_extension" =~ ".jar"
56+
|| "$file_extension" =~ ".war"
57+
|| "$file_extension" =~ ".zip" ]]; then
58+
unzip -qq "$temp_app_source_path"
59+
else
60+
# Keep compatibility with old logic
61+
tar -xzf "$temp_app_source_path"
62+
fi
4363

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

0 commit comments

Comments
 (0)