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
77 changes: 20 additions & 57 deletions .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ git config --global core.pager 'cat'
export UPLOAD_SAFE_LOGS=${UPLOAD_SAFE_LOGS:-"0"}
export SERVERLESS=${SERVERLESS:-"false"}
export STACK_VERSION=${STACK_VERSION:-""}
export ELASTIC_SUBSCRIPTION=${ELASTIC_SUBSCRIPTION:-""}
export STACK_LOGSDB_ENABLED=${STACK_LOGSDB_ENABLED:-"false"}
export FORCE_CHECK_ALL=${FORCE_CHECK_ALL:-"false"}
export PUBLISH_COVERAGE_REPORTS=${PUBLISH_COVERAGE_REPORTS:-"false"}

Expand All @@ -23,21 +25,19 @@ export GO_VERSION
REPO_NAME=$(repo_name "${BUILDKITE_REPO}")
export REPO_NAME

export TMP_FOLDER_TEMPLATE_BASE="tmp.${REPO_NAME}"
export TMP_FOLDER_TEMPLATE="${TMP_FOLDER_TEMPLATE_BASE}.XXXXXXXXX"

REPO_BUILD_TAG="${REPO_NAME}/$(buildkite_pr_branch_build_id)"
export REPO_BUILD_TAG

AWS_SERVICE_ACCOUNT_SECRET_PATH=kv/ci-shared/platform-ingest/aws_ingest_ci
PRIVATE_CI_GCS_CREDENTIALS_PATH=kv/ci-shared/platform-ingest/gcp-platform-ingest-ci-service-account

BUILDKITE_API_TOKEN_PATH=kv/ci-shared/platform-ingest/buildkite_token

EC_TOKEN_PATH=kv/ci-shared/platform-ingest/platform-ingest-ec-qa
EC_DATA_PATH=secret/ci/elastic-integrations/ec_data

# variables required for terraform
export JOB_GCS_BUCKET_INTERNAL="ecosystem-ci-internal"

# -------------
# variables required by packages using Terraform as a service deployer
# https://github.com/elastic/elastic-package/blob/f8f2f15a04bcc25eca00887fb147bd7f8a0f32b3/internal/servicedeployer/_static/terraform_deployer.yml#L8

export ENVIRONMENT="ci"
export REPO="${REPO_NAME}"

Expand Down Expand Up @@ -68,17 +68,26 @@ export BUILD_ID="${BUILDKITE_BUILD_NUMBER}"
CREATED_DATE=$(date +%s%3N)
export CREATED_DATE

# -------------

if [[ "${ELASTIC_PACKAGE_CUSTOMIZE_SERVICE_TEST_RUN_ID:-"false"}" == "true" ]]; then
# Required to customize the RunID value mainly for those packages creating resources in cloud providers
# via the terraform service deployer.
# Get the latest 4 digits of the BUILDKITE_STEP_ID
export ELASTIC_PACKAGE_PREFIX_SERVICE_TEST_RUN_ID="${BUILDKITE_STEP_ID: -4}"
fi

if [ -n "${ELASTIC_PACKAGE_LINKS_FILE_PATH+x}" ]; then
# first upload pipeline does not have the environment variables defined in the YAML
export ELASTIC_PACKAGE_LINKS_FILE_PATH=${BASE_DIR}/${ELASTIC_PACKAGE_LINKS_FILE_PATH}
fi

if [[ "${BUILDKITE_PIPELINE_SLUG}" == "integrations" && "${BUILDKITE_STEP_KEY}" == "reference-target-branch" ]]; then
if [[ ( "${BUILDKITE_PIPELINE_SLUG}" =~ ^(integrations|integrations-test-stack)$ ) && "${BUILDKITE_STEP_KEY}" == "reference-target-branch" ]]; then
# Get the commit from target branch in the first step (reference-target-branch).
# This step MUST be the first one and not run in parallel with any other step to ensure
# that there is just one value for this variable
if is_pr ; then
git fetch -v origin ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}
git fetch -v origin "${BUILDKITE_PULL_REQUEST_BASE_BRANCH}"
commit_main=$(git rev-parse --verify FETCH_HEAD)
buildkite-agent meta-data set "REPOSITORY_TARGET_BRANCH_COMMIT" "${commit_main}"
fi
Expand All @@ -91,7 +100,7 @@ if [[ "${BUILDKITE_PIPELINE_SLUG}" == "integrations-publish" ]]; then
fi
fi

