diff --git a/Makefile b/Makefile index c8617305d58..17eb209e09c 100644 --- a/Makefile +++ b/Makefile @@ -76,28 +76,14 @@ FMT_LOG=.fmt.log IMPORT_LOG=.import.log COLORIZE ?= | $(SED) 's/PASS/✅ PASS/g' | $(SED) 's/FAIL/❌ FAIL/g' | $(SED) 's/SKIP/🔕 SKIP/g' -GIT_SHA=$(shell git rev-parse HEAD) -GIT_SHALLOW_CLONE := $(shell git rev-parse --is-shallow-repository) -# Some of GitHub Actions workflows do a shallow checkout without tags. This avoids logging warnings from git. -GIT_CLOSEST_TAG=$(shell if [ "$(GIT_SHALLOW_CLONE)" = "false" ]; then git describe --abbrev=0 --tags; else echo 0.0.0; fi) -ifneq ($(GIT_CLOSEST_TAG),$(shell echo ${GIT_CLOSEST_TAG} | grep -E "$(semver_regex)")) - $(warning GIT_CLOSEST_TAG=$(GIT_CLOSEST_TAG) is not in the semver format $(semver_regex)) -endif -GIT_CLOSEST_TAG_MAJOR := $(shell echo $(GIT_CLOSEST_TAG) | $(SED) -n 's/v\([0-9]*\)\.[0-9]*\.[0-9]/\1/p') -GIT_CLOSEST_TAG_MINOR := $(shell echo $(GIT_CLOSEST_TAG) | $(SED) -n 's/v[0-9]*\.\([0-9]*\)\.[0-9]/\1/p') -GIT_CLOSEST_TAG_PATCH := $(shell echo $(GIT_CLOSEST_TAG) | $(SED) -n 's/v[0-9]*\.[0-9]*\.\([0-9]\)/\1/p') -DATE=$(shell TZ=UTC0 git show --quiet --date='format-local:%Y-%m-%dT%H:%M:%SZ' --format="%cd") -BUILD_INFO_IMPORT_PATH=$(JAEGER_IMPORT_PATH)/pkg/version -BUILD_INFO=-ldflags "-X $(BUILD_INFO_IMPORT_PATH).commitSHA=$(GIT_SHA) -X $(BUILD_INFO_IMPORT_PATH).latestVersion=$(GIT_CLOSEST_TAG) -X $(BUILD_INFO_IMPORT_PATH).date=$(DATE)" - -SYSOFILE=resource.syso - # import other Makefiles after the variables are defined -include Makefile.Tools.mk include docker/Makefile +include Makefile.BuildInfo.mk +include Makefile.Crossdock.mk include Makefile.Protobuf.mk include Makefile.Thrift.mk -include Makefile.Crossdock.mk +include Makefile.Tools.mk +include Makefile.Windows.mk .DEFAULT_GOAL := test-and-lint @@ -233,23 +219,23 @@ build-tracegen: .PHONY: build-anonymizer build-anonymizer: - $(GOBUILD) $(BUILD_INFO) -o ./cmd/anonymizer/anonymizer-$(GOOS)-$(GOARCH) $(BUILD_INFO) ./cmd/anonymizer/ + $(GOBUILD) $(BUILD_INFO) -o ./cmd/anonymizer/anonymizer-$(GOOS)-$(GOARCH) ./cmd/anonymizer/ .PHONY: build-esmapping-generator build-esmapping-generator: - $(GOBUILD) -o ./plugin/storage/es/esmapping-generator-$(GOOS)-$(GOARCH) $(BUILD_INFO) ./cmd/esmapping-generator/ + $(GOBUILD) $(BUILD_INFO) -o ./plugin/storage/es/esmapping-generator-$(GOOS)-$(GOARCH) ./cmd/esmapping-generator/ .PHONY: build-esmapping-generator-linux build-esmapping-generator-linux: - GOOS=linux GOARCH=amd64 $(GOBUILD) -o ./plugin/storage/es/esmapping-generator $(BUILD_INFO) ./cmd/esmapping-generator/ + GOOS=linux $(BUILD_INFO) GOARCH=amd64 $(GOBUILD) -o ./plugin/storage/es/esmapping-generator ./cmd/esmapping-generator/ .PHONY: build-es-index-cleaner build-es-index-cleaner: - $(GOBUILD) -o ./cmd/es-index-cleaner/es-index-cleaner-$(GOOS)-$(GOARCH) ./cmd/es-index-cleaner/ + $(GOBUILD) $(BUILD_INFO) -o ./cmd/es-index-cleaner/es-index-cleaner-$(GOOS)-$(GOARCH) ./cmd/es-index-cleaner/ .PHONY: build-es-rollover build-es-rollover: - $(GOBUILD) -o ./cmd/es-rollover/es-rollover-$(GOOS)-$(GOARCH) ./cmd/es-rollover/ + $(GOBUILD) $(BUILD_INFO) -o ./cmd/es-rollover/es-rollover-$(GOOS)-$(GOARCH) ./cmd/es-rollover/ .PHONY: docker-hotrod docker-hotrod: @@ -294,6 +280,7 @@ _build-a-binary-%: .PHONY: build-jaeger build-jaeger: BIN_NAME = jaeger build-jaeger: GO_TAGS = -tags ui +build-jaeger: BUILD_INFO = $(BUILD_INFO_V2) build-jaeger: build-ui _build-a-binary-jaeger$(SUFFIX)-$(GOOS)-$(GOARCH) .PHONY: build-all-in-one @@ -322,68 +309,6 @@ build-ingester: _build-a-binary-ingester$(SUFFIX)-$(GOOS)-$(GOARCH) build-remote-storage: BIN_NAME = remote-storage build-remote-storage: _build-a-binary-remote-storage$(SUFFIX)-$(GOOS)-$(GOARCH) -# Magic values: -# - LangID "0409" is "US-English". -# - CharsetID "04B0" translates to decimal 1200 for "Unicode". -# - FileOS "040004" defines the Windows kernel "Windows NT". -# - FileType "01" is "Application". -define VERSIONINFO -{ - "FixedFileInfo": { - "FileVersion": { - "Major": $(GIT_CLOSEST_TAG_MAJOR), - "Minor": $(GIT_CLOSEST_TAG_MINOR), - "Patch": $(GIT_CLOSEST_TAG_PATCH), - "Build": 0 - }, - "ProductVersion": { - "Major": $(GIT_CLOSEST_TAG_MAJOR), - "Minor": $(GIT_CLOSEST_TAG_MINOR), - "Patch": $(GIT_CLOSEST_TAG_PATCH), - "Build": 0 - }, - "FileFlagsMask": "3f", - "FileFlags ": "00", - "FileOS": "040004", - "FileType": "01", - "FileSubType": "00" - }, - "StringFileInfo": { - "FileDescription": "$(NAME)", - "FileVersion": "$(GIT_CLOSEST_TAG_MAJOR).$(GIT_CLOSEST_TAG_MINOR).$(GIT_CLOSEST_TAG_PATCH).0", - "LegalCopyright": "2015-2023 The Jaeger Project Authors", - "ProductName": "$(NAME)", - "ProductVersion": "$(GIT_CLOSEST_TAG_MAJOR).$(GIT_CLOSEST_TAG_MINOR).$(GIT_CLOSEST_TAG_PATCH).0" - }, - "VarFileInfo": { - "Translation": { - "LangID": "0409", - "CharsetID": "04B0" - } - } -} -endef - -export VERSIONINFO - -.PHONY: _prepare-winres -_prepare-winres: - $(MAKE) _prepare-winres-helper NAME="Jaeger Agent" PKGPATH="cmd/agent" - $(MAKE) _prepare-winres-helper NAME="Jaeger Collector" PKGPATH="cmd/collector" - $(MAKE) _prepare-winres-helper NAME="Jaeger Query" PKGPATH="cmd/query" - $(MAKE) _prepare-winres-helper NAME="Jaeger Ingester" PKGPATH="cmd/ingester" - $(MAKE) _prepare-winres-helper NAME="Jaeger Remote Storage" PKGPATH="cmd/remote-storage" - $(MAKE) _prepare-winres-helper NAME="Jaeger All-In-One" PKGPATH="cmd/all-in-one" - $(MAKE) _prepare-winres-helper NAME="Jaeger V2" PKGPATH="cmd/jaeger" - $(MAKE) _prepare-winres-helper NAME="Jaeger Tracegen" PKGPATH="cmd/tracegen" - $(MAKE) _prepare-winres-helper NAME="Jaeger Anonymizer" PKGPATH="cmd/anonymizer" - $(MAKE) _prepare-winres-helper NAME="Jaeger ES-Index-Cleaner" PKGPATH="cmd/es-index-cleaner" - $(MAKE) _prepare-winres-helper NAME="Jaeger ES-Rollover" PKGPATH="cmd/es-rollover" - -.PHONY: _prepare-winres-helper -_prepare-winres-helper: - echo $$VERSIONINFO | $(GOVERSIONINFO) -o="$(PKGPATH)/$(SYSOFILE)" - - .PHONY: build-binaries-linux build-binaries-linux: build-binaries-amd64 @@ -391,10 +316,12 @@ build-binaries-linux: build-binaries-amd64 build-binaries-amd64: GOOS=linux GOARCH=amd64 $(MAKE) _build-platform-binaries +# helper targets defined in Makefile.Windows.mk .PHONY: build-binaries-windows -build-binaries-windows: _prepare-winres +build-binaries-windows: + $(MAKE) _build-syso GOOS=windows GOARCH=amd64 $(MAKE) _build-platform-binaries - rm ./cmd/*/$(SYSOFILE) + $(MAKE) _clean-syso .PHONY: build-binaries-darwin build-binaries-darwin: diff --git a/Makefile.BuildInfo.mk b/Makefile.BuildInfo.mk new file mode 100644 index 00000000000..3b39a0c5868 --- /dev/null +++ b/Makefile.BuildInfo.mk @@ -0,0 +1,20 @@ +# Copyright (c) 2023 The Jaeger Authors. +# SPDX-License-Identifier: Apache-2.0 + +GIT_SHA=$(shell git rev-parse HEAD) +DATE=$(shell TZ=UTC0 git show --quiet --date='format-local:%Y-%m-%dT%H:%M:%SZ' --format="%cd") +# Defer evaluation of semver tags until actually needed, using trick from StackOverflow: +# https://stackoverflow.com/questions/44114466/how-to-declare-a-deferred-variable-that-is-computed-only-once-for-all +GIT_CLOSEST_TAG_V1 = $(eval GIT_CLOSEST_TAG_V1 := $(shell scripts/compute-version.sh v1))$(GIT_CLOSEST_TAG_V1) +GIT_CLOSEST_TAG_V2 = $(eval GIT_CLOSEST_TAG_V2 := $(shell scripts/compute-version.sh v2))$(GIT_CLOSEST_TAG_V2) + +# args: (1) - name, (2) - value +define buildinfo + $(JAEGER_IMPORT_PATH)/pkg/version.$(1)=$(2) +endef +# args (1) - V1|V2 +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_V2=$(call buildinfoflags,V2) diff --git a/Makefile.Tools.mk b/Makefile.Tools.mk index 29c0f9d51c6..981b5603d1d 100644 --- a/Makefile.Tools.mk +++ b/Makefile.Tools.mk @@ -20,11 +20,8 @@ install-tools: $(TOOLS_BIN_NAMES) .PHONY: install-test-tools install-test-tools: $(LINT) $(GOFUMPT) -.PHONY: install-build-tools -install-build-tools: $(GOVERSIONINFO) - .PHONY: install-ci -install-ci: install-test-tools install-build-tools +install-ci: install-test-tools list-internal-tools: @echo Third party tool modules: @@ -35,5 +32,5 @@ list-internal-tools: $(TOOLS_BIN_DIR): mkdir -p $@ -$(TOOLS_BIN_NAMES): $(TOOLS_BIN_DIR) $(TOOLS_MOD_DIR)/go.mod +$(TOOLS_BIN_NAMES): $(TOOLS_BIN_DIR) $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum cd $(TOOLS_MOD_DIR) && $(GO) build -o $@ -trimpath $(shell echo $(TOOLS_PKG_NAMES) | tr ' ' '\n' | grep $(notdir $@)) diff --git a/Makefile.Windows.mk b/Makefile.Windows.mk new file mode 100644 index 00000000000..6309e44e3c3 --- /dev/null +++ b/Makefile.Windows.mk @@ -0,0 +1,82 @@ +# Copyright (c) 2024 The Jaeger Authors. +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +SYSOFILE=resource.syso + +# Magic values: +# - LangID "0409" is "US-English". +# - CharsetID "04B0" translates to decimal 1200 for "Unicode". +# - FileOS "040004" defines the Windows kernel "Windows NT". +# - FileType "01" is "Application". +# https://learn.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource +define VERSIONINFO +{ + "FixedFileInfo": { + "FileVersion": { + "Major": $(SEMVER_MAJOR), + "Minor": $(SEMVER_MINOR), + "Patch": $(SEMVER_PATCH), + "Build": 0 + }, + "ProductVersion": { + "Major": $(SEMVER_MAJOR), + "Minor": $(SEMVER_MINOR), + "Patch": $(SEMVER_PATCH), + "Build": 0 + }, + "FileFlagsMask": "3f", + "FileFlags ": "00", + "FileOS": "040004", + "FileType": "01", + "FileSubType": "00" + }, + "StringFileInfo": { + "FileDescription": "$(NAME)", + "FileVersion": "$(SEMVER_MAJOR).$(SEMVER_MINOR).$(SEMVER_PATCH).0", + "LegalCopyright": "2015-2024 The Jaeger Project Authors", + "ProductName": "$(NAME)", + "ProductVersion": "$(SEMVER_MAJOR).$(SEMVER_MINOR).$(SEMVER_PATCH).0" + }, + "VarFileInfo": { + "Translation": { + "LangID": "0409", + "CharsetID": "04B0" + } + } +} +endef + +export VERSIONINFO + +.PHONY: _build_syso_once +_build_syso_once: + echo $$VERSIONINFO + echo $$VERSIONINFO | $(GOVERSIONINFO) -o="$(PKGPATH)/$(SYSOFILE)" - + +define _build_syso_macro + $(MAKE) _build_syso_once NAME="$(1)" PKGPATH="$(2)" SEMVER_MAJOR=$(SEMVER_MAJOR) SEMVER_MINOR=$(SEMVER_MINOR) SEMVER_PATCH=$(SEMVER_PATCH) +endef + +.PHONY: _build-syso +_build-syso: $(GOVERSIONINFO) + $(eval SEMVER_ALL := $(shell scripts/compute-version.sh -s v1)) + $(eval SEMVER_MAJOR := $(word 2, $(SEMVER_ALL))) + $(eval SEMVER_MINOR := $(word 3, $(SEMVER_ALL))) + $(eval SEMVER_PATCH := $(word 4, $(SEMVER_ALL))) + $(call _build_syso_macro,Jaeger Agent,cmd/agent) + $(call _build_syso_macro,Jaeger Collector,cmd/collector) + $(call _build_syso_macro,Jaeger Query,cmd/query) + $(call _build_syso_macro,Jaeger Ingester,cmd/ingester) + $(call _build_syso_macro,Jaeger Remote Storage,cmd/remote-storage) + $(call _build_syso_macro,Jaeger All-In-One,cmd/all-in-one) + $(call _build_syso_macro,Jaeger Tracegen,cmd/tracegen) + $(call _build_syso_macro,Jaeger Anonymizer,cmd/anonymizer) + $(call _build_syso_macro,Jaeger ES-Index-Cleaner,cmd/es-index-cleaner) + $(call _build_syso_macro,Jaeger ES-Rollover,cmd/es-rollover) + # TODO in the future this should be in v2 + $(call _build_syso_macro,Jaeger V2,cmd/jaeger) + +.PHONY: _clean-syso +_clean-syso: + rm ./cmd/*/$(SYSOFILE) diff --git a/scripts/adaptive-sampling-integration-test.sh b/scripts/adaptive-sampling-integration-test.sh old mode 100644 new mode 100755 diff --git a/scripts/build-upload-a-docker-image.sh b/scripts/build-upload-a-docker-image.sh old mode 100644 new mode 100755 diff --git a/scripts/compare_metrics.py b/scripts/compare_metrics.py old mode 100644 new mode 100755 diff --git a/scripts/compute-tags.sh b/scripts/compute-tags.sh old mode 100644 new mode 100755 index 143fb9670ab..7f0a4fb5a0e --- a/scripts/compute-tags.sh +++ b/scripts/compute-tags.sh @@ -13,7 +13,7 @@ fi set -u -BASE_BUILD_IMAGE=${1:?'expecting Docker image name, such as jaegertracing/jaeger'} +BASE_BUILD_IMAGE=${1:?'expecting Docker image name as argument, such as jaegertracing/jaeger'} BRANCH=${BRANCH:?'expecting BRANCH env var'} GITHUB_SHA=${GITHUB_SHA:?'expecting GITHUB_SHA env var'} # allow substituting for ggrep on Mac, since its default grep doesn't grok -P flag. diff --git a/scripts/compute-tags.test.sh b/scripts/compute-tags.test.sh old mode 100644 new mode 100755 diff --git a/scripts/compute-version.sh b/scripts/compute-version.sh new file mode 100755 index 00000000000..c7b8fa0f39c --- /dev/null +++ b/scripts/compute-version.sh @@ -0,0 +1,98 @@ +#!/bin/bash + +# Copyright (c) 2024 The Jaeger Authors. +# SPDX-License-Identifier: Apache-2.0 + +# Extract and parse Jaeger release version from the closest Git tag. + +set -euf -o pipefail +SED=${SED:-sed} + +usage() { + echo "Usage: $0 -v -s " + echo " -s split semver into 4 parts: semver major minor patch" + echo " -v verbose" + echo " jaeger_version: major version, v1 | v2" + exit 1 +} + +verbose="false" +split="false" + +while getopts "sv" opt; do + # shellcheck disable=SC2220 # we don't need a *) case + case "${opt}" in + s) + split="true" + ;; + v) + verbose="true" + ;; + *) + usage + ;; + esac +done + +shift $((OPTIND - 1)) + +case $1 in + v1) + JAEGER_MAJOR=v1 + ;; + v2) + JAEGER_MAJOR=v2 + ;; + *) + echo "Jaeger major version is required as argument" + usage +esac + +print_result() { + if [[ "$split" == "true" ]]; then + echo "$1" "$2" "$3" "$4" + else + echo "$1" + fi +} + +if [[ "$verbose" == "true" ]]; then + set -x +fi + +# Some of GitHub Actions workflows do a shallow checkout without tags. This avoids logging warnings from git. +if [[ $(git rev-parse --is-shallow-repository) == "false" ]]; then + GIT_CLOSEST_TAG=$(git describe --abbrev=0 --tags) +else + if [[ "$verbose" == "true" ]]; then + echo "The repository is a shallow clone, cannot determine most recent tag" >&2 + fi + print_result 0.0.0 0 0 0 + exit +fi + +MATCHING_TAG='' +for tag in $(git tag --list --contains "$(git rev-parse "$GIT_CLOSEST_TAG")"); do + if [[ "${tag:0:2}" == "$JAEGER_MAJOR" ]]; then + MATCHING_TAG="$tag" + break + fi +done +if [[ "$MATCHING_TAG" == "" ]]; then + if [[ "$verbose" == "true" ]]; then + echo "Did not find a tag matching major version $JAEGER_MAJOR" >&2 + fi + print_result 0.0.0 0 0 0 + exit +fi + +if [[ $MATCHING_TAG =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then + MAJOR="${BASH_REMATCH[1]}" + MINOR="${BASH_REMATCH[2]}" + PATCH="${BASH_REMATCH[3]}" +else + echo "Invalid semver format: $MATCHING_TAG" + exit 1 +fi + +print_result "$MATCHING_TAG" "$MAJOR" "$MINOR" "$PATCH" diff --git a/scripts/dco_check.py b/scripts/dco_check.py old mode 100644 new mode 100755 diff --git a/scripts/docker-login.sh b/scripts/docker-login.sh old mode 100644 new mode 100755 diff --git a/scripts/rebuild-ui.sh b/scripts/rebuild-ui.sh old mode 100644 new mode 100755