Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ check_if_file_exist_in_repo() {
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}\"")
if [[ ${response} -ge 1 ]]; then
export FILE_EXISTS_IN_REPO=true
echo "FILE_EXIST_IN_REPO = true"
echo "FILE_EXIST_IN_REPO = true"
else
export FILE_EXISTS_IN_REPO=false
echo "FILE_EXIST_IN_REPO = false"
Expand All @@ -45,35 +45,8 @@ if [[ "$BUILDKITE_PIPELINE_SLUG" == "fleet-server-package-mbp" ]]; then
check_if_file_exist_in_repo "infra" "${_branch}" #TODO should be changed to "main" for rollback...
fi

if [[ "$BUILDKITE_PIPELINE_SLUG" == "fleet-server" || "$BUILDKITE_PIPELINE_SLUG" == "fleet-server-perf-tests" ]]; then
if [[ "$BUILDKITE_STEP_KEY" == "publish" || "$BUILDKITE_STEP_KEY" == "cloud-e2e-test" || "$BUILDKITE_STEP_KEY" == "create-image" ]]; then
export DOCKER_USERNAME_SECRET=$(retry 5 vault kv get -field user "${DOCKER_REGISTRY_SECRET_PATH}")
export DOCKER_PASSWORD_SECRET=$(retry 5 vault kv get -field password "${DOCKER_REGISTRY_SECRET_PATH}")
docker login -u "${DOCKER_USERNAME_SECRET}" -p "${DOCKER_PASSWORD_SECRET}" "${DOCKER_REGISTRY}" 2>/dev/null
fi
fi

if [[ "$BUILDKITE_PIPELINE_SLUG" == "fleet-server" && "$BUILDKITE_STEP_KEY" == "cloud-e2e-test" ]]; then
export EC_API_KEY_SECRET=$(retry 5 vault kv get -field apiKey "${EC_KEY_SECRET_PATH}")
# Environment variables required by the Elastic Cloud service deployer
export EC_API_KEY=${EC_API_KEY_SECRET}
fi

# BK analytics
if [[ "$BUILDKITE_PIPELINE_SLUG" == "fleet-server" ]]; then
if [[ "$BUILDKITE_STEP_KEY" == "int-test" || "$BUILDKITE_STEP_KEY" == "e2e-test" || "$BUILDKITE_STEP_KEY" == "fips-e2e-test" ]]; then
echo "--- Prepare BK test analytics token :vault:"
BUILDKITE_ANALYTICS_TOKEN=$(vault kv get -field token kv/ci-shared/platform-ingest/buildkite_fleet_server_analytics_token)
export BUILDKITE_ANALYTICS_TOKEN
fi
fi


if [[ "$BUILDKITE_PIPELINE_SLUG" == "fleet-server-package-mbp" ]]; then
if [[ "$BUILDKITE_STEP_KEY" == "dra-snapshot" || "$BUILDKITE_STEP_KEY" == "dra-staging" ]]; then
export DOCKER_USERNAME_SECRET=$(retry 5 vault kv get -field user "${DOCKER_REGISTRY_SECRET_PATH}")
export DOCKER_PASSWORD_SECRET=$(retry 5 vault kv get -field password "${DOCKER_REGISTRY_SECRET_PATH}")
docker login -u "${DOCKER_USERNAME_SECRET}" -p "${DOCKER_PASSWORD_SECRET}" "${DOCKER_REGISTRY}" 2>/dev/null
DRA_CREDS_SECRET=$(retry 5 vault kv get -field=data -format=json ${CI_DRA_ROLE_PATH})
export VAULT_ADDR_SECRET=$(echo ${DRA_CREDS_SECRET} | jq -r '.vault_addr')
export VAULT_ROLE_ID_SECRET=$(echo ${DRA_CREDS_SECRET} | jq -r '.role_id')
Expand Down
66 changes: 46 additions & 20 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@

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

# This section is used to define the plugins that will be used in the pipeline.
# See https://buildkite.com/docs/pipelines/integrations/plugins/using#using-yaml-anchors-with-plugins
common:
- test_collector_plugin: &test_collector_plugin
test-collector#v1.11.0:
files: "build/test-*.xml"
format: "junit"
branches: "main"
debug: true
- bk_analytics_token_plugin: &bk_analytics_token_plugin
elastic/vault-secrets#v0.1.0:
path: "kv/ci-shared/platform-ingest/buildkite_analytics_token"
field: "token"
env_var: "BUILDKITE_ANALYTICS_TOKEN"
- docker_elastic_login_plugin: &docker_elastic_login_plugin
elastic/vault-docker-login#v0.6.0:
secret_path: 'kv/ci-shared/platform-ingest/elastic_docker_registry'
# See https://github.com/elastic/oblt-infra/blob/main/conf/resources/repos/fleet-server/01-gcp-buildkite-oidc.tf
# This plugin authenticates to Google Cloud using the OIDC token.
- oidc_plugin: &oidc_plugin
Expand All @@ -29,11 +37,9 @@ steps:
steps:
- label: ":white_check_mark: Run check-ci"
key: check-ci
command: "make check-ci"
command: ".buildkite/scripts/check_ci.sh"
agents:
image: "${GO_AGENT_IMAGE}"
cpu: "8"
memory: "4G"
provider: "gcp"

