Skip to content

Commit 1557353

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/scripts/buildkite-integration-tests.sh # magefile.go
1 parent 1cf3603 commit 1557353

File tree

8 files changed

+270
-21
lines changed

8 files changed

+270
-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: 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: 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
@@ -877,50 +877,115 @@ func (Cloud) Image(ctx context.Context) {
877877
Package(ctx)
878878
}
879879

880+
<<<<<<< HEAD
881+
=======
882+
// Load loads an artifact as a docker image.
883+
// 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
884+
// DOCKER_IMPORT_SOURCE - override source for import
885+
func (Cloud) Load() error {
886+
agentVersion, err := mage.AgentPackageVersion()
887+
if err != nil {
888+
return fmt.Errorf("failed to get agent package version: %w", err)
889+
}
890+
891+
// Need to get the FIPS env var flag to see if we are using the normal source cloud image name, or the FIPS variant
892+
fips := os.Getenv(fipsEnv)
893+
defer os.Setenv(fipsEnv, fips)
894+
fipsVal, err := strconv.ParseBool(fips)
895+
if err != nil {
896+
fipsVal = false
897+
}
898+
if err := os.Setenv(fipsEnv, strconv.FormatBool(fipsVal)); err != nil {
899+
return fmt.Errorf("failed to set fips env var: %w", err)
900+
}
901+
devtools.FIPSBuild = fipsVal
902+
903+
source := "build/distributions/elastic-agent-cloud-" + agentVersion + "-SNAPSHOT-linux-" + runtime.GOARCH + ".docker.tar.gz"
904+
if fipsVal {
905+
source = "build/distributions/elastic-agent-cloud-fips-" + agentVersion + "-SNAPSHOT-linux-" + runtime.GOARCH + ".docker.tar.gz"
906+
}
907+
if envSource, ok := os.LookupEnv("DOCKER_IMPORT_SOURCE"); ok && envSource != "" {
908+
source = envSource
909+
}
910+
911+
return sh.RunV("docker", "image", "load", "-i", source)
912+
}
913+
914+
>>>>>>> 5c5b174ae (ci: pin elastic-agent version (#8736))
880915
// Push builds a cloud image tags it correctly and pushes to remote image repo.
881916
// Previous login to elastic registry is required!
882917
func (Cloud) Push() error {
883-
snapshot := os.Getenv(snapshotEnv)
884-
defer os.Setenv(snapshotEnv, snapshot)
918+
agentVersion, err := mage.AgentPackageVersion()
919+
if err != nil {
920+
return fmt.Errorf("failed to get agent package version: %w", err)
921+
}
885922

886-
os.Setenv(snapshotEnv, "true")
923+
<<<<<<< HEAD
924+
sourceCloudImageName := fmt.Sprintf("docker.elastic.co/beats-ci/elastic-agent-cloud:%s", version)
925+
=======
926+
// Need to get the FIPS env var flag to see if we are using the normal source cloud image name, or the FIPS variant
927+
fips := os.Getenv(fipsEnv)
928+
defer os.Setenv(fipsEnv, fips)
929+
fipsVal, err := strconv.ParseBool(fips)
930+
if err != nil {
931+
fipsVal = false
932+
}
933+
if err := os.Setenv(fipsEnv, strconv.FormatBool(fipsVal)); err != nil {
934+
return fmt.Errorf("failed to set fips env var: %w", err)
935+
}
936+
devtools.FIPSBuild = fipsVal
887937

888-
version := getVersion()
889-
var tag string
938+
sourceCloudImageName := fmt.Sprintf("docker.elastic.co/beats-ci/elastic-agent-cloud:%s-SNAPSHOT", agentVersion)
939+
if fipsVal {
940+
sourceCloudImageName = fmt.Sprintf("docker.elastic.co/beats-ci/elastic-agent-cloud-fips:%s-SNAPSHOT", agentVersion)
941+
}
942+
var targetTag string
890943
if envTag, isPresent := os.LookupEnv("CUSTOM_IMAGE_TAG"); isPresent && len(envTag) > 0 {
891-
tag = envTag
944+
targetTag = envTag
892945
} else {
893-
commit := dockerCommitHash()
894-
time := time.Now().Unix()
895-
896-
tag = fmt.Sprintf("%s-%s-%d", version, commit, time)
946+
targetTag = fmt.Sprintf("%s-%s-%d", agentVersion, dockerCommitHash(), time.Now().Unix())
897947
}
898-
899-
sourceCloudImageName := fmt.Sprintf("docker.elastic.co/beats-ci/elastic-agent-cloud:%s", version)
948+
>>>>>>> 5c5b174ae (ci: pin elastic-agent version (#8736))
900949
var targetCloudImageName string
901950
if customImage, isPresent := os.LookupEnv("CI_ELASTIC_AGENT_DOCKER_IMAGE"); isPresent && len(customImage) > 0 {
902-
targetCloudImageName = fmt.Sprintf("%s:%s", customImage, tag)
951+
targetCloudImageName = fmt.Sprintf("%s:%s", customImage, targetTag)
903952
} else {
904-
targetCloudImageName = fmt.Sprintf(cloudImageTmpl, tag)
953+
targetCloudImageName = fmt.Sprintf(cloudImageTmpl, targetTag)
905954
}
906955

907956
fmt.Printf(">> Setting a docker image tag to %s\n", targetCloudImageName)
908957
err := sh.RunV("docker", "tag", sourceCloudImageName, targetCloudImageName)
909958
if err != nil {
910-
return fmt.Errorf("Failed setting a docker image tag: %w", err)
959+
return fmt.Errorf("failed setting a docker image tag: %w", err)
911960
}
912961
fmt.Println(">> Docker image tag updated successfully")
913962

914963
fmt.Println(">> Pushing a docker image to remote registry")
915964
err = sh.RunV("docker", "image", "push", targetCloudImageName)
916965
if err != nil {
917-
return fmt.Errorf("Failed pushing docker image: %w", err)
966+
return fmt.Errorf("failed pushing docker image: %w", err)
918967
}
919968
fmt.Printf(">> Docker image pushed to remote registry successfully: %s\n", targetCloudImageName)
920969

921970
return nil
922971
}
923972

973+
<<<<<<< HEAD
974+
=======
975+
// Create a new devmachine that will be auto-deleted in 6 hours.
976+
// Example: MACHINE_IMAGE="family/platform-ingest-elastic-agent-ubuntu-2204" ZONE="us-central1-a" mage devmachine:create "pavel-dev-machine"
977+
// ZONE defaults to 'us-central1-a', MACHINE_IMAGE defaults to 'family/platform-ingest-elastic-agent-ubuntu-2204'
978+
func (Devmachine) Create(instanceName string) error {
979+
if instanceName == "" {
980+
return errors.New(
981+
`instanceName is required.
982+
Example:
983+
mage devmachine:create "pavel-dev-machine" `)
984+
}
985+
return devmachine.Run(instanceName)
986+
}
987+
988+
>>>>>>> 5c5b174ae (ci: pin elastic-agent version (#8736))
924989
func Clean() {
925990
mg.Deps(devtools.Clean, Build.Clean)
926991
}

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)