Skip to content

Commit 5c5b174

Browse files
ci: pin elastic-agent version (#8736)
* ci: pin elastic-agent version * ci: override BEAT_VERSION * ci: fix mage cloud:load and cloud:push
1 parent 230c98d commit 5c5b174

File tree

8 files changed

+52
-38
lines changed

8 files changed

+52
-38
lines changed

.buildkite/bk.integration-fips.pipeline.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ env:
77
IMAGE_UBUNTU_2404_X86_64: "platform-ingest-elastic-agent-ubuntu-2404-1750467641"
88
IMAGE_UBUNTU_X86_64_FIPS: "platform-ingest-elastic-agent-ubuntu-2204-fips-1750467641"
99
IMAGE_UBUNTU_ARM64_FIPS: "platform-ingest-elastic-agent-ubuntu-2204-fips-aarch64-1750467641"
10+
# Remove AGENT_PACKAGE_VERSION and AGENT_VERSION pinning once 9.2.0 DRA and stack are released
11+
AGENT_VERSION: "9.1.0-SNAPSHOT"
1012

1113
steps:
1214
- label: Build and push custom elastic-agent image

.buildkite/bk.integration.pipeline.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ env:
1212
IMAGE_DEBIAN_12: "platform-ingest-elastic-agent-debian-12-1750467641"
1313
IMAGE_WIN_2022: "platform-ingest-elastic-agent-windows-2022-1750467641"
1414
IMAGE_WIN_2025: "platform-ingest-elastic-agent-windows-2025-1750467641"
15+
# Remove AGENT_PACKAGE_VERSION and AGENT_VERSION pinning once 9.2.0 DRA and stack are released
16+
AGENT_VERSION: "9.1.0-SNAPSHOT"
17+
1518

1619
# This section is used to define the plugins that will be used in the pipeline.
1720
# See https://buildkite.com/docs/pipelines/integrations/plugins/using#using-yaml-anchors-with-plugins

.buildkite/integration.pipeline.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
env:
44
VAULT_PATH: "kv/ci-shared/observability-ingest/cloud/gcp"
5+
# Remove AGENT_PACKAGE_VERSION and AGENT_VERSION pinning once 9.2.0 DRA and stack are released
6+
AGENT_PACKAGE_VERSION: "9.1.0"
7+
BEAT_VERSION: "9.1.0"
58

69
steps:
710
- group: "Integration tests: packaging"

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

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

2727
$env:TEST_BINARY_NAME = "elastic-agent"
28-
# Parsing version.go. Will be simplified here: https://github.com/elastic/ingest-dev/issues/4925
29-
$AGENT_VERSION = (Get-Content version/version.go | Select-String -Pattern 'const defaultBeatVersion =' | ForEach-Object { $_ -replace '.*?"(.*?)".*', '$1' })
30-
$env:AGENT_VERSION = $AGENT_VERSION + "-SNAPSHOT"
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"
32+
}
3133

3234
Write-Output "~~~ Agent version: $env:AGENT_VERSION"
3335
$env:SNAPSHOT = $true

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ echo "~~~ Running integration tests as $USER"
3737

3838
make install-gotestsum
3939