if [[ "${BUILDKITE_PIPELINE_SLUG}" == "integrations" ]]; then
if [[ "${BUILDKITE_PIPELINE_SLUG}" =~ ^(integrations|integrations-test-stack)$ ]]; then
if [[ "${BUILDKITE_STEP_KEY}" == "test-integrations" ]]; then
BUILDKITE_API_TOKEN=$(retry 5 vault kv get -field buildkite_token "${BUILDKITE_API_TOKEN_PATH}")
export BUILDKITE_API_TOKEN
Expand All @@ -100,62 +109,16 @@ if [[ "${BUILDKITE_PIPELINE_SLUG}" == "integrations" ]]; then
if [[ "${BUILDKITE_STEP_KEY}" == "publish-benchmarks" ]]; then
BUILDKITE_API_TOKEN=$(retry 5 vault kv get -field buildkite_token "${BUILDKITE_API_TOKEN_PATH}")
export BUILDKITE_API_TOKEN
GITHUB_TOKEN=$VAULT_GITHUB_TOKEN
export GITHUB_TOKEN
fi

if [[ "${BUILDKITE_STEP_KEY}" =~ ^test-integrations- ]]; then
ELASTIC_PACKAGE_AWS_SECRET_KEY=$(retry 5 vault kv get -field secret_key "${AWS_SERVICE_ACCOUNT_SECRET_PATH}")
export ELASTIC_PACKAGE_AWS_SECRET_KEY
ELASTIC_PACKAGE_AWS_ACCESS_KEY=$(retry 5 vault kv get -field access_key "${AWS_SERVICE_ACCOUNT_SECRET_PATH}")
export ELASTIC_PACKAGE_AWS_ACCESS_KEY

PRIVATE_CI_GCS_CREDENTIALS_SECRET=$(retry 5 vault kv get -field plaintext -format=json "${PRIVATE_CI_GCS_CREDENTIALS_PATH}")
export PRIVATE_CI_GCS_CREDENTIALS_SECRET
export JOB_GCS_BUCKET_INTERNAL="ingest-buildkite-ci"

# Environment variables required by the service deployer
export AWS_SECRET_ACCESS_KEY=${ELASTIC_PACKAGE_AWS_SECRET_KEY}
export AWS_ACCESS_KEY_ID=${ELASTIC_PACKAGE_AWS_ACCESS_KEY}

BUILDKITE_API_TOKEN=$(retry 5 vault kv get -field buildkite_token "${BUILDKITE_API_TOKEN_PATH}")
export BUILDKITE_API_TOKEN
fi
fi

if [[ "${BUILDKITE_PIPELINE_SLUG}" == "integrations-serverless" ]]; then
if [[ "${BUILDKITE_STEP_KEY}" == "test-integrations-serverless-project" ]]; then
# Currently, system tests are not run when testing with an Elastic Serverless project, so it is not required to
# add the AWS credentials as in the integrations pipeline.

PRIVATE_CI_GCS_CREDENTIALS_SECRET=$(retry 5 vault kv get -field plaintext -format=json "${PRIVATE_CI_GCS_CREDENTIALS_PATH}")
export PRIVATE_CI_GCS_CREDENTIALS_SECRET
export JOB_GCS_BUCKET_INTERNAL="ingest-buildkite-ci"

BUILDKITE_API_TOKEN=$(retry 5 vault kv get -field buildkite_token "${BUILDKITE_API_TOKEN_PATH}")
export BUILDKITE_API_TOKEN

