Skip to content

Commit 44a978c

Browse files
[8.18] backport #4912 #4985 #5000 #5075 (#5397)
* Convert Makefile to magefile.go (#4912) Reimplement Makefile targets in mage. Change buildkite pipeline to use mage. Change Dockerfile* to use mage. (cherry picked from commit db5f46b) # Conflicts: # .buildkite/pipeline.yml # .buildkite/scripts/common.sh # .buildkite/scripts/local_build.sh # .buildkite/scripts/test-release.sh # Dockerfile.build # Dockerfile.fips # Makefile # NOTICE.txt # README.md # dev-tools/cloud/Makefile # dev-tools/cloud/terraform/main.tf # dev-tools/e2e/Dockerfile # dev-tools/e2e/build.sh # dev-tools/e2e/validatecerts.go # dev-tools/go.mod # dev-tools/go.sum # docs/developers-guide.md # docs/docker-images.md # docs/fips.md # testing/e2e/fips_test.go * Ensure directory is made within zip artifacts (#4985) * Ensure directory is made within zip artifacts * Make test:release extraction stricter * Fail cloude2e step if tests can't run, fix image publication (#5000) Fail the pipeline if cloude2e tests can't run. mage docker:image now uses the DOCKER_IMAGE env var. * Add multiplatform images (#5075) Fixes issue where change from make to mage, result in the loss of creating multiple platform images. * Fix cherry-picks * change to serialdeps * Use magefile from main * Remove FIPS references, use docker plugin * Use bk plugins * cleanup go.mod in dev-tools and pkg/api * Add missing EC secret to cloud e2e step * Review feedback
1 parent 02b85c9 commit 44a978c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+5278
-17046
lines changed

.buildkite/hooks/pre-command

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ check_if_file_exist_in_repo() {
2727
local response=$(curl --fail -s -H "Authorization: token $GITHUB_REPO_TOKEN" https://api.github.com/repos/elastic/${repoName}/contents/${path_to_file}| grep -c "\"path\"\: \"${path_to_file}\"")
2828
if [[ ${response} -ge 1 ]]; then
2929
export FILE_EXISTS_IN_REPO=true
30-
echo "FILE_EXIST_IN_REPO = true"
30+
echo "FILE_EXIST_IN_REPO = true"
3131
else
3232
export FILE_EXISTS_IN_REPO=false
3333
echo "FILE_EXIST_IN_REPO = false"
@@ -45,25 +45,8 @@ if [[ "$BUILDKITE_PIPELINE_SLUG" == "fleet-server-package-mbp" ]]; then
4545
check_if_file_exist_in_repo "infra" "${_branch}" #TODO should be changed to "main" for rollback...
4646
fi
4747

48-
if [[ "$BUILDKITE_PIPELINE_SLUG" == "fleet-server" || "$BUILDKITE_PIPELINE_SLUG" == "fleet-server-perf-tests" ]]; then
49-
if [[ "$BUILDKITE_STEP_KEY" == "publish" || "$BUILDKITE_STEP_KEY" == "cloud-e2e-test" || "$BUILDKITE_STEP_KEY" == "create-image" ]]; then
50-
export DOCKER_USERNAME_SECRET=$(retry 5 vault kv get -field user "${DOCKER_REGISTRY_SECRET_PATH}")
51-
export DOCKER_PASSWORD_SECRET=$(retry 5 vault kv get -field password "${DOCKER_REGISTRY_SECRET_PATH}")
52-
docker login -u "${DOCKER_USERNAME_SECRET}" -p "${DOCKER_PASSWORD_SECRET}" "${DOCKER_REGISTRY}" 2>/dev/null
53-
fi
54-
fi
55-
56-
if [[ "$BUILDKITE_PIPELINE_SLUG" == "fleet-server" && "$BUILDKITE_STEP_KEY" == "cloud-e2e-test" ]]; then
57-
export EC_API_KEY_SECRET=$(retry 5 vault kv get -field apiKey "${EC_KEY_SECRET_PATH}")
58-
# Environment variables required by the Elastic Cloud service deployer
59-
export EC_API_KEY=${EC_API_KEY_SECRET}
60-
fi
61-
6248
if [[ "$BUILDKITE_PIPELINE_SLUG" == "fleet-server-package-mbp" ]]; then
6349
if [[ "$BUILDKITE_STEP_KEY" == "dra-snapshot" || "$BUILDKITE_STEP_KEY" == "dra-staging" ]]; then
64-
export DOCKER_USERNAME_SECRET=$(retry 5 vault kv get -field user "${DOCKER_REGISTRY_SECRET_PATH}")
65-
export DOCKER_PASSWORD_SECRET=$(retry 5 vault kv get -field password "${DOCKER_REGISTRY_SECRET_PATH}")
66-
docker login -u "${DOCKER_USERNAME_SECRET}" -p "${DOCKER_PASSWORD_SECRET}" "${DOCKER_REGISTRY}" 2>/dev/null
6750
DRA_CREDS_SECRET=$(retry 5 vault kv get -field=data -format=json ${CI_DRA_ROLE_PATH})
6851
export VAULT_ADDR_SECRET=$(echo ${DRA_CREDS_SECRET} | jq -r '.vault_addr')
6952
export VAULT_ROLE_ID_SECRET=$(echo ${DRA_CREDS_SECRET} | jq -r '.role_id')

.buildkite/pipeline.yml

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@
22

33
env:
44
DOCKER_COMPOSE_VERSION: "1.25.5"
5-
DOCKER_REGISTRY: "docker.elastic.co"
6-
DOCKER_IMAGE: "${DOCKER_REGISTRY}/observability-ci/fleet-server" # needs to rename for rollback
7-
DOCKER_IMAGE_SHA_TAG: "git-${BUILDKITE_COMMIT:0:12}" # needs to rename for rollback, should be "git-${BUILDKITE_COMMIT:0:12}"
8-
DOCKER_IMAGE_LATEST_TAG: "latest" # needs to rename for rollback
9-
DOCKER_IMAGE_GIT_TAG: "${BUILDKITE_BRANCH}" # needs to rename for rollback
10-
GO_AGENT_IMAGE: "golang:${GO_VERSION}"
115
TERRAFORM_VERSION: "1.6.4"
126
IMAGE_UBUNTU_X86_64: "family/core-ubuntu-2204"
137
IMAGE_UBUNTU_ARM_64: "core-ubuntu-2204-aarch64"
148

159
# This section is used to define the plugins that will be used in the pipeline.
1610
# See https://buildkite.com/docs/pipelines/integrations/plugins/using#using-yaml-anchors-with-plugins
1711
common:
12+
- test_collector_plugin: &test_collector_plugin
13+
test-collector#v1.11.0:
14+
files: "build/test-*.xml"
15+
format: "junit"
16+
branches: "main"
17+
debug: true
18+
- bk_analytics_token_plugin: &bk_analytics_token_plugin
19+
elastic/vault-secrets#v0.1.0:
20+
path: "kv/ci-shared/platform-ingest/buildkite_analytics_token"
21+
field: "token"
22+
env_var: "BUILDKITE_ANALYTICS_TOKEN"
23+
- docker_elastic_login_plugin: &docker_elastic_login_plugin
24+
elastic/vault-docker-login#v0.6.0:
25+
secret_path: 'kv/ci-shared/platform-ingest/elastic_docker_registry'
1826
# See https://github.com/elastic/oblt-infra/blob/main/conf/resources/repos/fleet-server/01-gcp-buildkite-oidc.tf
1927
# This plugin authenticates to Google Cloud using the OIDC token.
2028
- oidc_plugin: &oidc_plugin
@@ -29,11 +37,9 @@ steps:
2937
steps:
3038
- label: ":white_check_mark: Run check-ci"
3139
key: check-ci
32-
command: "make check-ci"
40+
command: ".buildkite/scripts/check_ci.sh"
3341
agents:
34-
image: "${GO_AGENT_IMAGE}"
35-
cpu: "8"
36-
memory: "4G"
42+
provider: "gcp"
3743

3844
- label: "Package x86_64"
3945
key: "package-x86-64-pr"
@@ -69,6 +75,8 @@ steps:
6975
- label: "Run go benchmark for PR branch"
7076
key: "go-benchmark-pr"
7177
command: ".buildkite/scripts/run_benchmark.sh pr"
78+
env:
79+
BENCHMARK_ARGS: "-count=8 -benchmem"
7280
artifact_paths:
7381
- build/next.out
7482
- build/next.stat
@@ -77,8 +85,11 @@ steps:
7785
machineType: "c2-standard-8"
7886

7987
- label: "Run go benchmark for ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}"
88+
skip: true # FIXME: Temporarily disabled until mage is on main
8089
key: "go-benchmark-base"
8190
command: ".buildkite/scripts/run_benchmark.sh base"
91+
env:
92+
BENCHMARK_ARGS: "-count=8 -benchmem"
8293
artifact_paths:
8394
- build/base.out
8495
- build/base.stat
@@ -87,6 +98,7 @@ steps:
8798
machineType: "c2-standard-8"
8899

89100
- label: "Compare results"
101+
skip: true # FIXME: Temporarily disabled until mage is on main
90102
key: "go-benchmark-compare"
91103
command: ".buildkite/scripts/run_benchmark.sh compare"
92104
artifact_paths:
@@ -130,6 +142,9 @@ steps:
130142
provider: "gcp"
131143
artifact_paths:
132144
- build/*.xml
145+
plugins:
146+
- *bk_analytics_token_plugin
147+
- *test_collector_plugin
133148
retry:
134149
automatic:
135150
limit: 1
@@ -144,6 +159,9 @@ steps:
144159
artifact_paths:
145160
- build/*.xml
146161
- build/e2e-coverage.out
162+
plugins:
163+
- *bk_analytics_token_plugin
164+
- *test_collector_plugin
147165

148166
- label: ":junit: Junit annotate"
149167
plugins:
@@ -180,9 +198,22 @@ steps:
180198

181199
- label: ":gcloud: Cloud e2e Test"
182200
key: "cloud-e2e-test"
201+
env:
202+
DOCKER_REGISTRY: "docker.elastic.co"
203+
DOCKER_IMAGE: "docker.elastic.co/beats-ci/elastic-agent-cloud-fleet"
204+
DOCKER_IMAGE_TAG: "pr-${BUILDKITE_PULL_REQUEST}-${BUILDKITE_COMMIT:0:12}"
205+
SNAPSHOT: "true"
206+
PLATFORMS: "linux/amd64"
207+
TF_VAR_pull_request: "${BUILDKITE_PULL_REQUEST}"
183208
command: ".buildkite/scripts/cloud_e2e_test.sh"
184209
agents:
185210
provider: "gcp"
211+
plugins:
212+
- *docker_elastic_login_plugin
213+
- elastic/vault-secrets#v0.1.0:
214+
path: "kv/ci-shared/platform-ingest/platform-ingest-ec-prod"
215+
field: "apiKey"
216+
env_var: "EC_API_KEY"
186217
depends_on:
187218
- step: "unit-test"
188219
allow_failure: false
@@ -195,9 +226,16 @@ steps:
195226
- label: ":docker: Publish docker image"
196227
key: "publish"
197228
command: ".buildkite/scripts/build_push_docker_image.sh"
229+
env:
230+
DOCKER_IMAGE: "docker.elastic.co/observability-ci/fleet-server" # needs to rename for rollback
231+
DOCKER_IMAGE_SHA_TAG: "git-${BUILDKITE_COMMIT:0:12}" # needs to rename for rollback, should be "git-${BUILDKITE_COMMIT:0:12}"
232+
DOCKER_IMAGE_LATEST_TAG: "latest" # needs to rename for rollback
233+
DOCKER_IMAGE_GIT_TAG: "${BUILDKITE_BRANCH}" # needs to rename for rollback
198234
if: "build.env('BUILDKITE_PULL_REQUEST') == 'false' && build.env('BUILDKITE_BRANCH') == 'main'"
199235
agents:
200236
provider: "gcp"
237+
plugins:
238+
- *docker_elastic_login_plugin
201239
depends_on:
202240
- step: "tests"
203241
allow_failure: false

.buildkite/scripts/build_push_docker_image.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ set -euo pipefail
44

55
source .buildkite/scripts/common.sh
66

7+
add_bin_path
8+
9+
with_go
10+
11+
with_mage
12+
713
echo "Building the docker image..."
814
if ! docker pull -q ${DOCKER_IMAGE}:${DOCKER_IMAGE_SHA_TAG} 2> /dev/null; then
915
DOCKER_IMAGE_TAG="${DOCKER_IMAGE_SHA_TAG}"
10-
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} make build-and-push-docker
16+
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} mage docker:publish
1117
fi
1218

1319
if [[ "${DOCKER_IMAGE_GIT_TAG}" == "main" ]]; then
14-
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_LATEST_TAG}" make build-and-push-docker
20+
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_LATEST_TAG}" mage docker:publish
1521
elif [[ ${BUILDKITE_PULL_REQUEST} == "false" ]]; then
16-
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_GIT_TAG}" make build-and-push-docker
22+
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_GIT_TAG}" mage docker:publish
1723
fi

.buildkite/scripts/check_ci.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
source .buildkite/scripts/common.sh
6+
7+
add_bin_path
8+
9+
with_go
10+
11+
with_mage
12+
13+
mage check:ci

.buildkite/scripts/cloud_e2e_test.sh

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,37 @@ with_Terraform
1212

1313
with_docker_compose
1414

15-
USER=fleetserverci make test-cloude2e
15+
with_mage
16+
17+
cleanup() {
18+
r=$?
19+
20+
if [ -f dev-tools/cloud/terraform/.terraform.lock.hcl ] ; then
21+
echo "--- Deployment detected, running cleanup."
22+
mage test:cloudE2EDown
23+
else
24+
echo "--- No deployment detected, skipping cleanup."
25+
fi
26+
exit $r
27+
}
28+
trap cleanup EXIT INT TERM
29+
30+
USER=fleetserverci mage docker:cover docker:customAgentImage docker:push test:cloudE2EUp
31+
FLEET_SERVER_URL=$(terraform output --raw --state=dev-tools/cloud/terraform/terraform.tfstate fleet_url)
32+
echo "Fleet server: \"${FLEET_SERVER_URL}\""
33+
echo "Deployment ID: $(terraform output --raw --state=dev-tools/cloud/terraform/terraform.tfstate deployment_id)"
34+
35+
if [[ "${FLEET_SERVER_URL}" == "" ]]; then
36+
message="FLEET_SERVER_URL is empty, cloud e2e tests cannot be executed"
37+
if [[ "${CI}" == "true" ]]; then
38+
buildkite-agent annotate \
39+
"${message}" \
40+
--context "ctx-cloude2e-test" \
41+
--style "error"
42+
fi
43+
echo "${message}"
44+
exit 1
45+
fi
46+
47+
echo "--- Trigger cloud E2E test"
48+
mage test:cloudE2ERun

.buildkite/scripts/common.sh

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,15 @@ download_mbp_packages_from_gcp_bucket() {
136136
}
137137

138138
with_mage() {
139-
local install_packages=(
140-
"github.com/magefile/mage"
141-
"github.com/elastic/go-licenser"
142-
"golang.org/x/tools/cmd/goimports"
143-
"github.com/jstemmer/go-junit-report"
144-
"gotest.tools/gotestsum"
145-
)
146139
create_workspace
147-
for pkg in "${install_packages[@]}"; do
148-
go install "${pkg}@latest"
149-
done
140+
go install github.com/magefile/mage # uses go.mod implicitly
141+
mage -clean
142+
mage -version
143+
which mage
150144
}
151145

152146
cleanup() {
153147
echo "Deleting temporary files..."
154148
rm -rf ${WORKSPACE}/${TMP_FOLDER_TEMPLATE_BASE}.*
155149
echo "Done."
156-
}
150+
}

.buildkite/scripts/dra_release.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ set -euo pipefail
44

55
source .buildkite/scripts/common.sh
66

7+
add_bin_path
8+
9+
with_go
10+
11+
with_mage
12+
713
FOLDER_PATH="build/distributions"
814
BASE_DIR="${WORKSPACE}/${FOLDER_PATH}"
915
DRA_OUTPUT="release-manager.out"
@@ -12,7 +18,7 @@ export TYPE=${1}
1218
# DRA_BRANCH can be used for manually testing packaging with PRs
1319
# e.g. define `DRA_BRANCH="main"` under Options/Environment Variables in the Buildkite UI after clicking new Build
1420
export BRANCH="${DRA_BRANCH:="${BUILDKITE_BRANCH:=""}"}"
15-
export VERSION="$(make get-version)"
21+
export VERSION="$(mage getVersion)"
1622

1723
if [[ "${VERSION}" == *"-SNAPSHOT"* || "${VERSION}" == "" ]]; then
1824
echo "The 'version' parameter is required and it cannot contain the suffix '-SNAPSHOT'."
@@ -24,14 +30,7 @@ if [[ "${PROJECT}" == "" ]]; then
2430
exit 1
2531
fi
2632

27-
add_bin_path
28-
2933
download_mbp_packages_from_gcp_bucket "${FOLDER_PATH}" "${TYPE}"
30-
31-
with_go
32-
33-
with_mage
34-
3534
export RM_VERSION="${VERSION}"
3635

3736
if [[ ${TYPE} == "snapshot" ]]; then

.buildkite/scripts/e2e_test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ with_go
1010

1111
with_docker_compose
1212

13+
with_mage
14+
1315
echo "Starting the E2E tests..."
14-
make test-e2e junit-report
16+
mage test:e2e test:junitReport

.buildkite/scripts/integration_test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ with_go
1010

1111
with_docker_compose
1212

13+
with_mage
14+
1315
echo "Starting the integration tests..."
14-
make test-int junit-report
16+
mage test:integration test:junitReport

.buildkite/scripts/local_build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ source .buildkite/scripts/common.sh
77
add_bin_path
88
with_go
99

10-
make local
10+
with_mage
11+
12+
mage build:local

0 commit comments

Comments
 (0)