- label: "Package x86_64"
key: "package-x86-64-pr"
Expand Down Expand Up @@ -69,6 +75,8 @@ steps:
- label: "Run go benchmark for PR branch"
key: "go-benchmark-pr"
command: ".buildkite/scripts/run_benchmark.sh pr"
env:
BENCHMARK_ARGS: "-count=8 -benchmem"
artifact_paths:
- build/next.out
- build/next.stat
Expand All @@ -78,7 +86,10 @@ steps:

- label: "Run go benchmark for ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}"
key: "go-benchmark-base"
skip: true # FIXME: Temporarily disabled until mage is on 9.0
command: ".buildkite/scripts/run_benchmark.sh base"
env:
BENCHMARK_ARGS: "-count=8 -benchmem"
artifact_paths:
- build/base.out
- build/base.stat
Expand All @@ -87,6 +98,7 @@ steps:
machineType: "c2-standard-8"

- label: "Compare results"
skip: true # FIXME: Temporarily disabled until mage is on main
key: "go-benchmark-compare"
command: ".buildkite/scripts/run_benchmark.sh compare"
artifact_paths:
Expand Down Expand Up @@ -142,11 +154,8 @@ steps:
artifact_paths:
- build/*.xml
plugins:
- test-collector#v1.10.2:
files: "build/test-*.xml"
format: "junit"
branches: "main"
debug: true
- *bk_analytics_token_plugin
- *test_collector_plugin
retry:
automatic:
limit: 1
Expand All @@ -162,11 +171,8 @@ steps:
- build/*.xml
- build/e2e-coverage.out
plugins:
- test-collector#v1.10.2:
files: "build/test-*.xml"
format: "junit"
branches: "main"
debug: true
- *bk_analytics_token_plugin
- *test_collector_plugin

- label: ":junit: Junit annotate"
plugins:
Expand Down Expand Up @@ -203,9 +209,22 @@ steps:

- label: ":gcloud: Cloud e2e Test"
key: "cloud-e2e-test"
env:
DOCKER_REGISTRY: "docker.elastic.co"
DOCKER_IMAGE: "docker.elastic.co/beats-ci/elastic-agent-cloud-fleet"
DOCKER_IMAGE_TAG: "pr-${BUILDKITE_PULL_REQUEST}-${BUILDKITE_COMMIT:0:12}"
SNAPSHOT: "true"
PLATFORMS: "linux/amd64"
TF_VAR_pull_request: "${BUILDKITE_PULL_REQUEST}"
command: ".buildkite/scripts/cloud_e2e_test.sh"
agents:
provider: "gcp"
plugins:
- *docker_elastic_login_plugin
- elastic/vault-secrets#v0.1.0:
path: "kv/ci-shared/platform-ingest/platform-ingest-ec-prod"
field: "apiKey"
env_var: "EC_API_KEY"
depends_on:
- step: "unit-test"
allow_failure: false
Expand All @@ -218,9 +237,16 @@ steps:
- label: ":docker: Publish docker image"
key: "publish"
command: ".buildkite/scripts/build_push_docker_image.sh"
env:
DOCKER_IMAGE: "docker.elastic.co/observability-ci/fleet-server" # needs to rename for rollback
DOCKER_IMAGE_SHA_TAG: "git-${BUILDKITE_COMMIT:0:12}" # needs to rename for rollback, should be "git-${BUILDKITE_COMMIT:0:12}"
DOCKER_IMAGE_LATEST_TAG: "latest" # needs to rename for rollback
DOCKER_IMAGE_GIT_TAG: "${BUILDKITE_BRANCH}" # needs to rename for rollback
if: "build.env('BUILDKITE_PULL_REQUEST') == 'false' && build.env('BUILDKITE_BRANCH') == 'main'"
agents:
provider: "gcp"
plugins:
- *docker_elastic_login_plugin
depends_on:
- step: "tests"
allow_failure: false
Expand Down
12 changes: 9 additions & 3 deletions .buildkite/scripts/build_push_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ set -euo pipefail

source .buildkite/scripts/common.sh

add_bin_path

with_go

with_mage

echo "Building the docker image..."
if ! docker pull -q ${DOCKER_IMAGE}:${DOCKER_IMAGE_SHA_TAG} 2> /dev/null; then
DOCKER_IMAGE_TAG="${DOCKER_IMAGE_SHA_TAG}"
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} make build-and-push-docker
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} mage docker:publish
fi

if [[ "${DOCKER_IMAGE_GIT_TAG}" == "main" ]]; then
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_LATEST_TAG}" make build-and-push-docker
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_LATEST_TAG}" mage docker:publish
elif [[ ${BUILDKITE_PULL_REQUEST} == "false" ]]; then
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_GIT_TAG}" make build-and-push-docker
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_GIT_TAG}" mage docker:publish
fi
13 changes: 13 additions & 0 deletions .buildkite/scripts/check_ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -euo pipefail

source .buildkite/scripts/common.sh

add_bin_path

with_go

with_mage

mage check:ci
35 changes: 34 additions & 1 deletion .buildkite/scripts/cloud_e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,37 @@ with_Terraform

with_docker_compose

USER=fleetserverci make test-cloude2e
with_mage

cleanup() {
r=$?

if [ -f dev-tools/cloud/terraform/.terraform.lock.hcl ] ; then
echo "--- Deployment detected, running cleanup."
mage test:cloudE2EDown
else
echo "--- No deployment detected, skipping cleanup."
fi
exit $r
}
trap cleanup EXIT INT TERM

USER=fleetserverci mage docker:cover docker:customAgentImage docker:push test:cloudE2EUp
FLEET_SERVER_URL=$(terraform output --raw --state=dev-tools/cloud/terraform/terraform.tfstate fleet_url)
echo "Fleet server: \"${FLEET_SERVER_URL}\""
echo "Deployment ID: $(terraform output --raw --state=dev-tools/cloud/terraform/terraform.tfstate deployment_id)"

if [[ "${FLEET_SERVER_URL}" == "" ]]; then
message="FLEET_SERVER_URL is empty, cloud e2e tests cannot be executed"
if [[ "${CI}" == "true" ]]; then
buildkite-agent annotate \
"${message}" \
--context "ctx-cloude2e-test" \
--style "error"
fi
echo "${message}"
exit 1
fi

echo "--- Trigger cloud E2E test"
mage test:cloudE2ERun
16 changes: 5 additions & 11 deletions .buildkite/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,15 @@ download_mbp_packages_from_gcp_bucket() {
}

with_mage() {
local install_packages=(
"github.com/magefile/mage"
"github.com/elastic/go-licenser"
"golang.org/x/tools/cmd/goimports"
"github.com/jstemmer/go-junit-report"
"gotest.tools/gotestsum"
)
create_workspace
for pkg in "${install_packages[@]}"; do
go install "${pkg}@latest"
done
go install github.com/magefile/mage # uses go.mod implicitly
mage -clean
mage -version
which mage
}

cleanup() {
echo "Deleting temporary files..."
rm -rf ${WORKSPACE}/${TMP_FOLDER_TEMPLATE_BASE}.*
echo "Done."
}
}
15 changes: 7 additions & 8 deletions .buildkite/scripts/dra_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ set -euo pipefail

source .buildkite/scripts/common.sh

add_bin_path

with_go

with_mage

FOLDER_PATH="build/distributions"
BASE_DIR="${WORKSPACE}/${FOLDER_PATH}"
DRA_OUTPUT="release-manager.out"
Expand All @@ -12,7 +18,7 @@ export TYPE=${1}
# DRA_BRANCH can be used for manually testing packaging with PRs
# e.g. define `DRA_BRANCH="main"` under Options/Environment Variables in the Buildkite UI after clicking new Build
export BRANCH="${DRA_BRANCH:="${BUILDKITE_BRANCH:=""}"}"
export VERSION="$(make get-version)"
export VERSION="$(mage getVersion)"

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

add_bin_path

download_mbp_packages_from_gcp_bucket "${FOLDER_PATH}" "${TYPE}"

with_go

with_mage

export RM_VERSION="${VERSION}"

if [[ ${TYPE} == "snapshot" ]]; then
Expand Down
4 changes: 3 additions & 1 deletion .buildkite/scripts/e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ with_go

with_docker_compose

with_mage

echo "Starting the E2E tests..."
make test-e2e junit-report
mage test:e2e test:junitReport
4 changes: 3 additions & 1 deletion .buildkite/scripts/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ with_go

with_docker_compose

with_mage

echo "Starting the integration tests..."
make test-int junit-report
mage test:integration test:junitReport
4 changes: 3 additions & 1 deletion .buildkite/scripts/local_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ source .buildkite/scripts/common.sh
add_bin_path
with_go

make local
with_mage

mage build:local
4 changes: 2 additions & 2 deletions .buildkite/scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ with_mage
case "${TYPE}" in
"snapshot")
export SNAPSHOT=true
make docker-release
mage docker:release
;;
"staging")
make docker-release
mage docker:release
;;
*)
echo "The option is unsupported yet"
Expand Down
8 changes: 5 additions & 3 deletions .buildkite/scripts/release_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ add_bin_path

with_go

make docker-release
with_mage

mage docker:release

upload_packages_to_gcp_bucket "build/distributions/"

make test-release
mage test:release

make build-docker
mage docker:image
Loading
Loading