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
71 changes: 62 additions & 9 deletions scripts/build/build-upload-a-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@
# Copyright (c) 2024 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0

# Milestone 1: Default to v2 docker image tags
#
# By default, docker images are tagged with v2-style tags (no -v1 suffix).
# To build v1-style images, set JAEGER_VERSION=1 or VERSION=1 in the environment,
# or pass --version 1 as an argument.
# To include both v2 and legacy v1 tags, set INCLUDE_LEGACY_V1=1 or pass --include-legacy-v1.
#
# Usage:
# build-upload-a-docker-image.sh [options]
# JAEGER_VERSION=1 build-upload-a-docker-image.sh [options]
# build-upload-a-docker-image.sh --version 1 [options]
# build-upload-a-docker-image.sh --include-legacy-v1 [options]

set -euf -o pipefail

print_help() {
echo "Usage: $0 [-c] [-D] [-h] [-l] [-o] [-p platforms]"
echo "Usage: $0 [-c] [-D] [-h] [-l] [-o] [-p platforms] [--version <1|2>] [--include-legacy-v1] [--dry-run]"
echo "-h: Print help"
echo "-b: add base_image and debug_image arguments to the build command"
echo "-c: name of the component to build"
Expand All @@ -15,10 +28,19 @@ print_help() {
echo "-o: overwrite image in the target remote repository even if the semver tag already exists"
echo "-p: Comma-separated list of platforms to build for (default: all supported)"
echo "-t: Release target (release|debug) if required by the Dockerfile"
echo "--version <1|2>: Explicitly set JAEGER_VERSION (default: 2)"
echo "--include-legacy-v1: Include legacy v1 tags when building v2 images"
echo "--dry-run: Perform dry run without pushing images"
exit 1
}

echo "BRANCH=${BRANCH:?'expecting BRANCH env var'}"

# Default to v2 unless explicitly set
export JAEGER_VERSION=${JAEGER_VERSION:-${VERSION:-2}}
export INCLUDE_LEGACY_V1=${INCLUDE_LEGACY_V1:-0}
DRY_RUN='N'

base_debug_img_arg=""
docker_file_arg="Dockerfile"
target_arg=""
Expand All @@ -28,6 +50,27 @@ namespace="jaegertracing"
overwrite='N'
upload_readme='N'

# Parse long options first
while [[ $# -gt 0 ]]; do
case "$1" in
--version)
export JAEGER_VERSION="$2"
shift 2
;;
--include-legacy-v1)
export INCLUDE_LEGACY_V1=1
shift
;;
--dry-run)
DRY_RUN='Y'
shift
;;
*)
break
;;
esac
done

while getopts "bc:d:f:hlop:t:" opt; do
# shellcheck disable=SC2220 # we don't need a *) case
case "${opt}" in
Expand Down Expand Up @@ -95,20 +138,30 @@ if [[ "${local_test_only}" = "Y" ]]; then
PUSHTAG="type=image,push=true"
else
echo "::group:: compute tags ${component_name}"
# Pass JAEGER_VERSION and INCLUDE_LEGACY_V1 to compute-tags.sh via environment
COMPUTE_TAGS_ARGS="${namespace}/${component_name}"
if [[ "$INCLUDE_LEGACY_V1" == "1" ]]; then
COMPUTE_TAGS_ARGS="--include-legacy-v1 ${COMPUTE_TAGS_ARGS}"
fi
# shellcheck disable=SC2086
IFS=" " read -r -a IMAGE_TAGS <<< "$(bash scripts/utils/compute-tags.sh ${namespace}/${component_name})"
IFS=" " read -r -a IMAGE_TAGS <<< "$(VERSION=${JAEGER_VERSION} INCLUDE_LEGACY_V1=${INCLUDE_LEGACY_V1} bash scripts/utils/compute-tags.sh ${COMPUTE_TAGS_ARGS})"
echo "::endgroup::"

