Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion scripts/build/build-upload-a-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
# Copyright (c) 2024 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0

# This script builds and optionally uploads a Docker image.
# Default behavior changed: now produces v2 artifacts unless JAEGER_VERSION=1 is explicitly set.
# To build v1 artifacts: JAEGER_VERSION=1 ./build-upload-a-docker-image.sh ...
# To build v2 artifacts (default): ./build-upload-a-docker-image.sh ... or JAEGER_VERSION=2 ...

set -euf -o pipefail

# Default to v2 unless explicitly overridden
JAEGER_VERSION=${JAEGER_VERSION:-2}

print_help() {
echo "Usage: $0 [-c] [-D] [-h] [-l] [-o] [-p platforms]"
echo "-h: Print help"
Expand Down Expand Up @@ -96,7 +104,7 @@ if [[ "${local_test_only}" = "Y" ]]; then
else
echo "::group:: compute tags ${component_name}"
# shellcheck disable=SC2086
IFS=" " read -r -a IMAGE_TAGS <<< "$(bash scripts/utils/compute-tags.sh ${namespace}/${component_name})"
IFS=" " read -r -a IMAGE_TAGS <<< "$(JAEGER_VERSION=${JAEGER_VERSION} bash scripts/utils/compute-tags.sh ${namespace}/${component_name})"
echo "::endgroup::"

# Only push multi-arch images to dockerhub/quay.io for main branch or for release tags vM.N.P{-rcX}
Expand Down
35 changes: 27 additions & 8 deletions scripts/makefiles/BuildBinaries.mk
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
# Copyright (c) 2023 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0

# JAEGER_VERSION controls which version of build info is embedded in binaries.
# Default is v2 (JAEGER_VERSION=2), except for four legacy targets that remain v1:
# - build-all-in-one
# - build-query
# - build-collector
# - build-ingester
# To explicitly build v1 artifacts for other targets, set JAEGER_VERSION=1 when invoking make.
# Example: JAEGER_VERSION=1 make build-jaeger

# This command expects $GOOS/$GOARCH env variables set to reflect the desired target platform.
GOBUILD=echo "building binary for $$(go env GOOS)-$$(go env GOARCH)"; \
CGO_ENABLED=0 installsuffix=cgo $(GO) build -trimpath

# Default JAEGER_VERSION to 2 unless building one of the four exception targets
# or JAEGER_VERSION is explicitly set by the caller
ifeq ($(JAEGER_VERSION),)
ifeq ($(filter $(MAKECMDGOALS),build-all-in-one build-query build-collector build-ingester),)
JAEGER_VERSION := 2
else
JAEGER_VERSION := 1
endif
endif

ifeq ($(DEBUG_BINARY),)
DISABLE_OPTIMIZATIONS =
SUFFIX =
Expand Down Expand Up @@ -43,34 +62,34 @@ build-examples:

.PHONY: build-tracegen
build-tracegen:
$(GOBUILD) $(BUILD_INFO) -o ./cmd/tracegen/tracegen-$(GOOS)-$(GOARCH) ./cmd/tracegen/
$(GOBUILD) $(BUILD_INFO_V$(JAEGER_VERSION)) -o ./cmd/tracegen/tracegen-$(GOOS)-$(GOARCH) ./cmd/tracegen/

.PHONY: build-anonymizer
build-anonymizer:
$(GOBUILD) $(BUILD_INFO) -o ./cmd/anonymizer/anonymizer-$(GOOS)-$(GOARCH) ./cmd/anonymizer/
$(GOBUILD) $(BUILD_INFO_V$(JAEGER_VERSION)) -o ./cmd/anonymizer/anonymizer-$(GOOS)-$(GOARCH) ./cmd/anonymizer/

.PHONY: build-esmapping-generator
build-esmapping-generator:
$(GOBUILD) $(BUILD_INFO) -o ./cmd/esmapping-generator/esmapping-generator-$(GOOS)-$(GOARCH) ./cmd/esmapping-generator/
$(GOBUILD) $(BUILD_INFO_V$(JAEGER_VERSION)) -o ./cmd/esmapping-generator/esmapping-generator-$(GOOS)-$(GOARCH) ./cmd/esmapping-generator/

.PHONY: build-es-index-cleaner
build-es-index-cleaner:
$(GOBUILD) $(BUILD_INFO) -o ./cmd/es-index-cleaner/es-index-cleaner-$(GOOS)-$(GOARCH) ./cmd/es-index-cleaner/
$(GOBUILD) $(BUILD_INFO_V$(JAEGER_VERSION)) -o ./cmd/es-index-cleaner/es-index-cleaner-$(GOOS)-$(GOARCH) ./cmd/es-index-cleaner/

.PHONY: build-es-rollover
build-es-rollover:
$(GOBUILD) $(BUILD_INFO) -o ./cmd/es-rollover/es-rollover-$(GOOS)-$(GOARCH) ./cmd/es-rollover/
$(GOBUILD) $(BUILD_INFO_V$(JAEGER_VERSION)) -o ./cmd/es-rollover/es-rollover-$(GOOS)-$(GOARCH) ./cmd/es-rollover/

# Requires variables: $(BIN_NAME) $(BIN_PATH) $(GO_TAGS) $(DISABLE_OPTIMIZATIONS) $(SUFFIX) $(GOOS) $(GOARCH) $(BUILD_INFO)
# Requires variables: $(BIN_NAME) $(BIN_PATH) $(GO_TAGS) $(DISABLE_OPTIMIZATIONS) $(SUFFIX) $(GOOS) $(GOARCH)
# Other targets can depend on this one but with a unique suffix to ensure it is always executed.
# BUILD_INFO is selected based on JAEGER_VERSION (v1 or v2).
BIN_PATH = ./cmd/$(BIN_NAME)
.PHONY: _build-a-binary
_build-a-binary-%:
$(GOBUILD) $(DISABLE_OPTIMIZATIONS) $(GO_TAGS) -o $(BIN_PATH)/$(BIN_NAME)$(SUFFIX)-$(GOOS)-$(GOARCH) $(BUILD_INFO) $(BIN_PATH)
$(GOBUILD) $(DISABLE_OPTIMIZATIONS) $(GO_TAGS) -o $(BIN_PATH)/$(BIN_NAME)$(SUFFIX)-$(GOOS)-$(GOARCH) $(BUILD_INFO_V$(JAEGER_VERSION)) $(BIN_PATH)

.PHONY: build-jaeger
build-jaeger: BIN_NAME = jaeger
build-jaeger: BUILD_INFO = $(BUILD_INFO_V2)
build-jaeger: build-ui _build-a-binary-jaeger$(SUFFIX)-$(GOOS)-$(GOARCH)
@ set -euf -o pipefail ; \
echo "Checking version of built binary" ; \
Expand Down
1 change: 1 addition & 0 deletions scripts/makefiles/BuildInfo.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ define buildinfoflags
-ldflags "-X $(call buildinfo,commitSHA,$(GIT_SHA)) -X $(call buildinfo,latestVersion,$(GIT_CLOSEST_TAG_$(1))) -X $(call buildinfo,date,$(DATE))"
endef
BUILD_INFO=$(call buildinfoflags,V1)
BUILD_INFO_V1=$(call buildinfoflags,V1)
BUILD_INFO_V2=$(call buildinfoflags,V2)
8 changes: 8 additions & 0 deletions scripts/utils/compute-tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
# SPDX-License-Identifier: Apache-2.0

# Compute major/minor/etc image tags based on the current branch
#
# Default behavior changed: produces v2-first tags unless JAEGER_VERSION=1 is explicitly set.
# To generate v1-only tags: JAEGER_VERSION=1 ./compute-tags.sh <image-name>
# To generate v2-first tags (default): ./compute-tags.sh <image-name> or JAEGER_VERSION=2 ...
#
# When JAEGER_VERSION=2 (or unset), v2 tags are produced first.
# When JAEGER_VERSION=1, v1 tags are produced.

set -ef -o pipefail

Expand All @@ -16,6 +23,7 @@ set -u
BASE_BUILD_IMAGE=${1:?'expecting Docker image name as argument, such as jaegertracing/jaeger'}
BRANCH=${BRANCH:?'expecting BRANCH env var'}
GITHUB_SHA=${GITHUB_SHA:-$(git rev-parse HEAD)}
JAEGER_VERSION=${JAEGER_VERSION:-2}

# accumulate output in this variable
IMAGE_TAGS=""
Expand Down
129 changes: 129 additions & 0 deletions test-v2-defaults.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/bin/bash

# Copyright (c) 2025 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0

# Test script to verify Milestone 1: v2 default reassignment
# This script verifies that build targets default to v2 except for the four exception targets.

set -uo pipefail

cd "$(dirname "$0")"

echo "Testing Milestone 1: v2 Default Reassignment"
echo "=============================================="
echo ""

# Color codes for output
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

pass_count=0
fail_count=0

test_version() {
local target="$1"
local expected_version="$2"
local description="$3"

echo -n "Testing $description... "

# Run make with -n (dry-run) and grep for latestVersion
local actual_version
actual_version=$(make -n "$target" GOOS=linux GOARCH=amd64 2>&1 | grep -oP 'latestVersion=v\K[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true)

if [ -z "$actual_version" ]; then
echo -e "${RED}FAIL${NC} (no version found)"
((fail_count++))
return 0
fi

local expected_major="${expected_version%%.*}"
local actual_major="${actual_version%%.*}"

if [ "$actual_major" = "$expected_major" ]; then
echo -e "${GREEN}PASS${NC} (v$actual_version)"
((pass_count++))
else
echo -e "${RED}FAIL${NC} (expected v$expected_version, got v$actual_version)"
((fail_count++))
fi
return 0
}

test_override() {
local target="$1"
local override_version="$2"
local expected_version="$3"
local description="$4"

echo -n "Testing $description... "

# Run make with -n (dry-run) and grep for latestVersion
local actual_version
actual_version=$(JAEGER_VERSION="$override_version" make -n "$target" GOOS=linux GOARCH=amd64 2>&1 | grep -oP 'latestVersion=v\K[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true)

if [ -z "$actual_version" ]; then
echo -e "${RED}FAIL${NC} (no version found)"
((fail_count++))
return 0
fi

local expected_major="${expected_version%%.*}"
local actual_major="${actual_version%%.*}"

if [ "$actual_major" = "$expected_major" ]; then
echo -e "${GREEN}PASS${NC} (v$actual_version)"
((pass_count++))
else
echo -e "${RED}FAIL${NC} (expected v$expected_version, got v$actual_version)"
((fail_count++))
fi
return 0
}

echo "1. Testing v2 defaults for non-exception targets:"
echo "--------------------------------------------------"
test_version "build-jaeger" "2" "build-jaeger defaults to v2"
test_version "build-tracegen" "2" "build-tracegen defaults to v2"
test_version "build-anonymizer" "2" "build-anonymizer defaults to v2"
test_version "build-esmapping-generator" "2" "build-esmapping-generator defaults to v2"
test_version "build-es-index-cleaner" "2" "build-es-index-cleaner defaults to v2"
test_version "build-es-rollover" "2" "build-es-rollover defaults to v2"
test_version "build-remote-storage" "2" "build-remote-storage defaults to v2"
echo ""

echo "2. Testing v1 defaults for exception targets:"
echo "----------------------------------------------"
test_version "build-all-in-one" "1" "build-all-in-one defaults to v1"
test_version "build-query" "1" "build-query defaults to v1"
test_version "build-collector" "1" "build-collector defaults to v1"
test_version "build-ingester" "1" "build-ingester defaults to v1"
echo ""

echo "3. Testing override mechanism (v2 targets to v1):"
echo "--------------------------------------------------"
test_override "build-jaeger" "1" "1" "JAEGER_VERSION=1 build-jaeger uses v1"
test_override "build-tracegen" "1" "1" "JAEGER_VERSION=1 build-tracegen uses v1"
echo ""

echo "4. Testing override mechanism (v1 targets to v2):"
echo "--------------------------------------------------"
test_override "build-all-in-one" "2" "2" "JAEGER_VERSION=2 build-all-in-one uses v2"
test_override "build-collector" "2" "2" "JAEGER_VERSION=2 build-collector uses v2"
echo ""

echo "=============================================="
echo "Test Results:"
echo " Passed: $pass_count"
echo " Failed: $fail_count"
echo "=============================================="

if [ "$fail_count" -eq 0 ]; then
echo -e "${GREEN}All tests passed!${NC}"
exit 0
else
echo -e "${RED}Some tests failed!${NC}"
exit 1
fi