EC_API_KEY_SECRET=$(retry 5 vault kv get -field apiKey "${EC_TOKEN_PATH}")
export EC_API_KEY_SECRET
EC_HOST_SECRET=$(retry 5 vault kv get -field url "${EC_TOKEN_PATH}")
export EC_HOST_SECRET
EC_REGION_SECRET=$(retry 5 vault read -field region_qa "${EC_DATA_PATH}")
export EC_REGION_SECRET
fi
fi

if [[ "$BUILDKITE_PIPELINE_SLUG" == "integrations-backport" ]]; then
if [[ "$BUILDKITE_STEP_KEY" == "create-backport-branch" ]]; then
GITHUB_USERNAME="elastic-vault-github-plugin-prod"
GITHUB_EMAIL="elasticmachine@elastic.co"
GITHUB_TOKEN=$VAULT_GITHUB_TOKEN
export GITHUB_TOKEN GITHUB_EMAIL GITHUB_USERNAME
fi
fi

if [[ "$BUILDKITE_PIPELINE_SLUG" == "integrations" || "$BUILDKITE_PIPELINE_SLUG" == "integrations-serverless" ]]; then
if [[ "$BUILDKITE_STEP_KEY" == "report-failed-tests" ]]; then
export GITHUB_TOKEN="${VAULT_GITHUB_TOKEN}"
fi
fi

60 changes: 31 additions & 29 deletions .buildkite/hooks/pre-exit
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,51 @@ source .buildkite/scripts/common.sh

set -euo pipefail

if [[ "$BUILDKITE_PIPELINE_SLUG" == "integrations" ]]; then
# FIXME: update condition depending on the pipeline steps triggered
if [[ "$BUILDKITE_STEP_KEY" =~ ^test-integrations- ]]; then
unset ELASTIC_PACKAGE_AWS_ACCESS_KEY
unset ELASTIC_PACKAGE_AWS_SECRET_KEY
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
should_run_stack_down() {
# as first check, ensure that the elastic-package binary exists
if [ ! -f "${ELASTIC_PACKAGE_BIN}" ]; then
return 1
fi

# Ensure that kind cluster is deleted
delete_kind_cluster
if is_serverless; then
return 0
fi

# Ensure elastic stack is stopped
if [ -f "${ELASTIC_PACKAGE_BIN}" ]; then
echo "--- Take down the Elastic stack"
${ELASTIC_PACKAGE_BIN} stack down -v
fi
if is_stack_created; then
return 0
fi

return 1
}

if [[ "$BUILDKITE_PIPELINE_SLUG" == "integrations-backport" && "$BUILDKITE_STEP_KEY" == "create-backport-branch" ]]; then
cd "${WORKSPACE}"
git config remote.origin.url "https://github.com/elastic/integrations.git"
fi

if [[ "$BUILDKITE_PIPELINE_SLUG" == "integrations-serverless" ]]; then
if [[ "$BUILDKITE_STEP_KEY" == "test-integrations-serverless-project" ]]; then
unset ELASTIC_PACKAGE_AWS_ACCESS_KEY
unset ELASTIC_PACKAGE_AWS_SECRET_KEY
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
exit_code=0
if [[ "$BUILDKITE_PIPELINE_SLUG" =~ ^(integrations|integrations-test-stack|integrations-serverless)$ ]]; then
# it should match "^test-integration-" steps created in the integrations and integrations-test-stack pipelines (e.g. test-integration-apache or test-integration-aws)
# as well as the step ID "test-integrations-serverless-project" from the "integrations-serverless" pipeline
if [[ "$BUILDKITE_STEP_KEY" =~ ^test-integrations- ]]; then

# Ensure that kind cluster is deleted
delete_kind_cluster

