From 98d1ba712b5714beca83e6e2a29f1daa98489943 Mon Sep 17 00:00:00 2001 From: zhiyongli Date: Fri, 15 Dec 2023 23:47:14 +0800 Subject: [PATCH 1/5] Add jar/zip support --- .../startup-script.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/builders/container-apps-internal-registry-demo/startup-script.sh b/builders/container-apps-internal-registry-demo/startup-script.sh index e2b68588c6..97cf6546ae 100644 --- a/builders/container-apps-internal-registry-demo/startup-script.sh +++ b/builders/container-apps-internal-registry-demo/startup-script.sh @@ -28,18 +28,29 @@ if [ -n "$CORRELATION_ID" ]; then echo "$CORRELATION_ID" > "$build_env_dir/CORRELATION_ID" fi -while [[ ! -f "$temp_app_source_path" || ! "$(file $temp_app_source_path)" =~ "compressed data" ]] +file_type="" +while [[ ! -f "$temp_app_source_path" ]] || + [[ ! $file_type =~ "compressed data" ]] && + [[ ! $file_type =~ "Zip archive data" ]] && + [[ ! $file_type =~ "Java archive 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 sleep 5 + file_type=$(file $temp_app_source_path) 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_type =~ "Zip archive data" || $file_type =~ "Java archive data" ]]; 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 From 047e33143fcdd29a27be9ed77bb0f0c9fa9cf6fa Mon Sep 17 00:00:00 2001 From: zhiyongli Date: Sat, 16 Dec 2023 18:45:27 +0800 Subject: [PATCH 2/5] Use content type to decision the unzip --- .../Dockerfile | 1 + .../startup-script.sh | 25 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/builders/container-apps-internal-registry-demo/Dockerfile b/builders/container-apps-internal-registry-demo/Dockerfile index 25c019a2dc..1135ce721d 100644 --- a/builders/container-apps-internal-registry-demo/Dockerfile +++ b/builders/container-apps-internal-registry-demo/Dockerfile @@ -38,6 +38,7 @@ RUN set -eux; \ sudo \ curl \ unzip \ + grep \ ; \ rm -rf /var/lib/apt/lists/* diff --git a/builders/container-apps-internal-registry-demo/startup-script.sh b/builders/container-apps-internal-registry-demo/startup-script.sh index 97cf6546ae..ce01d84a98 100644 --- a/builders/container-apps-internal-registry-demo/startup-script.sh +++ b/builders/container-apps-internal-registry-demo/startup-script.sh @@ -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", @@ -28,24 +29,30 @@ if [ -n "$CORRELATION_ID" ]; then echo "$CORRELATION_ID" > "$build_env_dir/CORRELATION_ID" fi -file_type="" -while [[ ! -f "$temp_app_source_path" ]] || - [[ ! $file_type =~ "compressed data" ]] && - [[ ! $file_type =~ "Zip archive data" ]] && - [[ ! $file_type =~ "Java archive data" ]] +content_type="" +while [[ ! -f "$temp_app_source_path" || + ! "$(file $temp_app_source_path)" =~ "compressed data" && + ! $content_type =~ "application/java-archive" && + ! $content_type =~ "application/gzip" && + ! $content_type =~ "application/zip" ]] 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 sleep 5 - file_type=$(file $temp_app_source_path) + + if [[ -f "$temp_app_header_path" ]]; then + content_type=$(grep -i Content-Type "$temp_app_header_path" | cut -d ' ' -f2) + else + echo ""$temp_app_header_path" not found" + fi done # Extract app code to CNB_APP_DIR directory. -echo "Found app source at '$temp_app_source_path'. Extracting to $CNB_APP_DIR" +echo "Found app source at '$temp_app_source_path' with format '$content_type'. Extracting to $CNB_APP_DIR" mkdir -p $CNB_APP_DIR cd $CNB_APP_DIR -if [[ $file_type =~ "Zip archive data" || $file_type =~ "Java archive data" ]]; then +if [[ $content_type =~ "application/zip" || $content_type =~ "java-archive" ]]; then unzip -qq "$temp_app_source_path" else # Keep compatibility with old logic From 59a47d569cd2024cf69feb0bf3ed9d85823890e1 Mon Sep 17 00:00:00 2001 From: zhiyongli Date: Tue, 19 Dec 2023 09:29:15 +0800 Subject: [PATCH 3/5] Remove the message header file not found --- .../container-apps-internal-registry-demo/startup-script.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/builders/container-apps-internal-registry-demo/startup-script.sh b/builders/container-apps-internal-registry-demo/startup-script.sh index ce01d84a98..990c65b818 100644 --- a/builders/container-apps-internal-registry-demo/startup-script.sh +++ b/builders/container-apps-internal-registry-demo/startup-script.sh @@ -42,8 +42,6 @@ do if [[ -f "$temp_app_header_path" ]]; then content_type=$(grep -i Content-Type "$temp_app_header_path" | cut -d ' ' -f2) - else - echo ""$temp_app_header_path" not found" fi done From 751348e85b92550f09dccb736991c06eb2bc879d Mon Sep 17 00:00:00 2001 From: zhiyongli Date: Tue, 19 Dec 2023 22:05:01 +0800 Subject: [PATCH 4/5] Use extension --- .../startup-script.sh | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/builders/container-apps-internal-registry-demo/startup-script.sh b/builders/container-apps-internal-registry-demo/startup-script.sh index 990c65b818..3f2bb3cfe3 100644 --- a/builders/container-apps-internal-registry-demo/startup-script.sh +++ b/builders/container-apps-internal-registry-demo/startup-script.sh @@ -26,31 +26,36 @@ 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 -content_type="" -while [[ ! -f "$temp_app_source_path" || - ! "$(file $temp_app_source_path)" =~ "compressed data" && - ! $content_type =~ "application/java-archive" && - ! $content_type =~ "application/gzip" && - ! $content_type =~ "application/zip" ]] +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" -D "$temp_app_header_path" -s sleep 5 if [[ -f "$temp_app_header_path" ]]; then - content_type=$(grep -i Content-Type "$temp_app_header_path" | cut -d ' ' -f2) + 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 done # Extract app code to CNB_APP_DIR directory. -echo "Found app source at '$temp_app_source_path' with format '$content_type'. Extracting to $CNB_APP_DIR" +echo "Found app source at '$temp_app_source_path'. Extracting to $CNB_APP_DIR" mkdir -p $CNB_APP_DIR cd $CNB_APP_DIR -if [[ $content_type =~ "application/zip" || $content_type =~ "java-archive" ]]; then +if [[ "$file_extension" =~ ".jar" + || "$file_extension" =~ ".war" + || "$file_extension" =~ ".zip" ]]; then unzip -qq "$temp_app_source_path" else # Keep compatibility with old logic From 3b2c8255cccbdced3dbd5b81a8feb977f2179fbd Mon Sep 17 00:00:00 2001 From: zhiyongli Date: Wed, 20 Dec 2023 22:00:43 +0800 Subject: [PATCH 5/5] move sleep after extension check --- .../container-apps-internal-registry-demo/startup-script.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builders/container-apps-internal-registry-demo/startup-script.sh b/builders/container-apps-internal-registry-demo/startup-script.sh index 3f2bb3cfe3..07aa7c74e2 100644 --- a/builders/container-apps-internal-registry-demo/startup-script.sh +++ b/builders/container-apps-internal-registry-demo/startup-script.sh @@ -34,8 +34,6 @@ while [[ ! -f "$temp_app_source_path" || ! "$(file $temp_app_source_path)" =~ "c 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" -D "$temp_app_header_path" -s - sleep 5 - 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 @@ -46,6 +44,7 @@ do break fi fi + sleep 5 done # Extract app code to CNB_APP_DIR directory.