Skip to content

Commit a9532e8

Browse files
authored
[buildkite]: get version qualifier from google bucket (#2950)
* [buildkite]: get version qualifier from google bucket * omit version qualifier on snapshot builds * omit version qualifier on snapshot builds * omit version qualifier on snapshot builds * fix
1 parent 787fe8d commit a9532e8

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

.buildkite/pipeline.yml

+4-9
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,31 @@ agents:
55
image: "family/platform-ingest-beats-ubuntu-2204"
66

77
steps:
8-
# TODO remove && build.env('VERSION_QUALIFIER') == null
98
- label: ":package: Package Cloudbeat - Snapshot"
10-
if: (build.branch == 'main' || build.branch =~ /^[0-9]+\.[0-9x]+\$/ || build.env("RUN_RELEASE") == "true") && build.env('VERSION_QUALIFIER') == null
9+
if: build.branch == 'main' || build.branch =~ /^[0-9]+\.[0-9x]+\$/ || build.env("RUN_RELEASE") == "true"
1110
env:
1211
WORKFLOW: "snapshot"
1312
key: "package-snapshot"
1413
command: "./.buildkite/scripts/package.sh"
1514
artifact_paths: "build/distributions/*"
1615

17-
# TODO remove && build.env('VERSION_QUALIFIER') == null
1816
- label: ":rocket: Publishing Snapshot DRA artifacts"
19-
if: (build.branch == 'main' || build.branch =~ /^[0-9]+\.[0-9x]+\$/ || build.env("RUN_RELEASE") == "true") && build.env('VERSION_QUALIFIER') == null
17+
if: build.branch == 'main' || build.branch =~ /^[0-9]+\.[0-9x]+\$/ || build.env("RUN_RELEASE") == "true"
2018
depends_on: "package-snapshot"
2119
command: "./.buildkite/scripts/publish.sh"
2220
env:
2321
WORKFLOW: "snapshot"
2422

25-
# Allow building staging from main when VERSION_QUALIFIER is set (allow prerelease testing)
26-
# TODO remove || build.env('VERSION_QUALIFIER') != null
2723
- label: ":package: Package Cloudbeat - Staging"
28-
if: build.branch =~ /^[0-9]+\.[0-9]+\$/ || build.env("RUN_RELEASE") == "true" || build.env('VERSION_QUALIFIER') != null
24+
if: build.branch =~ /^[0-9]+\.[0-9]+\$/ || build.env("RUN_RELEASE") == "true"
2925
env:
3026
WORKFLOW: "staging"
3127
key: "package-staging"
3228
command: "./.buildkite/scripts/package.sh"
3329
artifact_paths: "build/distributions/*"
3430

35-
# TODO remove || build.env('VERSION_QUALIFIER') != null
3631
- label: ":rocket: Publishing Staging DRA artifacts"
37-
if: build.branch =~ /^[0-9]+\.[0-9]+\$/ || build.env("RUN_RELEASE") == "true" || build.env('VERSION_QUALIFIER') != null
32+
if: build.branch =~ /^[0-9]+\.[0-9]+\$/ || build.env("RUN_RELEASE") == "true"
3833
depends_on: "package-staging"
3934
command: "./.buildkite/scripts/publish.sh"
4035
env:

.buildkite/scripts/package.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ source ./bin/activate-hermit
88
CLOUDBEAT_VERSION=$(grep defaultBeatVersion version/version.go | cut -d'=' -f2 | tr -d '" ')
99
PYTHON_BIN=./build/ve/$(go env GOOS)/bin
1010
PYTHON=$PYTHON_BIN/python
11-
VERSION_QUALIFIER="${VERSION_QUALIFIER:-""}"
11+
12+
source .buildkite/scripts/qualifier.sh
13+
echo "VERSION_QUALIFIER: ${VERSION_QUALIFIER}"
14+
export VERSION_QUALIFIER
1215

1316
if [ "$WORKFLOW" = "snapshot" ]; then
1417
export SNAPSHOT="true"
@@ -22,7 +25,7 @@ mage package
2225

2326
CSV_FILE="build/dependencies-${CLOUDBEAT_VERSION}"
2427
[ -n "${SNAPSHOT+x}" ] && CSV_FILE+="-SNAPSHOT"
25-
if [[ -n "$VERSION_QUALIFIER" ]]; then
28+
if [[ -n "${VERSION_QUALIFIER}" ]]; then
2629
CSV_FILE+="-${VERSION_QUALIFIER}"
2730
fi
2831

.buildkite/scripts/publish.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ elif [ -n "$(git ls-remote --heads origin $MAJOR.x)" ]; then
1313
else
1414
BRANCH=main
1515
fi
16-
VERSION_QUALIFIER="${VERSION_QUALIFIER:-""}"
16+
17+
source .buildkite/scripts/qualifier.sh
18+
echo "VERSION_QUALIFIER: ${VERSION_QUALIFIER}"
1719

1820
# Download artifacts from other stages
1921
echo "Downloading artifacts..."

.buildkite/scripts/qualifier.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
# this file should be sourced from inside the package and publish script.
4+
5+
fetch_elastic_qualifier() {
6+
local branch="${1}"
7+
local url="https://storage.googleapis.com/dra-qualifier/${branch}"
8+
local qualifier=""
9+
if curl -sf -o /dev/null "${url}"; then
10+
qualifier=$(curl -s "${url}")
11+
fi
12+
echo "${qualifier}"
13+
}
14+
15+
# If this is a snapshot build, omit VERSION_QUALIFIER
16+
if [ "${WORKFLOW}" = "snapshot" ]; then
17+
VERSION_QUALIFIER=''
18+
19+
# If the VERSION_QUALIFIER is already set (e.g. buildkite custom run), don't modify it.
20+
# Else try to fetch from google bucket for the current branch
21+
elif [ -z "${VERSION_QUALIFIER+x}" ]; then
22+
# VERSION_QUALIFIER is not set, get from bucket
23+
VERSION_QUALIFIER="$(fetch_elastic_qualifier "${BUILDKITE_BRANCH}")"
24+
fi

0 commit comments

Comments
 (0)