# Ensure elastic stack is stopped
if [ -f "${ELASTIC_PACKAGE_BIN}" ]; then
if should_run_stack_down; then
echo "--- Take down the Elastic stack"
EC_API_KEY=${EC_API_KEY_SECRET} EC_HOST=${EC_HOST_SECRET} ${ELASTIC_PACKAGE_BIN} stack down -v
if ! ${ELASTIC_PACKAGE_BIN} stack down -v ; then
exit_code=1
fi
fi

echo "+++ :bookmark: Documentation to access logs"
inline_link "https://docs.elastic.dev/ingest-dev-docs/elastic-packages/ecosystem-ci-pipelines#private-logs"
fi
fi

echo "--- Cleaning up"
unset_secrets
cleanup

google_cloud_logout_active_account

if [[ "$BUILDKITE_PIPELINE_SLUG" == "integrations-backport" && "$BUILDKITE_STEP_KEY" == "create-backport-branch" ]]; then
cd "${WORKSPACE}"
git config remote.origin.url "https://github.com/elastic/integrations.git"
fi
exit "${exit_code}"
43 changes: 43 additions & 0 deletions .buildkite/pipeline.backport-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json

env:
SETUP_GVM_VERSION: "v0.6.0"
LINUX_AGENT_IMAGE: "golang:${GO_VERSION}"
YQ_VERSION: 'v4.35.2'
GH_CLI_VERSION: "2.29.0"
NOTIFY_TO: "ecosystem-team@elastic.co"

steps:
- label: ":ballot_box_with_check: Backports inventory validation"
key: "check-backports-inventory"
command: ".buildkite/scripts/check_backports_inventory.sh"
agents:
image: "${LINUX_AGENT_IMAGE}"
if_changed:
- ".backports.yml"
- ".buildkite/scripts/run_dev_scripts_tests.sh"
- "dev/scripts/**.sh"
- "cmd/backport/**"
if: |
build.env('BUILDKITE_PULL_REQUEST') == "false" && build.branch == "main"

- label: ":git: Create backport branches for new entries"
key: "trigger-backport-create"
command: ".buildkite/scripts/trigger_backport.sh"
agents:
image: "${LINUX_AGENT_IMAGE}"
plugins:
- elastic/vault-github-token#v0.1.0:
depends_on:
- step: "check-backports-inventory"
allow_failure: false
if_changed:
- ".backports.yml"
if: |
build.env('BUILDKITE_PULL_REQUEST') == "false" &&
build.branch == "main" &&
build.env('BUILDKITE_PIPELINE_SLUG') == "integrations-backport-dispatch"

notify:
- email: "$NOTIFY_TO"
if: "build.state == 'failed' && build.env('BUILDKITE_PULL_REQUEST') == 'false'"
64 changes: 60 additions & 4 deletions .buildkite/pipeline.backport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,33 @@
name: "integrations-backport"

env:
SETUP_GVM_VERSION: "v0.6.0"
YQ_VERSION: 'v4.35.2'
GH_CLI_VERSION: "2.29.0"
# Agent images used in pipeline steps
LINUX_AGENT_IMAGE: "golang:${GO_VERSION}"
NOTIFY_TO: "ecosystem-team@elastic.co"

steps:

- label: "Check that it runs from UI"
key: "check-ui"
command:
- "buildkite-agent annotate \"The $BUILDKITE_PIPELINE_SLUG is used only for running from UI!\" --style 'warning'"
- "buildkite-agent annotate \"The $${BUILDKITE_PIPELINE_SLUG} pipeline can only be triggered from the UI by members of the 'ecosystem' team, or via a trigger step from the 'integrations' or 'integrations-backport-dispatch' pipeline. For the recommended workflow see the [documentation](https://www.elastic.co/guide/en/integrations-developer/current/developer-workflow-support-old-package.html).\" --style 'warning'"
- "exit 1"
if: "build.source != 'ui'"
if: |
!(
(build.source == 'ui' && build.creator.teams includes "ecosystem") ||
(build.source == 'trigger_job' && build.env('BUILDKITE_TRIGGERED_FROM_BUILD_PIPELINE_SLUG') == 'integrations') ||
(build.source == 'trigger_job' && build.env('BUILDKITE_TRIGGERED_FROM_BUILD_PIPELINE_SLUG') == 'integrations-backport-dispatch')
)

