diff --git a/utils/build/docker/cpp_kong/install_ddtrace.sh b/utils/build/docker/cpp_kong/install_ddtrace.sh index 70676b30b54..375f20cca3e 100755 --- a/utils/build/docker/cpp_kong/install_ddtrace.sh +++ b/utils/build/docker/cpp_kong/install_ddtrace.sh @@ -65,6 +65,8 @@ fi # --------------------------------------------------------------------------- # 2. Get Kong plugin files # --------------------------------------------------------------------------- +KONG_IS_RELEASE=false + rock_file="" for f in kong-plugin-ddtrace*.rock; do if [ -e "$f" ]; then @@ -96,10 +98,12 @@ elif [ -d kong-plugin-ddtrace ]; then echo "Using Kong plugin from binaries/kong-plugin-ddtrace" else - KONG_PLUGIN_BRANCH="${KONG_PLUGIN_BRANCH:-main}" - echo "Cloning kong-plugin-ddtrace branch ${KONG_PLUGIN_BRANCH}" - git clone --depth 1 --branch "$KONG_PLUGIN_BRANCH" \ - https://github.com/DataDog/kong-plugin-ddtrace.git kong-plugin-ddtrace + TAG=$(get_latest_release "DataDog/kong-plugin-ddtrace") + echo "Installing kong-plugin-ddtrace from latest release ${TAG}" + curl -sL "https://github.com/DataDog/kong-plugin-ddtrace/archive/refs/tags/${TAG}.tar.gz" \ + | tar -xz + mv "kong-plugin-ddtrace-${TAG#v}" kong-plugin-ddtrace + KONG_IS_RELEASE=true fi # --------------------------------------------------------------------------- @@ -108,6 +112,16 @@ fi PLUGIN_VERSION=$(grep -oP 'VERSION\s*=\s*"\K[^"]+' \ kong-plugin-ddtrace/kong/plugins/ddtrace/handler.lua) +if [ "$KONG_IS_RELEASE" = "false" ]; then + auth_header=$(get_authentication_header) + COMMIT_SHA=$(eval "curl --silent --fail --retry 3 $auth_header \ + https://api.github.com/repos/DataDog/kong-plugin-ddtrace/commits/main" \ + | grep '"sha"' | head -1 | cut -d'"' -f4 | cut -c1-7) + if [ -n "$COMMIT_SHA" ]; then + PLUGIN_VERSION="${PLUGIN_VERSION}-dev+${COMMIT_SHA}" + fi +fi + echo "${PLUGIN_VERSION}" > /builds/SYSTEM_TESTS_LIBRARY_VERSION printf '{"status":"ok","library":{"name":"cpp_kong","version":"%s"}}' \ "$PLUGIN_VERSION" > /builds/healthcheck.json diff --git a/utils/scripts/load-binary.sh b/utils/scripts/load-binary.sh index a0bc211ba2d..26613c1a054 100755 --- a/utils/scripts/load-binary.sh +++ b/utils/scripts/load-binary.sh @@ -309,17 +309,11 @@ elif [ "$TARGET" = "cpp_httpd" ]; then elif [ "$TARGET" = "cpp_kong" ]; then assert_version_is_dev - assert_target_branch_is_not_set - RELEASE=$(curl --silent --fail --show-error -H "Authorization: token $GITHUB_TOKEN" \ - "https://api.github.com/repos/DataDog/kong-plugin-ddtrace/releases/tags/tip") - ASSET_NAME=$(echo "$RELEASE" | jq -r '.assets[] | select(.name | test("kong-plugin-ddtrace.*\\.rock")) | .name') - ASSET_URL=$(echo "$RELEASE" | jq -r '.assets[] | select(.name | test("kong-plugin-ddtrace.*\\.rock")) | .url') - echo "Downloading $ASSET_NAME from kong-plugin-ddtrace tip release" - curl --silent --fail --show-error -L \ - -H "Authorization: token $GITHUB_TOKEN" \ - -H "Accept: application/octet-stream" \ - --output "$ASSET_NAME" \ - "$ASSET_URL" + LIBRARY_TARGET_BRANCH="${LIBRARY_TARGET_BRANCH:-main}" + echo "Cloning kong-plugin-ddtrace branch ${LIBRARY_TARGET_BRANCH}" + git clone --depth 1 --branch "$LIBRARY_TARGET_BRANCH" \ + https://github.com/DataDog/kong-plugin-ddtrace.git kong-plugin-ddtrace + echo "Using kong-plugin-ddtrace@$(git -C kong-plugin-ddtrace rev-parse --short HEAD)" elif [ "$TARGET" = "cpp_nginx" ]; then assert_version_is_dev