# Only push multi-arch images to dockerhub/quay.io for main branch or for release tags vM.N.P{-rcX}
if [[ "$BRANCH" == "main" || $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$ ]]; then
echo "will build docker images and upload to dockerhub/quay.io, BRANCH=$BRANCH"
bash scripts/utils/docker-login.sh
PUSHTAG="type=image,push=true"
upload_comment=" and uploading"
if [[ "$overwrite" == 'N' ]]; then
check_overwrite "${IMAGE_TAGS[@]}"
if [[ "$DRY_RUN" == "Y" ]]; then
echo "DRY RUN: would build docker images and upload to dockerhub/quay.io, BRANCH=$BRANCH"
PUSHTAG="type=image,push=false"
else
echo "will build docker images and upload to dockerhub/quay.io, BRANCH=$BRANCH"
bash scripts/utils/docker-login.sh
PUSHTAG="type=image,push=true"
upload_comment=" and uploading"
if [[ "$overwrite" == 'N' ]]; then
check_overwrite "${IMAGE_TAGS[@]}"
fi
upload_readme='Y'
fi
upload_readme='Y'
else
echo 'skipping docker images upload, because not on tagged release or main branch'
PUSHTAG="type=image,push=false"
Expand Down
65 changes: 56 additions & 9 deletions scripts/makefiles/BuildBinaries.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
# Copyright (c) 2023 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0

# Milestone 1: Re-number build targets to use v2 by default
#
# By default, binaries are built with v2 version info (JAEGER_VERSION=2).
# To override and build v1 binaries, set JAEGER_VERSION=1 in the environment
# or when invoking make, e.g.:
# JAEGER_VERSION=1 make build-all-in-one
#
# Exception targets that still default to v1:
# - build-all-in-one
# - build-query
# - build-collector
# - build-ingester
#
# All other targets default to v2.

# Check if user explicitly set JAEGER_VERSION via environment or command line
# If not set, we'll determine the default based on the target
JAEGER_VERSION_EXPLICIT := $(origin JAEGER_VERSION)

# Default to v2 for most targets
JAEGER_VERSION ?= 2

# Check if any of the exception targets are in MAKECMDGOALS
# and override JAEGER_VERSION to 1 for those targets if not explicitly set by user
ifneq ($(filter build-all-in-one build-query build-collector build-ingester,$(MAKECMDGOALS)),)
# Only override if JAEGER_VERSION was not explicitly set (i.e., origin is undefined or file)
ifneq ($(filter undefined file,$(JAEGER_VERSION_EXPLICIT)),)
JAEGER_VERSION = 1
endif
endif

# Select BUILD_INFO based on JAEGER_VERSION
ifeq ($(JAEGER_VERSION),1)
BUILD_INFO_DEFAULT = $(BUILD_INFO)
else
BUILD_INFO_DEFAULT = $(BUILD_INFO_V2)
endif

# 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
Expand Down Expand Up @@ -43,34 +81,34 @@ build-examples:

.PHONY: build-tracegen
build-tracegen:
$(GOBUILD) $(BUILD_INFO) -o ./cmd/tracegen/tracegen-$(GOOS)-$(GOARCH) ./cmd/tracegen/
$(GOBUILD) $(BUILD_INFO_DEFAULT) -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_DEFAULT) -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_DEFAULT) -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_DEFAULT) -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_DEFAULT) -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) $(BUILD_INFO_TO_USE)
# Other targets can depend on this one but with a unique suffix to ensure it is always executed.
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_TO_USE) $(BIN_PATH)

.PHONY: build-jaeger
build-jaeger: BIN_NAME = jaeger
build-jaeger: BUILD_INFO = $(BUILD_INFO_V2)
build-jaeger: BUILD_INFO_TO_USE = $(BUILD_INFO_DEFAULT)
build-jaeger: build-ui _build-a-binary-jaeger$(SUFFIX)-$(GOOS)-$(GOARCH)
@ set -euf -o pipefail ; \
echo "Checking version of built binary" ; \
Expand All @@ -79,7 +117,11 @@ build-jaeger: build-ui _build-a-binary-jaeger$(SUFFIX)-$(GOOS)-$(GOARCH)
if [ "$(GOOS)" == "$$REAL_GOOS" ] && [ "$(GOARCH)" == "$$REAL_GOARCH" ]; then \
./cmd/jaeger/jaeger-$(GOOS)-$(GOARCH) version 2>/dev/null ; \
echo "" ; \
want=$(GIT_CLOSEST_TAG_V2) ; \
if [ "$(JAEGER_VERSION)" == "1" ]; then \
want=$(GIT_CLOSEST_TAG_V1) ; \
else \
want=$(GIT_CLOSEST_TAG_V2) ; \
fi ; \
have=$$(./cmd/jaeger/jaeger-$(GOOS)-$(GOARCH) version 2>/dev/null | jq -r .gitVersion) ; \
if [ "$$want" == "$$have" ]; then \
echo "🟢 versions match: want=$$want, have=$$have" ; \
Expand All @@ -95,22 +137,27 @@ build-jaeger: build-ui _build-a-binary-jaeger$(SUFFIX)-$(GOOS)-$(GOARCH)