# Ensure that the check-ui step runs before any other step
- wait: ~

- input: "Input values for the variables"
key: "input-variables"
if: "build.source != 'trigger_job'"
fields:
- select: "DRY_RUN"
key: "DRY_RUN"
Expand All @@ -29,7 +43,7 @@ steps:
key: "BASE_COMMIT"
required: true
default: ""
- text: "Enter package name"
- text: "Enter package name (as defined in manifest.yml)"
key: "PACKAGE_NAME"
required: true
default: ""
Expand All @@ -44,11 +58,53 @@ steps:
value: "true"
- label: "False"
value: "false"
default: "false"
default: "true"
- text: "Backport branch name (optional, defaults to backport-<package>-<major>.<minor>)"
key: "BACKPORT_BRANCH_NAME"
required: false
default: ""
- text: "PR number to notify on completion (optional)"
key: "PR_NUMBER"
required: false
default: ""

- label: "Creating the backport branch"
key: "create-backport-branch"
command: ".buildkite/scripts/backport_branch.sh"
agents:
image: "${LINUX_AGENT_IMAGE}"
env:
GITHUB_EMAIL: "elasticmachine@elastic.co"
GITHUB_USERNAME: "elastic-vault-github-plugin-prod"
plugins:
- elastic/vault-github-token#v0.1.0:
depends_on:
- step: "input-variables"
allow_failure: false

- label: ":github: Notify PR"
key: "notify-pr"
command: |
if ! outcome=$$(buildkite-agent step get "outcome" --step "create-backport-branch"); then
echo "Failed to retrieve step outcome, skipping PR notification"
exit 0
fi
if [[ "$${outcome}" == "passed" ]]; then
NOTIFY_STATUS=success .buildkite/scripts/notify_backport_pr.sh
else
NOTIFY_STATUS=failure .buildkite/scripts/notify_backport_pr.sh
fi
agents:
image: "${LINUX_AGENT_IMAGE}"
plugins:
- elastic/vault-github-token#v0.1.0:
depends_on:
- step: "create-backport-branch"
allow_failure: true

notify:
# Only notify for automated backport creation failures (triggered by integrations-backport-dispatch).
# Dry-run failures from PR builds (triggered by integrations) are already surfaced as a failing
# CI status on the PR itself and do not warrant a team email.
- email: "$NOTIFY_TO"
if: "build.state == 'failed' && build.source == 'trigger_job' && build.env('BUILDKITE_TRIGGERED_FROM_BUILD_PIPELINE_SLUG') == 'integrations-backport-dispatch'"
5 changes: 4 additions & 1 deletion .buildkite/pipeline.publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json

env:
SETUP_GVM_VERSION: "v0.5.2"
SETUP_GVM_VERSION: "v0.6.0"
LINUX_AGENT_IMAGE: "golang:${GO_VERSION}"
DOCKER_COMPOSE_VERSION: "v2.24.1"
DOCKER_VERSION: "false"
Expand Down Expand Up @@ -38,6 +38,9 @@ steps:
ARTIFACTS_FOLDER: "artifacts-to-sign"
# by default it will publish packages
DRY_RUN: "${DRY_RUN:-false}"
# Comma-separated list of package zip filenames to skip (e.g. "foo-1.0.0.zip,bar-2.0.0.zip")
# kubeletstats_input_otel-0.1.0 was deleted but it is kept in the repository for now, in case it is needed to release a new version if needed
SKIP_PACKAGES: "kubeletstats_input_otel-0.1.0.zip"
depends_on:
- step: "check"
allow_failure: false
Expand Down
Loading
Loading