Skip to content

Commit 3ab8d1f

Browse files
pkoutsovasilismergify[bot]
authored andcommitted
ci: pin elastic-agent version (#8736)
* ci: pin elastic-agent version * ci: override BEAT_VERSION * ci: fix mage cloud:load and cloud:push (cherry picked from commit 5c5b174) # Conflicts: # .buildkite/bk.integration-fips.pipeline.yml # .buildkite/bk.integration.pipeline.yml # .buildkite/scripts/buildkite-integration-tests.sh # magefile.go
1 parent 1cd6b96 commit 3ab8d1f

File tree

8 files changed

+279
-21
lines changed

8 files changed

+279
-21
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json
2+
3+
env:
4+
ASDF_MAGE_VERSION: 1.14.0
5+
MS_GOTOOLCHAIN_TELEMETRY_ENABLED: "0"
6+
7+
IMAGE_UBUNTU_2404_X86_64: "platform-ingest-elastic-agent-ubuntu-2404-1750467641"
8+
IMAGE_UBUNTU_X86_64_FIPS: "platform-ingest-elastic-agent-ubuntu-2204-fips-1750467641"
9+
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"
12+
13+
steps:
14+
- label: Build and push custom elastic-agent image
15+
depends_on:
16+
- 'packaging-containers-x86-64-fips' # Reuse artifacts produced in .buildkite/integration.pipeline.yml
17+
key: integration-fips-cloud-image
18+
env:
19+
FIPS: "true"
20+
CUSTOM_IMAGE_TAG: "git-${BUILDKITE_COMMIT:0:12}"
21+
CI_ELASTIC_AGENT_DOCKER_IMAGE: "docker.elastic.co/beats-ci/elastic-agent-cloud-fips"
22+
TF_VAR_integration_server_docker_image: "docker.elastic.co/beats-ci/elastic-agent-cloud-fips:git-${BUILDKITE_COMMIT:0:12}"
23+
command: |
24+
buildkite-agent artifact download build/distributions/elastic-agent-cloud-fips-*-linux-amd64.docker.tar.gz . --step 'packaging-containers-x86-64-fips'
25+
mage cloud:load
26+
mage cloud:push
27+
agents:
28+
provider: "gcp"
29+
machineType: "n1-standard-8"
30+
image: "${IMAGE_UBUNTU_2404_X86_64}"
31+
plugins:
32+
- elastic/vault-docker-login#v0.5.2:
33+
secret_path: 'kv/ci-shared/platform-ingest/elastic_docker_registry'
34+
35+
- label: Start ESS stack for FIPS integration tests
36+
key: integration-fips-ess
37+
depends_on:
38+
- integration-fips-cloud-image
39+
env:
40+
ASDF_TERRAFORM_VERSION: 1.9.2
41+
TF_VAR_integration_server_docker_image: "docker.elastic.co/beats-ci/elastic-agent-cloud-fips:git-${BUILDKITE_COMMIT:0:12}"
42+
command: |
43+
source .buildkite/scripts/steps/ess_start.sh
44+
artifact_paths:
45+
- test_infra/ess/*.tfstate
46+
- test_infra/ess/*.lock.hcl
47+
agents:
48+
image: "docker.elastic.co/ci-agent-images/platform-ingest/buildkite-agent-beats-ci-with-hooks:0.5"
49+
useCustomGlobalHooks: true
50+
51+
- group: "fips:Stateful:Ubuntu"
52+
key: integration-tests-ubuntu-fips
53+
depends_on:
54+
- integration-fips-ess
55+
steps:
56+
- label: "fips:x86_64:sudo-{{matrix.sudo}}:{{matrix.groups}}"
57+
depends_on:
58+
- packaging-ubuntu-x86-64-fips # Reuse artifacts produced in .buildkite/integration.pipeline.yml
59+
env:
60+
FIPS: "true"
61+
TF_VAR_integration_server_docker_image: "docker.elastic.co/beats-ci/elastic-agent-cloud-fips:git-${BUILDKITE_COMMIT:0:12}"
62+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
63+
command: |
64+
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-x86-64-fips'
65+
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix.groups}} {{matrix.sudo}}
66+
artifact_paths:
67+
- build/**
68+
- build/diagnostics/**
69+
retry:
70+
automatic:
71+
limit: 1
72+
agents:
73+
provider: "aws"
74+
image: "${IMAGE_UBUNTU_X86_64_FIPS}"
75+
instanceType: "m5.2xlarge"
76+
matrix:
77+
setup:
78+
sudo:
79+
- "false"
80+
- "true"
81+
groups:
82+
- fleet # currently there is only a single test in the fleet group, add more tests once they have been defined
83+
84+
- label: "fips:arm64:sudo-{{matrix.sudo}}:{{matrix.groups}}"
85+
depends_on:
86+
- packaging-ubuntu-arm64-fips
87+
env:
88+
FIPS: "true"
89+
TF_VAR_integration_server_docker_image: "docker.elastic.co/beats-ci/elastic-agent-cloud-fips:git-${BUILDKITE_COMMIT:0:12}"
90+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
91+
command: |
92+
buildkite-agent artifact download build/distributions/** . --step 'packaging-ubuntu-arm64-fips'
93+
.buildkite/scripts/steps/integration_tests_tf.sh {{matrix.groups}} {{matrix.sudo}}
94+
artifact_paths:
95+
- build/**
96+
- build/diagnostics/**
97+
retry:
98+
automatic:
99+
limit: 1
100+
agents:
101+
provider: "aws"
102+
image: "${IMAGE_UBUNTU_ARM64_FIPS}"
103+
instanceType: "m6g.2xlarge"
104+
matrix:
105+
setup:
106+
sudo:
107+
- "false"
108+
- "true"
109+
groups:
110+
- fleet
111+
112+
- label: "fips:upgrade-ech-deployment"
113+
if: build.env("BUILDKITE_PULL_REQUEST") != "false" && build.env("GITHUB_PR_LABELS") =~ /.*(Testing:run:TestUpgradeIntegrationsServer).*/
114+
env:
115+
FIPS: "true"
116+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
117+
command: |
118+
export EC_API_KEY=$(retry -t 5 -- vault kv get -field=apiKey kv/ci-shared/platform-ingest/platform-ingest-ec-prod)
119+
.buildkite/scripts/buildkite-integration-tests.sh ech-deployment false
120+
artifact_paths:
121+
- build/**
122+
- build/diagnostics/**
123+
retry:
124+
automatic:
125+
limit: 1
126+
agents:
127+
provider: "aws"
128+
image: "${IMAGE_UBUNTU_X86_64_FIPS}"
129+
instanceType: "m5.2xlarge"
130+
131+
- label: ESS FIPS stack cleanup
132+
depends_on:
133+
- integration-tests-ubuntu-fips
134+
allow_dependency_failure: true
135+
command: |
136+
buildkite-agent artifact download "test_infra/ess/**" . --step "integration-fips-ess"
137+
ls -lah test_infra/ess
138+
.buildkite/scripts/steps/ess_down.sh
139+
agents:
140+
image: "docker.elastic.co/ci-agent-images/platform-ingest/buildkite-agent-beats-ci-with-hooks:0.5"
141+
useCustomGlobalHooks: true
142+
143+
- label: Aggregate test reports
144+
depends_on:
145+
- integration-tests-ubuntu-fips
146+
allow_dependency_failure: true
147+
command: |
148+
buildkite-agent artifact download "build/*.xml" .
149+
agents:
150+
image: "docker.elastic.co/ci-agent-images/platform-ingest/buildkite-agent-beats-ci-with-hooks:0.5"
151+
useCustomGlobalHooks: true
152+
soft_fail:
153+
- exit_status: "*"
154+
plugins:
155+
- elastic/vault-secrets#v0.1.0:
156+
path: "kv/ci-shared/platform-ingest/buildkite_analytics_token"
157+
field: "token"
158+
env_var: "BUILDKITE_ANALYTICS_TOKEN"
159+
- test-collector#v1.11.0:
160+
files: "build/*.xml"
161+
format: "junit"
162+
branches: "main"
163+
debug: true

.buildkite/bk.integration.pipeline.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@ env:
66

77
# The following images are defined here and their values will be updated by updatecli
88
# Please do not change them manually.
9+
<<<<<<< HEAD
910
IMAGE_UBUNTU_2404_X86_64: "platform-ingest-elastic-agent-ubuntu-2404-1749258065"
1011
IMAGE_UBUNTU_2404_ARM_64: "platform-ingest-elastic-agent-ubuntu-2404-aarch64-1749258065"
1112
IMAGE_RHEL_8: "platform-ingest-elastic-agent-rhel-8-1749258065"
1213
IMAGE_DEBIAN_12: "platform-ingest-elastic-agent-debian-12-1749258065"
1314
IMAGE_WIN_2022: "platform-ingest-elastic-agent-windows-2022-1749258065"
1415
IMAGE_WIN_2025: "platform-ingest-elastic-agent-windows-2025-1749258065"
16+
=======
17+
IMAGE_UBUNTU_2404_X86_64: "platform-ingest-elastic-agent-ubuntu-2404-1750467641"
18+
IMAGE_UBUNTU_2404_ARM_64: "platform-ingest-elastic-agent-ubuntu-2404-aarch64-1750467641"
19+
IMAGE_RHEL_8: "platform-ingest-elastic-agent-rhel-8-1750467641"
20+
IMAGE_DEBIAN_12: "platform-ingest-elastic-agent-debian-12-1750467641"
21+
IMAGE_WIN_2022: "platform-ingest-elastic-agent-windows-2022-1750467641"
22+
IMAGE_WIN_2025: "platform-ingest-elastic-agent-windows-2025-1750467641"
23+
# Remove AGENT_PACKAGE_VERSION and AGENT_VERSION pinning once 9.2.0 DRA and stack are released
24+
AGENT_VERSION: "9.1.0-SNAPSHOT"
25+
26+
>>>>>>> 5c5b174ae (ci: pin elastic-agent version (#8736))
1527

1628
# This section is used to define the plugins that will be used in the pipeline.
1729
# 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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,18 @@ echo "~~~ Running integration tests as $USER"
3232

3333
make install-gotestsum
3434

35+
<<<<<<< HEAD
3536
# Parsing version.go. Will be simplified here: https://github.com/elastic/ingest-dev/issues/4925
3637
AGENT_VERSION=$(grep "const defaultBeatVersion =" version/version.go | cut -d\" -f2)
3738
AGENT_VERSION="${AGENT_VERSION}-SNAPSHOT"
39+
=======
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
45+
46+
>>>>>>> 5c5b174ae (ci: pin elastic-agent version (#8736))
3847
export AGENT_VERSION
3948
echo "~~~ Agent version: ${AGENT_VERSION}"
4049

.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: 81 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -818,50 +818,115 @@ func (Cloud) Image(ctx context.Context) {
818818
Package(ctx)
819819
}
820820

821+
<<<<<<< HEAD
822+
=======
823+
// Load loads an artifact as a docker image.
824+
// 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
825+
// DOCKER_IMPORT_SOURCE - override source for import
826+
func (Cloud) Load() error {
827+
agentVersion, err := mage.AgentPackageVersion()
828+
if err != nil {
829+
return fmt.Errorf("failed to get agent package version: %w", err)
830+
}
831+
832+
// Need to get the FIPS env var flag to see if we are using the normal source cloud image name, or the FIPS variant
833+
fips := os.Getenv(fipsEnv)
834+
defer os.Setenv(fipsEnv, fips)
835+
fipsVal, err := strconv.ParseBool(fips)
836+
if err != nil {
837+
fipsVal = false
838+
}
839+
if err := os.Setenv(fipsEnv, strconv.FormatBool(fipsVal)); err != nil {
840+
return fmt.Errorf("failed to set fips env var: %w", err)
841+
}
842+
devtools.FIPSBuild = fipsVal
843+
844+
source := "build/distributions/elastic-agent-cloud-" + agentVersion + "-SNAPSHOT-linux-" + runtime.GOARCH + ".docker.tar.gz"
845+
if fipsVal {
846+
source = "build/distributions/elastic-agent-cloud-fips-" + agentVersion + "-SNAPSHOT-linux-" + runtime.GOARCH + ".docker.tar.gz"
847+
}
848+
if envSource, ok := os.LookupEnv("DOCKER_IMPORT_SOURCE"); ok && envSource != "" {
849+
source = envSource
850+
}
851+
852+
return sh.RunV("docker", "image", "load", "-i", source)
853+
}
854+
855+
>>>>>>> 5c5b174ae (ci: pin elastic-agent version (#8736))
821856
// Push builds a cloud image tags it correctly and pushes to remote image repo.
822857
// Previous login to elastic registry is required!
823858
func (Cloud) Push() error {
824-
snapshot := os.Getenv(snapshotEnv)
825-
defer os.Setenv(snapshotEnv, snapshot)
859+
agentVersion, err := mage.AgentPackageVersion()
860+
if err != nil {
861+
return fmt.Errorf("failed to get agent package version: %w", err)
862+
}
826863

827-
os.Setenv(snapshotEnv, "true")
864+
<<<<<<< HEAD
865+
sourceCloudImageName := fmt.Sprintf("docker.elastic.co/beats-ci/elastic-agent-cloud:%s", version)
866+
=======
867+
// Need to get the FIPS env var flag to see if we are using the normal source cloud image name, or the FIPS variant
868+
fips := os.Getenv(fipsEnv)
869+
defer os.Setenv(fipsEnv, fips)
870+
fipsVal, err := strconv.ParseBool(fips)
871+
if err != nil {
872+
fipsVal = false
873+
}
874+
if err := os.Setenv(fipsEnv, strconv.FormatBool(fipsVal)); err != nil {
875+
return fmt.Errorf("failed to set fips env var: %w", err)
876+
}
877+
devtools.FIPSBuild = fipsVal
828878

829-
version := getVersion()
830-
var tag string
879+
sourceCloudImageName := fmt.Sprintf("docker.elastic.co/beats-ci/elastic-agent-cloud:%s-SNAPSHOT", agentVersion)
880+
if fipsVal {
881+
sourceCloudImageName = fmt.Sprintf("docker.elastic.co/beats-ci/elastic-agent-cloud-fips:%s-SNAPSHOT", agentVersion)
882+
}
883+
var targetTag string
831884
if envTag, isPresent := os.LookupEnv("CUSTOM_IMAGE_TAG"); isPresent && len(envTag) > 0 {
832-
tag = envTag
885+
targetTag = envTag
833886
} else {
834-
commit := dockerCommitHash()
835-
time := time.Now().Unix()
836-
837-
tag = fmt.Sprintf("%s-%s-%d", version, commit, time)
887+
targetTag = fmt.Sprintf("%s-%s-%d", agentVersion, dockerCommitHash(), time.Now().Unix())
838888
}
839-
840-
sourceCloudImageName := fmt.Sprintf("docker.elastic.co/beats-ci/elastic-agent-cloud:%s", version)
889+
>>>>>>> 5c5b174ae (ci: pin elastic-agent version (#8736))
841890
var targetCloudImageName string
842891
if customImage, isPresent := os.LookupEnv("CI_ELASTIC_AGENT_DOCKER_IMAGE"); isPresent && len(customImage) > 0 {
843-
targetCloudImageName = fmt.Sprintf("%s:%s", customImage, tag)
892+
targetCloudImageName = fmt.Sprintf("%s:%s", customImage, targetTag)
844893
} else {
845-
targetCloudImageName = fmt.Sprintf(cloudImageTmpl, tag)
894+
targetCloudImageName = fmt.Sprintf(cloudImageTmpl, targetTag)
846895
}
847896

848897
fmt.Printf(">> Setting a docker image tag to %s\n", targetCloudImageName)
849898
err := sh.RunV("docker", "tag", sourceCloudImageName, targetCloudImageName)
850899
if err != nil {
851-
return fmt.Errorf("Failed setting a docker image tag: %w", err)
900+
return fmt.Errorf("failed setting a docker image tag: %w", err)
852901
}
853902
fmt.Println(">> Docker image tag updated successfully")
854903

855904
fmt.Println(">> Pushing a docker image to remote registry")
856905
err = sh.RunV("docker", "image", "push", targetCloudImageName)
857906
if err != nil {
858-
return fmt.Errorf("Failed pushing docker image: %w", err)
907+
return fmt.Errorf("failed pushing docker image: %w", err)
859908
}
860909
fmt.Printf(">> Docker image pushed to remote registry successfully: %s\n", targetCloudImageName)
861910

862911
return nil
863912
}
864913

914+
<<<<<<< HEAD
915+
=======
916+
// Create a new devmachine that will be auto-deleted in 6 hours.
917+
// Example: MACHINE_IMAGE="family/platform-ingest-elastic-agent-ubuntu-2204" ZONE="us-central1-a" mage devmachine:create "pavel-dev-machine"
918+
// ZONE defaults to 'us-central1-a', MACHINE_IMAGE defaults to 'family/platform-ingest-elastic-agent-ubuntu-2204'
919+
func (Devmachine) Create(instanceName string) error {
920+
if instanceName == "" {
921+
return errors.New(
922+
`instanceName is required.
923+
Example:
924+
mage devmachine:create "pavel-dev-machine" `)
925+
}
926+
return devmachine.Run(instanceName)
927+
}
928+
929+
>>>>>>> 5c5b174ae (ci: pin elastic-agent version (#8736))
865930
func Clean() {
866931
mg.Deps(devtools.Clean, Build.Clean)
867932
}

testing/integration/upgrade_broken_package_test.go

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

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

0 commit comments

Comments
 (0)