.PHONY: build-all-in-one
build-all-in-one: BIN_NAME = all-in-one
build-all-in-one: BUILD_INFO_TO_USE = $(BUILD_INFO)
build-all-in-one: build-ui _build-a-binary-all-in-one$(SUFFIX)-$(GOOS)-$(GOARCH)

.PHONY: build-query
build-query: BIN_NAME = query
build-query: BUILD_INFO_TO_USE = $(BUILD_INFO)
build-query: build-ui _build-a-binary-query$(SUFFIX)-$(GOOS)-$(GOARCH)

.PHONY: build-collector
build-collector: BIN_NAME = collector
build-collector: BUILD_INFO_TO_USE = $(BUILD_INFO)
build-collector: _build-a-binary-collector$(SUFFIX)-$(GOOS)-$(GOARCH)

.PHONY: build-ingester
build-ingester: BIN_NAME = ingester
build-ingester: BUILD_INFO_TO_USE = $(BUILD_INFO)
build-ingester: _build-a-binary-ingester$(SUFFIX)-$(GOOS)-$(GOARCH)

.PHONY: build-remote-storage
build-remote-storage: BIN_NAME = remote-storage
build-remote-storage: BUILD_INFO_TO_USE = $(BUILD_INFO_DEFAULT)
build-remote-storage: _build-a-binary-remote-storage$(SUFFIX)-$(GOOS)-$(GOARCH)

.PHONY: build-binaries-linux-amd64
Expand Down
48 changes: 46 additions & 2 deletions scripts/utils/compute-tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
# Copyright (c) 2024 The Jaeger Authors.
# SPDX-License-Identifier: Apache-2.0

# Milestone 1: Compute docker image tags defaulting to v2
#
# By default, this script produces v2-style tags (no -v1 suffix).
# To produce v1-style tags, set VERSION=1 or JAEGER_VERSION=1 in the environment.
# To include both v2 and legacy v1 tags, set INCLUDE_LEGACY_V1=1 or pass --include-legacy-v1.
#
# Usage:
# compute-tags.sh <base-image-name>
# VERSION=1 compute-tags.sh <base-image-name>
# INCLUDE_LEGACY_V1=1 compute-tags.sh <base-image-name>
# compute-tags.sh --include-legacy-v1 <base-image-name>

# Compute major/minor/etc image tags based on the current branch

set -ef -o pipefail
Expand All @@ -13,10 +25,27 @@ fi

set -u

# Parse arguments for --include-legacy-v1 flag
INCLUDE_LEGACY_V1=${INCLUDE_LEGACY_V1:-0}
while [[ $# -gt 0 ]]; do
case "$1" in
--include-legacy-v1)
INCLUDE_LEGACY_V1=1
shift
;;
*)
break
;;
esac
done

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)}

# Default to v2 unless explicitly set to v1
VERSION=${VERSION:-${JAEGER_VERSION:-2}}

# accumulate output in this variable
IMAGE_TAGS=""

Expand All @@ -33,14 +62,29 @@ tags() {
## The other possible values are 'main' or another branch name.
if [[ $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$ ]]; then
MAJOR_MINOR_PATCH=${BRANCH#v}
tags "${BASE_BUILD_IMAGE}:${MAJOR_MINOR_PATCH}"
tags "${BASE_BUILD_IMAGE}:latest"

if [[ "$VERSION" == "1" ]]; then
# v1-only mode: produce v1 tags only
tags "${BASE_BUILD_IMAGE}-v1:${MAJOR_MINOR_PATCH}"
tags "${BASE_BUILD_IMAGE}-v1:latest"
else
# v2 mode (default): produce v2 tags first
tags "${BASE_BUILD_IMAGE}:${MAJOR_MINOR_PATCH}"
tags "${BASE_BUILD_IMAGE}:latest"

# Optionally append v1 tags for compatibility
if [[ "$INCLUDE_LEGACY_V1" == "1" ]]; then
tags "${BASE_BUILD_IMAGE}-v1:${MAJOR_MINOR_PATCH}"
tags "${BASE_BUILD_IMAGE}-v1:latest"
fi
fi
elif [[ $BRANCH != "main" ]]; then
# not on release tag nor on main - no tags are needed since we won't publish
echo ""
exit
fi

# Snapshot tags (always produced regardless of version)
tags "${BASE_BUILD_IMAGE}-snapshot:${GITHUB_SHA}"
tags "${BASE_BUILD_IMAGE}-snapshot:latest"

Expand Down