Skip to content

Commit a155660

Browse files
ci: build agent from snapshot DRA (#9048)
* feat: rework .package-version and mage integration:UpdatePackageVersion to make CI build always from snapshot DRA * feat: incorporate USE_PACKAGE_VERSION in mage * experiment: bump version.go * Revert "experiment: bump version.go" This reverts commit a57ee10. * chore: bump .package-version * feat: allow AGENT_VERSION to be overridden by env var * fix: use named args for all args in integration_tests_tf.ps1 * feat: panic on err of initPackageVersion * fix: don't panic when .package-version file doesn't exist, log it instead * feat: rework fabrication of CI_ELASTIC_AGENT_DOCKER_IMAGE * feat: use os.WriteFile in writePackageVersion * chore: bump to latest snapshot DRA * fix: always DownloadManifest if PackagingFromManifest is set in mage package * fix: check err of filepath.Abs(dropPath)
1 parent 734f6e2 commit a155660

20 files changed

+253
-77
lines changed

.buildkite/integration.pipeline.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,9 @@ steps:
111111
env:
112112
PACKAGES: "docker"
113113
PLATFORMS: "linux/amd64"
114-
CUSTOM_IMAGE_TAG: "git-${BUILDKITE_COMMIT:0:12}"
115-
CI_ELASTIC_AGENT_DOCKER_IMAGE: "docker.elastic.co/beats-ci/elastic-agent-cloud"
116114
command: |
117-
source .buildkite/scripts/common.sh
118115
.buildkite/scripts/steps/integration-package.sh
119-
echo "~~~ Pushing cloud image"
120-
mage cloud:push
116+
.buildkite/scripts/steps/integration-cloud-image-push.sh
121117
artifact_paths:
122118
- build/distributions/**
123119
agents:
@@ -149,13 +145,9 @@ steps:
149145
PACKAGES: "docker"
150146
PLATFORMS: "linux/amd64"
151147
FIPS: "true"
152-
CUSTOM_IMAGE_TAG: "git-${BUILDKITE_COMMIT:0:12}"
153-
CI_ELASTIC_AGENT_DOCKER_IMAGE: "docker.elastic.co/beats-ci/elastic-agent-cloud-fips"
154148
command: |
155-
source .buildkite/scripts/common.sh
156149
.buildkite/scripts/steps/integration-package.sh
157-
echo "~~~ Pushing cloud image"
158-
mage cloud:push
150+
.buildkite/scripts/steps/integration-cloud-image-push.sh
159151
artifact_paths:
160152
- build/distributions/**
161153
agents:

.buildkite/scripts/buildkite-integration-tests.ps1

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,28 @@ go install gotest.tools/gotestsum
2525
gotestsum --version
2626

2727
$env:TEST_BINARY_NAME = "elastic-agent"
28-
if (-not $env:AGENT_VERSION) {
29-
# Parsing version.go. Will be simplified here: https://github.com/elastic/ingest-dev/issues/4925
30-
$AGENT_VERSION = (Get-Content version/version.go | Select-String -Pattern 'const defaultBeatVersion =' | ForEach-Object { $_ -replace '.*?"(.*?)".*', '$1' })
31-
$env:AGENT_VERSION = $AGENT_VERSION + "-SNAPSHOT"
28+
29+
if (-not $env:AGENT_VERSION)
30+
{
31+
if (Test-Path .package-version)
32+
{
33+
$packageContent = Get-Content .package-version -Raw | ConvertFrom-Json
34+
$env:AGENT_VERSION = $packageContent.version
35+
Write-Output "~~~ Agent version: $env:AGENT_VERSION (from .package-version)"
36+
}
37+
else
38+
{
39+
# Parsing version.go. Will be simplified here: https://github.com/elastic/ingest-dev/issues/4925
40+
$AGENT_VERSION = (Get-Content version/version.go | Select-String -Pattern 'const defaultBeatVersion =' | ForEach-Object { $_ -replace '.*?"(.*?)".*', '$1' })
41+
$env:AGENT_VERSION = $AGENT_VERSION + "-SNAPSHOT"
42+
Write-Output "~~~ Agent version: $env:AGENT_VERSION (from version/version.go)"
43+
}
44+
}
45+
else
46+
{
47+
Write-Output "~~~ Agent version: $env:AGENT_VERSION (specified by env var)"
3248
}
3349

34-
Write-Output "~~~ Agent version: $env:AGENT_VERSION"
3550
$env:SNAPSHOT = $true
3651

3752
Write-Host "~~~ Running integration tests as $env:USERNAME"

.buildkite/scripts/buildkite-integration-tests.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,20 @@ echo "~~~ Running integration tests as $USER"
3838
make install-gotestsum
3939

4040
if [[ -z "${AGENT_VERSION:-}" ]]; then
41-
# Parsing version.go. Will be simplified here: https://github.com/elastic/ingest-dev/issues/4925
42-
AGENT_VERSION=$(grep "const defaultBeatVersion =" version/version.go | cut -d\" -f2)
43-
AGENT_VERSION="${AGENT_VERSION}-SNAPSHOT"
41+
if [[ -f "${WORKSPACE}/.package-version" ]]; then
42+
AGENT_VERSION="$(jq -r '.version' .package-version)"
43+
echo "~~~ Agent version: ${AGENT_VERSION} (from .package-version)"
44+
else
45+
AGENT_VERSION=$(grep "const defaultBeatVersion =" version/version.go | cut -d\" -f2)
46+
AGENT_VERSION="${AGENT_VERSION}-SNAPSHOT"
47+
echo "~~~ Agent version: ${AGENT_VERSION} (from version/version.go)"
48+
fi
49+
50+
export AGENT_VERSION
51+
else
52+
echo "~~~ Agent version: ${AGENT_VERSION} (specified by env var)"
4453
fi
4554

46-
export AGENT_VERSION
47-
echo "~~~ Agent version: ${AGENT_VERSION}"
48-
4955
os_data=$(uname -spr | tr ' ' '_')
5056
root_suffix=""
5157
if [ "$TEST_SUDO" == "true" ]; then

.buildkite/scripts/buildkite-k8s-integration-tests.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@ DOCKER_VARIANTS="${DOCKER_VARIANTS:-basic,wolfi,complete,complete-wolfi,service,
99
CLUSTER_NAME="${K8S_VERSION}-kubernetes"
1010

1111
if [[ -z "${AGENT_VERSION:-}" ]]; then
12-
# If not specified, use the version in version/version.go
13-
AGENT_VERSION="$(grep "const defaultBeatVersion =" version/version.go | cut -d\" -f2)"
14-
AGENT_VERSION="${AGENT_VERSION}-SNAPSHOT"
12+
if [[ -f "${WORKSPACE}/.package-version" ]]; then
13+
AGENT_VERSION="$(jq -r '.version' .package-version)"
14+
echo "~~~ Agent version: ${AGENT_VERSION} (from .package-version)"
15+
else
16+
AGENT_VERSION="$(grep "const defaultBeatVersion =" version/version.go | cut -d\" -f2)"
17+
AGENT_VERSION="${AGENT_VERSION}-SNAPSHOT"
18+
echo "~~~ Agent version: ${AGENT_VERSION} (from version/version.go)"
19+
fi
20+
21+
export AGENT_VERSION
22+
else
23+
echo "~~~ Agent version: ${AGENT_VERSION} (specified by env var)"
1524
fi
1625

1726
echo "~~~ Create kind cluster '${CLUSTER_NAME}'"

.buildkite/scripts/steps/ess.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
function ess_up {
22
param (
33
[string]$StackVersion,
4+
[string]$StackBuildId = "",
45
[string]$EssRegion = "gcp-us-west2"
56
)
67

@@ -22,6 +23,7 @@ function ess_up {
2223
& terraform init
2324
& terraform apply -auto-approve `
2425
-var="stack_version=$StackVersion" `
26+
-var="stack_build_id=$StackBuildId" `
2527
-var="ess_region=$EssRegion" `
2628
-var="creator=$BuildkiteBuildCreator" `
2729
-var="buildkite_id=$BuildkiteBuildNumber" `
@@ -99,12 +101,13 @@ function Retry-Command {
99101

100102
function Get-Ess-Stack {
101103
param (
102-
[string]$StackVersion
104+
[string]$StackVersion,
105+
[string]$StackBuildId = ""
103106
)
104107

105108
if ($Env:BUILDKITE_RETRY_COUNT -gt 0) {
106109
Write-Output "The step is retried, starting the ESS stack again"
107-
ess_up $StackVersion
110+
ess_up $StackVersion $StackBuildId
108111
Write-Output "ESS stack is up. ES_HOST: $Env:ELASTICSEARCH_HOST"
109112
} else {
110113
# TODO: Use a metadata prefix for "fips." if we ever need to test Windows artifacts for FIPS.

.buildkite/scripts/steps/ess.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ function ess_up() {
66
local WORKSPACE=$(git rev-parse --show-toplevel)
77
local TF_DIR="${WORKSPACE}/test_infra/ess/"
88
local STACK_VERSION=$1
9-
local ESS_REGION=${2:-"gcp-us-west2"}
9+
local STACK_BUILD_ID=${2:-""}
10+
local ESS_REGION=${3:-"gcp-us-west2"}
1011

1112
if [ -z "$STACK_VERSION" ]; then
1213
echo "Error: Specify stack version: ess_up [stack_version]" >&2
@@ -22,6 +23,7 @@ function ess_up() {
2223
terraform apply \
2324
-auto-approve \
2425
-var="stack_version=${STACK_VERSION}" \
26+
-var="stack_build_id=${STACK_BUILD_ID}" \
2527
-var="ess_region=${ESS_REGION}" \
2628
-var="creator=${BUILDKITE_BUILD_CREATOR}" \
2729
-var="buildkite_id=${BUILDKITE_BUILD_NUMBER}" \

.buildkite/scripts/steps/ess_start.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ set -euo pipefail
44
source .buildkite/scripts/steps/ess.sh
55
source .buildkite/scripts/steps/fleet.sh
66

7-
OVERRIDE_STACK_VERSION="$(cat .package-version)"
8-
OVERRIDE_STACK_VERSION=${OVERRIDE_STACK_VERSION}"-SNAPSHOT"
7+
STACK_VERSION="$(jq -r '.version' .package-version)"
8+
STACK_BUILD_ID="$(jq -r '.stack_build_id' .package-version)"
99

10-
ess_up $OVERRIDE_STACK_VERSION
10+
ess_up "$STACK_VERSION" "$STACK_BUILD_ID"
1111

1212
preinstall_fleet_packages
1313

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
source .buildkite/scripts/common.sh
5+
6+
echo "~~~ Pushing cloud image"
7+
8+
suffix=""
9+
if [ "${FIPS:-false}" == "true" ]; then
10+
suffix="-fips"
11+
fi
12+
13+
CI_ELASTIC_AGENT_DOCKER_IMAGE="docker.elastic.co/beats-ci/elastic-agent-cloud${suffix}"
14+
export CI_ELASTIC_AGENT_DOCKER_IMAGE
15+
echo "CI_ELASTIC_AGENT_DOCKER_IMAGE: ${CI_ELASTIC_AGENT_DOCKER_IMAGE}"
16+
17+
18+
export CUSTOM_IMAGE_TAG="git-${BUILDKITE_COMMIT:0:12}"
19+
export USE_PACKAGE_VERSION="true"
20+
21+
mage cloud:push

.buildkite/scripts/steps/integration-package.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ source .buildkite/scripts/common.sh
55

66
export SNAPSHOT="true"
77
export EXTERNAL="true"
8+
export USE_PACKAGE_VERSION="true"
89

910
mage package

.buildkite/scripts/steps/integration_tests.sh

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,9 @@ STACK_PROVISIONER="${1:-"stateful"}"
77
MAGE_TARGET="${2:-"integration:test"}"
88
MAGE_SUBTARGET="${3:-""}"
99

10-
11-
# Override the stack version from `.package-version` contents
12-
# There is a time when the current snapshot is not available on cloud yet, so we cannot use the latest version automatically
13-
# This file is managed by an automation (mage integration:UpdateAgentPackageVersion) that check if the snapshot is ready.
14-
15-
STACK_VERSION="$(cat .package-version)"
16-
if [[ -n "$STACK_VERSION" ]]; then
17-
STACK_VERSION=${STACK_VERSION}"-SNAPSHOT"
18-
fi
19-
2010
# Run integration tests
2111
set +e
22-
AGENT_STACK_VERSION="${STACK_VERSION}" TEST_INTEG_CLEAN_ON_EXIT=true STACK_PROVISIONER="$STACK_PROVISIONER" SNAPSHOT=true mage $MAGE_TARGET $MAGE_SUBTARGET
12+
USE_PACKAGE_VERSION=true TEST_INTEG_CLEAN_ON_EXIT=true STACK_PROVISIONER="$STACK_PROVISIONER" SNAPSHOT=true mage $MAGE_TARGET $MAGE_SUBTARGET
2313
TESTS_EXIT_STATUS=$?
2414
set -e
2515

0 commit comments

Comments
 (0)