From 59dee215090e3e7010c7fb1c38b726a31e25c840 Mon Sep 17 00:00:00 2001 From: Vishal Yadav Date: Fri, 8 May 2026 22:37:42 +0530 Subject: [PATCH 1/2] Fix #5 unzip overwrite failure and add cache reuse When the awscli cache layer is restored by the lifecycle, the layer directory already contains the aws/ tree from the previous install. unzip without -o prompts to replace existing files; in non-interactive builds it reads EOF, chooses "None", and exits non-zero, triggering the "Failed to extract AWS CLI" error. Two fixes: - Add -o flag to unzip so it overwrites without prompting - Add cache reuse: if the cached binary exists and runs for the same architecture, skip the 64MB download+install entirely Also pass --update to aws/install to handle the case where the previous aws-cli directory already exists. Co-Authored-By: Claude Sonnet 4.6 --- bin/build | 56 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/bin/build b/bin/build index e6e0fe6..a81b948 100644 --- a/bin/build +++ b/bin/build @@ -38,6 +38,7 @@ echo " awscli: Detected target architecture: $target_arch" BP_DIR=$(cd $(dirname ${0:-}); cd ..; pwd) TARGET_DIR="$AWS_CLI_LAYER_DIR" +AWS_CLI_BIN="$TARGET_DIR/bin/aws" # Map architecture to AWS CLI installer name case "$target_arch" in @@ -55,35 +56,42 @@ esac AWS_CLI_URL="https://awscli.amazonaws.com/awscli-exe-linux-${awscli_arch}.zip" -echo " awscli: Downloading AWS CLI for ${target_arch} (${awscli_arch})" -cd "$TARGET_DIR" && curl -L "$AWS_CLI_URL" -o awscli.zip || { - echo " ! awscli: Failed to download AWS CLI for ${target_arch}" - exit 1 -} - -cd "$TARGET_DIR" && unzip -q awscli.zip || { - echo " ! awscli: Failed to extract AWS CLI" - exit 1 -} - -# Install AWS CLI -echo " awscli: Installing AWS CLI" -"$TARGET_DIR/aws/install" -i "$TARGET_DIR/aws-cli" -b "$TARGET_DIR/bin" || { - echo " ! awscli: Failed to install AWS CLI" - exit 1 -} - -# Verify AWS CLI works -AWS_CLI_BIN="$TARGET_DIR/bin/aws" -if [ -f "$AWS_CLI_BIN" ]; then +# Reuse cached layer if binary exists and was built for the same architecture. +# Reading cached_arch from the TOML written by a previous build is reliable +# because the lifecycle restores it from the cache image before bin/build runs. +cached_arch="" +if [[ -f "$AWS_CLI_LAYER_TOML" ]]; then + cached_arch=$(grep 'architecture' "$AWS_CLI_LAYER_TOML" 2>/dev/null | head -1 | sed 's/.*"\(.*\)".*/\1/') +fi + +if [[ "$cached_arch" == "$target_arch" ]] && [[ -f "$AWS_CLI_BIN" ]] && "$AWS_CLI_BIN" --version > /dev/null 2>&1; then + echo " awscli: Reusing cached AWS CLI for ${target_arch}" +else + echo " awscli: Downloading AWS CLI for ${target_arch} (${awscli_arch})" + cd "$TARGET_DIR" && curl -L "$AWS_CLI_URL" -o awscli.zip || { + echo " ! awscli: Failed to download AWS CLI for ${target_arch}" + exit 1 + } + + # -o: overwrite existing files without prompting (avoids EOF prompt when cache is restored) + cd "$TARGET_DIR" && unzip -qo awscli.zip || { + echo " ! awscli: Failed to extract AWS CLI" + exit 1 + } + + echo " awscli: Installing AWS CLI" + "$TARGET_DIR/aws/install" -i "$TARGET_DIR/aws-cli" -b "$TARGET_DIR/bin" --update || { + echo " ! awscli: Failed to install AWS CLI" + exit 1 + } + "$AWS_CLI_BIN" --version || { echo " ! awscli: AWS CLI verification failed" exit 1 } echo " awscli: Successfully installed AWS CLI for ${target_arch}" -else - echo " ! awscli: Binary not found after installation" - exit 1 + + rm -f "$TARGET_DIR/awscli.zip" fi # Expose AWS CLI on PATH at launch time. From 07711752ec8b28c72e1ca68585ce3439be47cae3 Mon Sep 17 00:00:00 2001 From: Vishal Yadav Date: Fri, 8 May 2026 22:42:12 +0530 Subject: [PATCH 2/2] Bump version to 0.0.7 Co-Authored-By: Claude Sonnet 4.6 --- buildpack.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildpack.toml b/buildpack.toml index f33e367..bd7774c 100644 --- a/buildpack.toml +++ b/buildpack.toml @@ -2,7 +2,7 @@ api = "0.10" [buildpack] id = "neeto-deploy/awscli" -version = "0.0.6" +version = "0.0.7" name = "NeetoDeploy AWS CLI Buildpack" description = "A Cloud Native Buildpack that installs AWS CLI for AWS operations"