40-
# Parsing version.go. Will be simplified here: https://github.com/elastic/ingest-dev/issues/4925
41-
AGENT_VERSION=$(grep "const defaultBeatVersion =" version/version.go | cut -d\" -f2)
42-
AGENT_VERSION="${AGENT_VERSION}-SNAPSHOT"
40+
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"
44+
fi
4345

4446
export AGENT_VERSION
4547
echo "~~~ Agent version: ${AGENT_VERSION}"

.buildkite/scripts/common.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ fi
99
if [[ -z "${SETUP_GVM_VERSION-""}" ]]; then
1010
SETUP_GVM_VERSION="v0.5.2" # https://github.com/andrewkroh/gvm/issues/44#issuecomment-1013231151
1111
fi
12-
BEAT_VERSION=$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+(\-[a-zA-Z]+[0-9]+)?' "${WORKSPACE}/version/version.go")
13-
export BEAT_VERSION
12+
13+
if [[ -z "${BEAT_VERSION-""}" ]]; then
14+
BEAT_VERSION=$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+(\-[a-zA-Z]+[0-9]+)?' "${WORKSPACE}/version/version.go")
15+
export BEAT_VERSION
16+
fi
1417

1518
getOSOptions() {
1619
case $(uname | tr '[:upper:]' '[:lower:]') in

magefile.go

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -996,11 +996,10 @@ func (Cloud) Image(ctx context.Context) {
996996
// Looks in build/distributions for an elastic-agent-cloud*.docker.tar.gz artifact and imports it as docker.elastic.co/beats-ci/elastic-agent-cloud:$VERSION
997997
// DOCKER_IMPORT_SOURCE - override source for import
998998
func (Cloud) Load() error {
999-
snapshot := os.Getenv(snapshotEnv)
1000-
defer os.Setenv(snapshotEnv, snapshot)
1001-
os.Setenv(snapshotEnv, "true")
1002-
1003-
version := getVersion()
999+
agentVersion, err := mage.AgentPackageVersion()
1000+
if err != nil {
1001+
return fmt.Errorf("failed to get agent package version: %w", err)
1002+
}
10041003

10051004
// Need to get the FIPS env var flag to see if we are using the normal source cloud image name, or the FIPS variant
10061005
fips := os.Getenv(fipsEnv)
@@ -1009,12 +1008,14 @@ func (Cloud) Load() error {
10091008
if err != nil {
10101009
fipsVal = false
10111010
}
1012-
os.Setenv(fipsEnv, strconv.FormatBool(fipsVal))
1011+
if err := os.Setenv(fipsEnv, strconv.FormatBool(fipsVal)); err != nil {
1012+
return fmt.Errorf("failed to set fips env var: %w", err)
1013+
}
10131014
devtools.FIPSBuild = fipsVal
10141015

1015-
source := "build/distributions/elastic-agent-cloud-" + version + "-linux-" + runtime.GOARCH + ".docker.tar.gz"
1016+
source := "build/distributions/elastic-agent-cloud-" + agentVersion + "-SNAPSHOT-linux-" + runtime.GOARCH + ".docker.tar.gz"
10161017
if fipsVal {
1017-
source = "build/distributions/elastic-agent-cloud-fips-" + version + "-linux-" + runtime.GOARCH + ".docker.tar.gz"
1018+
source = "build/distributions/elastic-agent-cloud-fips-" + agentVersion + "-SNAPSHOT-linux-" + runtime.GOARCH + ".docker.tar.gz"
10181019
}
10191020
if envSource, ok := os.LookupEnv("DOCKER_IMPORT_SOURCE"); ok && envSource != "" {
10201021
source = envSource
@@ -1026,20 +1027,9 @@ func (Cloud) Load() error {
10261027
// Push builds a cloud image tags it correctly and pushes to remote image repo.
10271028
// Previous login to elastic registry is required!
10281029
func (Cloud) Push() error {
1029-
snapshot := os.Getenv(snapshotEnv)
1030-
defer os.Setenv(snapshotEnv, snapshot)
1031-
1032-
os.Setenv(snapshotEnv, "true")
1033-
1034-
version := getVersion()
1035-
var tag string
1036-
if envTag, isPresent := os.LookupEnv("CUSTOM_IMAGE_TAG"); isPresent && len(envTag) > 0 {
1037-
tag = envTag
1038-
} else {
1039-
commit := dockerCommitHash()
1040-
time := time.Now().Unix()
1041-
1042-
tag = fmt.Sprintf("%s-%s-%d", version, commit, time)
1030+
agentVersion, err := mage.AgentPackageVersion()
1031+
if err != nil {
1032+
return fmt.Errorf("failed to get agent package version: %w", err)
10431033
}
10441034

10451035
// Need to get the FIPS env var flag to see if we are using the normal source cloud image name, or the FIPS variant
@@ -1049,38 +1039,46 @@ func (Cloud) Push() error {
10491039
if err != nil {
10501040
fipsVal = false
10511041
}
1052-
os.Setenv(fipsEnv, strconv.FormatBool(fipsVal))
1042+
if err := os.Setenv(fipsEnv, strconv.FormatBool(fipsVal)); err != nil {
1043+
return fmt.Errorf("failed to set fips env var: %w", err)
1044+
}
10531045
devtools.FIPSBuild = fipsVal
10541046

1055-
sourceCloudImageName := fmt.Sprintf("docker.elastic.co/beats-ci/elastic-agent-cloud:%s", version)
1047+
sourceCloudImageName := fmt.Sprintf("docker.elastic.co/beats-ci/elastic-agent-cloud:%s-SNAPSHOT", agentVersion)
10561048
if fipsVal {
1057-
sourceCloudImageName = fmt.Sprintf("docker.elastic.co/beats-ci/elastic-agent-cloud-fips:%s", version)
1049+
sourceCloudImageName = fmt.Sprintf("docker.elastic.co/beats-ci/elastic-agent-cloud-fips:%s-SNAPSHOT", agentVersion)
1050+
}
1051+
var targetTag string
1052+
if envTag, isPresent := os.LookupEnv("CUSTOM_IMAGE_TAG"); isPresent && len(envTag) > 0 {
1053+
targetTag = envTag
1054+
} else {
1055+
targetTag = fmt.Sprintf("%s-%s-%d", agentVersion, dockerCommitHash(), time.Now().Unix())
10581056
}
10591057
var targetCloudImageName string
10601058
if customImage, isPresent := os.LookupEnv("CI_ELASTIC_AGENT_DOCKER_IMAGE"); isPresent && len(customImage) > 0 {
1061-
targetCloudImageName = fmt.Sprintf("%s:%s", customImage, tag)
1059+
targetCloudImageName = fmt.Sprintf("%s:%s", customImage, targetTag)
10621060
} else {
1063-
targetCloudImageName = fmt.Sprintf(cloudImageTmpl, tag)
1061+
targetCloudImageName = fmt.Sprintf(cloudImageTmpl, targetTag)
10641062
}
10651063

10661064
fmt.Printf(">> Setting a docker image tag to %s\n", targetCloudImageName)
10671065
err = sh.RunV("docker", "tag", sourceCloudImageName, targetCloudImageName)
10681066
if err != nil {
1069-
return fmt.Errorf("Failed setting a docker image tag: %w", err)
1067+
return fmt.Errorf("failed setting a docker image tag: %w", err)
10701068
}
10711069
fmt.Println(">> Docker image tag updated successfully")
10721070

10731071
fmt.Println(">> Pushing a docker image to remote registry")
10741072
err = sh.RunV("docker", "image", "push", targetCloudImageName)
10751073
if err != nil {
1076-
return fmt.Errorf("Failed pushing docker image: %w", err)
1074+
return fmt.Errorf("failed pushing docker image: %w", err)
10771075
}
10781076
fmt.Printf(">> Docker image pushed to remote registry successfully: %s\n", targetCloudImageName)
10791077

10801078
return nil
10811079
}
10821080

1083-
// Creates a new devmachine that will be auto-deleted in 6 hours.
1081+
// Create a new devmachine that will be auto-deleted in 6 hours.
10841082
// Example: MACHINE_IMAGE="family/platform-ingest-elastic-agent-ubuntu-2204" ZONE="us-central1-a" mage devmachine:create "pavel-dev-machine"
10851083
// ZONE defaults to 'us-central1-a', MACHINE_IMAGE defaults to 'family/platform-ingest-elastic-agent-ubuntu-2204'
10861084
func (Devmachine) Create(instanceName string) error {

testing/integration/ess/upgrade_broken_package_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestUpgradeBrokenPackageVersion(t *testing.T) {
3232
Local: false, // requires Agent installation
3333
Sudo: true, // requires Agent installation
3434
})
35+
t.Skip("Skip this test until elastic agent version pinning is removed from Integration test runs on CI")
3536

3637
ctx, cancel := testcontext.WithDeadline(t, context.Background(), time.Now().Add(10*time.Minute))
3738
defer cancel()

0 commit comments

Comments
 (0)