Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci] Add support for v2 tags during build #5890

Merged
merged 5 commits into from
Aug 27, 2024
Merged
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
101 changes: 14 additions & 87 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -322,79 +309,19 @@ 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

.PHONY: 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:
Expand Down
20 changes: 20 additions & 0 deletions Makefile.BuildInfo.mk
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 2 additions & 5 deletions Makefile.Tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 $@))
82 changes: 82 additions & 0 deletions Makefile.Windows.mk
Original file line number Diff line number Diff line change
@@ -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)
Empty file modified scripts/adaptive-sampling-integration-test.sh
100644 → 100755
Empty file.
Empty file modified scripts/build-upload-a-docker-image.sh
100644 → 100755
Empty file.
Empty file modified scripts/compare_metrics.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion scripts/compute-tags.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Empty file modified scripts/compute-tags.test.sh
100644 → 100755
Empty file.
98 changes: 98 additions & 0 deletions scripts/compute-version.sh
Original file line number Diff line number Diff line change
@@ -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 <jaeger_version>"
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"
Empty file modified scripts/dco_check.py
100644 → 100755
Empty file.
Empty file modified scripts/docker-login.sh
100644 → 100755
Empty file.
Empty file modified scripts/rebuild-ui.sh
100644 → 100755
Empty file.
Loading