From 3c1b2ddd611b26396e669016b5f07e8c61cff1cc Mon Sep 17 00:00:00 2001 From: Bulat Khusnimardanov Date: Thu, 17 Aug 2023 15:59:34 +0000 Subject: [PATCH 1/3] Added fallback method to retrieve cosign version --- src/terraform/devcontainer-feature.json | 2 +- src/terraform/install.sh | 32 ++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/terraform/devcontainer-feature.json b/src/terraform/devcontainer-feature.json index b1e6df2c8..119b4335e 100644 --- a/src/terraform/devcontainer-feature.json +++ b/src/terraform/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "terraform", - "version": "1.3.3", + "version": "1.3.4", "name": "Terraform, tflint, and TFGrunt", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/terraform", "description": "Installs the Terraform CLI and optionally TFLint and Terragrunt. Auto-detects latest version and installs needed dependencies.", diff --git a/src/terraform/install.sh b/src/terraform/install.sh index 82e3e8d51..898d86d71 100755 --- a/src/terraform/install.sh +++ b/src/terraform/install.sh @@ -160,12 +160,42 @@ check_packages() { # Install 'cosign' for validating signatures # https://docs.sigstore.dev/cosign/overview/ +get_cosign_latest_version() { + local github_api_url="https://api.github.com/repos/sigstore/cosign/releases/latest" + local response + response=$(curl -s -w "%{http_code}" "$github_api_url") + local status_code=${response: -3} + local content=${response::-3} + + if [[ $status_code -eq 200 ]]; then + local latest_version + latest_version=$(echo "$content" | grep tag_name | cut -d : -f2 | tr -d "v\", ") + echo "$latest_version" + else + local github_url="https://github.com/sigstore/cosign/releases/latest" + redirect_url=$(curl -s -L -w "%{url_effective}" -o /dev/null "$github_url") + + response=$(curl -L -s -o /dev/null -w "%{url_effective}\n%{response_code}" "$github_url") + local status_code=${response: -3} + local redirect_url=${response::-3} + + if [[ $status_code -eq 200 ]]; then + local latest_version + latest_version=$(echo "$redirect_url" | cut -d '/' -f8 | tr -d "v") + echo "$latest_version" + else + echo "Failed to fetch latest cosign version" + exit 1 + fi + fi +} + ensure_cosign() { check_packages curl ca-certificates gnupg2 if ! type cosign > /dev/null 2>&1; then echo "Installing cosign..." - local LATEST_COSIGN_VERSION=$(curl https://api.github.com/repos/sigstore/cosign/releases/latest | grep tag_name | cut -d : -f2 | tr -d "v\", ") + local LATEST_COSIGN_VERSION=$(get_cosign_latest_version) curl -L "https://github.com/sigstore/cosign/releases/latest/download/cosign_${LATEST_COSIGN_VERSION}_${architecture}.deb" -o /tmp/cosign_${LATEST_COSIGN_VERSION}_${architecture}.deb dpkg -i /tmp/cosign_${LATEST_COSIGN_VERSION}_${architecture}.deb From ecd2a45e662baf93af63edbface7dc27063af63e Mon Sep 17 00:00:00 2001 From: Bulat Khusnimardanov <61210700+bulat-khusnimardanov@users.noreply.github.com> Date: Fri, 18 Aug 2023 09:10:41 +0200 Subject: [PATCH 2/3] Update src/terraform/install.sh Co-authored-by: Samruddhi Khandale --- src/terraform/install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/terraform/install.sh b/src/terraform/install.sh index 898d86d71..cc8dab017 100755 --- a/src/terraform/install.sh +++ b/src/terraform/install.sh @@ -195,7 +195,8 @@ ensure_cosign() { if ! type cosign > /dev/null 2>&1; then echo "Installing cosign..." - local LATEST_COSIGN_VERSION=$(get_cosign_latest_version) + LATEST_COSIGN_VERSION="latest" + find_version_from_git_tags LATEST_COSIGN_VERSION 'https://github.com/sigstore/cosign' curl -L "https://github.com/sigstore/cosign/releases/latest/download/cosign_${LATEST_COSIGN_VERSION}_${architecture}.deb" -o /tmp/cosign_${LATEST_COSIGN_VERSION}_${architecture}.deb dpkg -i /tmp/cosign_${LATEST_COSIGN_VERSION}_${architecture}.deb From 83d43a94fc95a495e0c31b8b978cbceec5f9c64d Mon Sep 17 00:00:00 2001 From: Bulat Khusnimardanov Date: Fri, 18 Aug 2023 07:19:14 +0000 Subject: [PATCH 3/3] Remove get_cosign_latest_version function --- src/terraform/install.sh | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/src/terraform/install.sh b/src/terraform/install.sh index cc8dab017..1156f6d41 100755 --- a/src/terraform/install.sh +++ b/src/terraform/install.sh @@ -160,36 +160,6 @@ check_packages() { # Install 'cosign' for validating signatures # https://docs.sigstore.dev/cosign/overview/ -get_cosign_latest_version() { - local github_api_url="https://api.github.com/repos/sigstore/cosign/releases/latest" - local response - response=$(curl -s -w "%{http_code}" "$github_api_url") - local status_code=${response: -3} - local content=${response::-3} - - if [[ $status_code -eq 200 ]]; then - local latest_version - latest_version=$(echo "$content" | grep tag_name | cut -d : -f2 | tr -d "v\", ") - echo "$latest_version" - else - local github_url="https://github.com/sigstore/cosign/releases/latest" - redirect_url=$(curl -s -L -w "%{url_effective}" -o /dev/null "$github_url") - - response=$(curl -L -s -o /dev/null -w "%{url_effective}\n%{response_code}" "$github_url") - local status_code=${response: -3} - local redirect_url=${response::-3} - - if [[ $status_code -eq 200 ]]; then - local latest_version - latest_version=$(echo "$redirect_url" | cut -d '/' -f8 | tr -d "v") - echo "$latest_version" - else - echo "Failed to fetch latest cosign version" - exit 1 - fi - fi -} - ensure_cosign() { check_packages curl ca-certificates gnupg2