Skip to content
Snippets Groups Projects
Unverified Commit 19674f3d authored by Timo Furrer's avatar Timo Furrer
Browse files

Introduce support for VERSION file

This change set introduces support for the `VERSION` file used by other
GitLab projects (like Gitaly). It contains the SSoT for the version that
is built - especially for releases.
Using the version from this file is the fallback for when the build is
NOT happening in a git source tree - this is the case for official
GitLab KAS releases via CNG and Omnibus.

When building in a git source tree the `VERSION` file is NOT used, but
the closest git tag with a commit reference suffix is used that is
produced by `git describe`.

This change set also implies that the `make` interface changed, because
it no longer supports providing the `GIT_COMMIT` and `GIT_TAG` arguments
that would in turn have been used for the release versioning.
However, this is still a non-breaking change because the argument will
just not be respected.

Preconditions for this change set to work properly:

- [ ] release-tools needs to support the `VERSION` file for KAS.
- [ ] (optional) change CNG to no longer provide the `GIT_TAG` and
  `GIT_COMMIT` make arguments.
- [ ] (optional) change Omnibus to no longer provide the `GIT_TAG` and
  `GIT_COMMIT` make arguments.

Changelog: other
parent 83048470
No related merge requests found
SHELL = /usr/bin/env bash -eo pipefail
# git invocations must be conditional because git is not available in e.g. CNG and variables are supplied manually.
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
GIT_TAG ?= $(shell git tag --points-at HEAD --list 'v*' --sort v:refname 2>/dev/null | head -n 1 || true)
BUILD_TIME = $(shell date -u +%Y%m%d.%H%M%S)
ifeq ($(GIT_TAG), )
GIT_TAG = v0.0.0
endif
AGENTK_FIPS_IMAGE_TAG = $(CI_REGISTRY_IMAGE)/agentk-fips:$(GIT_TAG)
# NOTE:
# Building the `gitlab-agent` project, that is KAS and agentk,
# is supported in multiple contexts.
# For official KAS releases happening in CNG and Omnibus, the binaries
# are built from an archive (non-git) source tree.
# Whereas official agentk releases are happening in the canonical gitlab-agent
# repository where it is built from a git source tree.
# Therefore, we use the following logic to determine the release `VERSION`:
# - If git is available `git describe` is used
# - For revisions that are pointed to by a tag, the tag is used as is.
# If the revision has multiple tags, the most recent one (version sort) is used.
# - For revisions that are NOT pointed to by a tag, the closest tag in lineage is used
# with a suffix of `-<N>-g<SHA>` where `N` is the number of commits between HEAD and
# that last tag and `SHA` is the commit sha. The `g` stands for `git`.
# - If git is NOT available the contents of the `VERSION` file in the root of the source tree
# is used.
# The `VERSION` file is maintained by release-tools (https://gitlab.com/gitlab-org/release-tools/).
# For any kinds of releases it is expected that release-tools takes care of updating it
# to the proper version before building the releases.
#
# The `BUILD_REF` is populated by the HEADs commit SHA if Git is available,
# or the value of `VERSION` is used otherwise.
VERSION := $(shell git describe --match v* 2>/dev/null || cat ./VERSION 2>/dev/null || echo unknown)
BUILD_REF := $(shell git rev-parse --short HEAD || echo $(VERSION))
BUILD_TIME := $(shell date -u +%Y%m%d.%H%M%S)
AGENTK_IMAGE_TAG_VERSION = $(VERSION)
AGENTK_IMAGE_TAG_DEBUG_VERSION = $(VERSION)-debug
AGENTK_IMAGE_TAG_LATEST_VERSION := latest
AGENTK_IMAGE_TAG_LATEST_DEBUG_VERSION := latest-debug
AGENTK_IMAGE_TAG_STABLE_VERSION := stable
AGENTK_IMAGE_TAG_STABLE_DEBUG_VERSION := stable-debug
AGENTK_IMAGE_TAG_COMMIT_VERSION = $(VERSION)
AGENTK_IMAGE_TAG_COMMIT_DEBUG_VERSION = $(VERSION)-debug
AGENTK_FIPS_IMAGE_TAG = $(CI_REGISTRY_IMAGE)/agentk-fips:$(AGENTK_IMAGE_TAG_VERSION)
AGENTK_FIPS_IMAGE_TAG_WITH_ARCH = $(AGENTK_FIPS_IMAGE_TAG)-$(ARCH)
AGENTK_FIPS_STABLE_IMAGE_TAG = $(CI_REGISTRY_IMAGE)/agentk-fips:stable
AGENTK_FIPS_STABLE_IMAGE_TAG_WITH_ARCH = $(AGENTK_FIPS_STABLE_IMAGE_TAG)-$(ARCH)
LDFLAGS := -X "gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd.Version=$(GIT_TAG)"
LDFLAGS += -X "gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd.Commit=$(GIT_COMMIT)"
LDFLAGS := -X "gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd.Version=$(VERSION)"
LDFLAGS += -X "gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd.Commit=$(BUILD_REF)"
LDFLAGS += -X "gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd.BuildTime=$(BUILD_TIME)"
GO_BUILD_FLAGS = -ldflags '$(LDFLAGS)'
......@@ -143,16 +170,16 @@ quick-test:
# Flags are for oci_push rule. Docs https://docs.aspect.build/rules/rules_oci/docs/push.
.PHONY: release-latest
release-latest:
bazel run //cmd/agentk:push -- --repository='$(OCI_REPO)' --tag=latest
bazel run //cmd/agentk:push_debug -- --repository='$(OCI_REPO)' --tag=latest-debug
bazel run //cmd/agentk:push -- --repository='$(OCI_REPO)' --tag='$(AGENTK_IMAGE_TAG_LATEST_VERSION)'
bazel run //cmd/agentk:push_debug -- --repository='$(OCI_REPO)' --tag='$(AGENTK_IMAGE_TAG_LATEST_DEBUG_VERSION)'
# Build and push all docker images tagged as "stable".
# This only works on a linux machine
# Flags are for oci_push rule. Docs https://docs.aspect.build/rules/rules_oci/docs/push.
.PHONY: release-stable
release-stable:
bazel run //cmd/agentk:push -- --repository='$(OCI_REPO)' --tag=stable
bazel run //cmd/agentk:push_debug -- --repository='$(OCI_REPO)' --tag=stable-debug
bazel run //cmd/agentk:push -- --repository='$(OCI_REPO)' --tag='$(AGENTK_IMAGE_TAG_STABLE_VERSION)'
bazel run //cmd/agentk:push_debug -- --repository='$(OCI_REPO)' --tag='$(AGENTK_IMAGE_TAG_STABLE_DEBUG_VERSION)'
# Build and push all FIPS docker images tagged with the tag on the current commit and as "stable".
# This only works on a linux machine
......@@ -181,8 +208,8 @@ release-tag-and-stable-fips-manifest:
# Flags are for oci_push rule. Docs https://docs.aspect.build/rules/rules_oci/docs/push.
.PHONY: release-tag
release-tag:
bazel run //cmd/agentk:push -- --repository='$(OCI_REPO)' --tag='$(GIT_TAG)'
bazel run //cmd/agentk:push_debug -- --repository='$(OCI_REPO)' --tag='$(GIT_TAG)-debug'
bazel run //cmd/agentk:push -- --repository='$(OCI_REPO)' --tag='$(AGENTK_IMAGE_TAG_VERSION)'
bazel run //cmd/agentk:push_debug -- --repository='$(OCI_REPO)' --tag='$(AGENTK_IMAGE_TAG_DEBUG_VERSION)'
# Build and push all FIPS docker images tagged with the tag on the current commit.
# This only works on a linux machine
......@@ -205,8 +232,8 @@ release-tag-fips-manifest:
# This only works on a linux machine
.PHONY: release-commit
release-commit:
bazel run //cmd/agentk:push -- --repository='$(OCI_REPO)' --tag='$(GIT_COMMIT)'
bazel run //cmd/agentk:push_debug -- --repository='$(OCI_REPO)' --tag='$(GIT_COMMIT)-debug'
bazel run //cmd/agentk:push -- --repository='$(OCI_REPO)' --tag='$(AGENTK_IMAGE_TAG_COMMIT_VERSION)'
bazel run //cmd/agentk:push_debug -- --repository='$(OCI_REPO)' --tag='$(AGENTK_IMAGE_TAG_COMMIT_DEBUG_VERSION)'
# Set TARGET_DIRECTORY variable to the target directory before running this target
.PHONY: gdk-install
......@@ -215,7 +242,6 @@ gdk-install:
mv 'cmd/kas/kas_race' '$(TARGET_DIRECTORY)'
# Set TARGET_DIRECTORY variable to the target directory before running this target
# Optional: set GIT_TAG and GIT_COMMIT variables to supply those values manually.
# This target is used by:
# - CNG: https://gitlab.com/gitlab-org/build/CNG/-/tree/master/gitlab-kas
# - Omnibus: https://gitlab.com/gitlab-org/omnibus-gitlab/-/blob/master/config/software/gitlab-kas.rb
......@@ -226,7 +252,6 @@ kas:
-o '$(TARGET_DIRECTORY)' ./cmd/kas
# Set TARGET_DIRECTORY variable to the target directory before running this target
# Optional: set GIT_TAG and GIT_COMMIT variables to supply those values manually.
# This target is used by FIPS build in this repo.
.PHONY: agentk
agentk:
......
v17.0.0-rc1
......@@ -10,11 +10,11 @@ set -o pipefail
# If the GIT_COMMIT or GIT_TAG variables are not already set
# then it will not try and use git commands to set them.
# See: https://gitlab.com/gitlab-org/cluster-integration/gitlab-agent/-/issues/253
[ -z "${GIT_COMMIT:-}" ] && GIT_COMMIT=$(git rev-parse --short HEAD)
[ -z "${GIT_TAG:-}" ] && GIT_TAG=$(git tag --points-at HEAD --list 'v*' --sort v:refname 2>/dev/null | head -n 1 || true)
GIT_TAG="${GIT_TAG:="v0.0.0"}"
[ -z "${GIT_TAG:-}" ] && GIT_TAG=$(git describe --match v* 2>/dev/null || cat ./VERSION 2>/dev/null || echo unknown)
[ -z "${GIT_COMMIT:-}" ] && GIT_COMMIT=$(git rev-parse --short HEAD || echo "$GIT_TAG")
BUILD_TIME=$(date -u +%Y%m%d.%H%M%S)
# Prefix with STABLE_ so that these values are saved to stable-status.txt
# instead of volatile-status.txt.
# Stamped rules will be retriggered by changes to stable-status.txt, but not by
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment