Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
38e398b
Add more collapsed sections in CI output
mrodm Jun 5, 2025
3c71322
Update collapsed section titles
mrodm Jun 5, 2025
5f91789
Avoid running stack dump and down if stack is not started
mrodm Jun 6, 2025
c774108
Test failure
mrodm Jun 6, 2025
18e885f
Ensure failed group is opened - Buildkite output
mrodm Jun 6, 2025
2c8c36f
Run stack down command in any case to shutdown all containers
mrodm Jun 6, 2025
269a449
Run dump and ensure it does not exit build to continue cleanup process
mrodm Jun 6, 2025
75831b4
Rephrase group title
mrodm Jun 6, 2025
a5ca34a
Remove set x flag in build zip scripts
mrodm Jun 10, 2025
7bf29af
Change to uppercase
mrodm Jul 22, 2025
df812de
yq is not required in Serverless builds
mrodm Jul 22, 2025
93e4ff1
Add comment
mrodm Jul 22, 2025
a314998
Install elastic-package just once in Serverless
mrodm Jul 22, 2025
569ca1c
Show just one message to upload safe logs
mrodm Jul 23, 2025
5ba8b0f
Fix lint error
mrodm Jul 23, 2025
dce92ea
Ensure all steps in pre-exit are executed
mrodm Jul 23, 2025
2bfa9d8
Move definition of SERVERLESS variable to pipeline
mrodm Jul 23, 2025
823cc6f
Fix condition pre-exit hook
mrodm Jul 23, 2025
2a241b5
Run dump and stack down commands if stack has been created
mrodm Jul 23, 2025
c5d81fa
Remove debug in pre-exit
mrodm Jul 23, 2025
85a83ca
Add check about serverless and targets
mrodm Jul 23, 2025
9a048e1
Revert refactor upload safe logs
mrodm Jul 23, 2025
192ba69
Test with set -x flag
mrodm Jul 24, 2025
91303e9
Test adding a subshell for testtype func
mrodm Jul 24, 2025
7174187
Use subshell and add more collapsed groups in build-install scripts
mrodm Jul 24, 2025
9b035ed
Ignore errors dumping logs in cleanup
mrodm Jul 24, 2025
de15917
Add set +x in a subshell to get stack arguments
mrodm Jul 24, 2025
c990503
Add collapsed groups
mrodm Jul 24, 2025
6e33bd7
Move set flags
mrodm Jul 24, 2025
80b23a6
Apply missing set +x to get test type
mrodm Jul 24, 2025
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
7 changes: 6 additions & 1 deletion .buildkite/hooks/pre-exit
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ source .buildkite/scripts/tooling.sh

set -euo pipefail

exit_code=0
if [[ "${BUILDKITE_PIPELINE_SLUG}" == "elastic-package-test-serverless" && "${BUILDKITE_STEP_KEY}" == "test-serverless" ]]; then
echo "--- Take down the Elastic stack"
# BUILDKITE resets PATH contents in pre-exit hook, but elastic-package
# is already installed in the test_serverless pipeline step, accessing
# directly to the binary
"${HOME}"/go/bin/elastic-package stack down -v
if ! "${HOME}"/go/bin/elastic-package stack down -v ; then
# Ensure that even if this command fails, the script continues
exit_code=1
fi
fi

echo "--- Cleanup"
cleanup
unset_secrets

exit "$exit_code"
1 change: 1 addition & 0 deletions .buildkite/pipeline.serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ steps:
provider: "gcp"
image: "${UBUNTU_X86_64_AGENT_IMAGE}"
env:
SERVERLESS: "true"
SERVERLESS_PROJECT: "${SERVERLESS_PROJECT:-observability}"
UPLOAD_SAFE_LOGS: 1
# See https://github.com/elastic/oblt-infra/blob/main/conf/resources/repos/integrations/01-gcp-buildkite-oidc.tf
Expand Down
54 changes: 38 additions & 16 deletions .buildkite/scripts/integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ FALSE_POSITIVES_TARGET="test-check-packages-false-positives"
KIND_TARGET="test-check-packages-with-kind"
SYSTEM_TEST_FLAGS_TARGET="test-system-test-flags"
TEST_BUILD_ZIP_TARGET="test-build-zip"
TEST_BUILD_INSTALL_ZIP_TARGET="test-build-install-zip"

REPO_NAME=$(repo_name "${BUILDKITE_REPO}")
export REPO_BUILD_TAG="${REPO_NAME}/$(buildkite_pr_branch_build_id)"
REPO_BUILD_TAG="${REPO_NAME}/$(buildkite_pr_branch_build_id)"
export REPO_BUILD_TAG
TARGET=""
PACKAGE=""
SERVERLESS="false"
Expand Down Expand Up @@ -58,50 +60,67 @@ if [[ "${TARGET}" == "" ]]; then
exit 1
fi

if [[ "${SERVERLESS}" == "true" && "${TARGET}" != "${PARALLEL_TARGET}" ]]; then
# Just tested parallel target to run with Serverless projects, other Makefile targets
# have not been tested yet and could fail unexpectedly. For instance, "test-check-package-false-positives"
# target would require a different management to not stop Elastic stack after each package test.
echo "Target ${TARGET} is not supported for Serverless testing"
usage
exit 1
fi

add_bin_path

if [[ "$SERVERLESS" == "false" ]]; then
# If packages are tested with Serverless, these action are already performed
# If packages are tested with Serverless, these actions are already performed
# here: .buildkite/scripts/test_packages_with_serverless.sh
echo "--- install go"
echo "--- Install go"
with_go

if [[ "${TARGET}" != "${TEST_BUILD_ZIP_TARGET}" ]]; then
# Not supported in Macos ARM
echo "--- install docker"
echo "--- Install docker"
with_docker

echo "--- install docker-compose plugin"
echo "--- Install docker-compose plugin"
with_docker_compose_plugin
fi
fi

echo "--- install yq"
with_yq
# In Serverless pipeline, elastic-package is installed in advance here:
# .buildkite/scripts/test_packages_with_serverless.sh
# No need to install it again for every package.
echo "--- Install elastic-package"
make install
fi

if [[ "${TARGET}" == "${KIND_TARGET}" || "${TARGET}" == "${SYSTEM_TEST_FLAGS_TARGET}" ]]; then
echo "--- install kubectl & kind"
echo "--- Install kubectl & kind"
with_kubernetes
fi

if [[ "${TARGET}" == "${TEST_BUILD_INSTALL_ZIP_TARGET}" || "${TARGET}" == "${FALSE_POSITIVES_TARGET}" ]]; then
echo "--- Install yq"
with_yq
fi
Comment on lines +101 to +104
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to install yq in other targets for now.


label="${TARGET}"
if [ -n "${PACKAGE}" ]; then
label="${label} - ${PACKAGE}"
fi

echo "--- Run integration test ${label}"
if [[ "${TARGET}" == "${PARALLEL_TARGET}" ]] || [[ "${TARGET}" == "${FALSE_POSITIVES_TARGET}" ]]; then
make install

# allow to fail this command, to be able to upload safe logs
set +e
make SERVERLESS="${SERVERLESS}" PACKAGE_UNDER_TEST="${PACKAGE}" "${TARGET}"
testReturnCode=$?
set -e

retry_count=${BUILDKITE_RETRY_COUNT:-"0"}

if [[ "${UPLOAD_SAFE_LOGS}" -eq 1 ]] ; then
retry_count=${BUILDKITE_RETRY_COUNT:-"0"}
package_folder="${PACKAGE}"

if [[ "${ELASTIC_PACKAGE_TEST_ENABLE_INDEPENDENT_AGENT:-""}" == "false" ]]; then
package_folder="${package_folder}-stack_agent"
fi
Expand All @@ -114,6 +133,8 @@ if [[ "${TARGET}" == "${PARALLEL_TARGET}" ]] || [[ "${TARGET}" == "${FALSE_POSIT
package_folder="${package_folder}_retry_${retry_count}"
fi

echo "--- Uploading safe logs to GCP bucket ${JOB_GCS_BUCKET_INTERNAL}"

upload_safe_logs \
"${JOB_GCS_BUCKET_INTERNAL}" \
"build/elastic-stack-dump/check-${PACKAGE}/logs/elastic-agent-internal/*.*" \
Expand All @@ -135,9 +156,10 @@ if [[ "${TARGET}" == "${PARALLEL_TARGET}" ]] || [[ "${TARGET}" == "${FALSE_POSIT
echo "make SERVERLESS=${SERVERLESS} PACKAGE_UNDER_TEST=${PACKAGE} ${TARGET} failed with ${testReturnCode}"
exit ${testReturnCode}
fi

make check-git-clean
exit 0
else
make "${TARGET}"
fi

make install "${TARGET}" check-git-clean
echo "--- Check git clean"
make check-git-clean
exit 0
4 changes: 2 additions & 2 deletions .buildkite/scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ VERSION=""
add_bin_path
with_go

echo "--- fetching tags"
echo "--- Fetching tags"
# Ensure that tags are present so goreleaser can build the changelog from the last release.
git rev-parse --is-shallow-repository
git fetch origin --tags

echo "--- running goreleaser"
echo "--- Running goreleaser"
# Run latest version of goreleaser
curl -sL https://git.io/goreleaser | bash
10 changes: 5 additions & 5 deletions .buildkite/scripts/test-with-integrations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ set -euo pipefail

add_bin_path

echo "--- install gh cli"
echo "--- Install gh cli"
with_github_cli

echo "--- install jq"
echo "--- Install jq"
with_jq


Expand Down Expand Up @@ -87,7 +87,7 @@ create_integrations_pull_request() {

update_dependency() {
# it needs to set the Golang version from the integrations repository (.go-version file)
echo "--- install go for integrations repository :go:"
echo "--- Install go for integrations repository :go:"
with_go

echo "--- Updating go.mod and go.sum with ${GITHUB_PR_HEAD_SHA} :hammer_and_wrench:"
Expand Down Expand Up @@ -167,7 +167,7 @@ create_or_update_pull_request() {

rm -rf "${temp_path}"

echo "--- adding comment into ${GITHUB_PR_BASE_REPO} pull request :memo:"
echo "--- Adding comment into ${GITHUB_PR_BASE_REPO} pull request :memo:"
add_pr_comment "${BUILDKITE_PULL_REQUEST}" "$(get_integrations_pr_link "${integrations_pr_number}")"
}

Expand All @@ -186,5 +186,5 @@ if [[ "${BUILDKITE_PULL_REQUEST}" == "false" ]]; then
exit 1
fi

echo "--- creating or updating integrations pull request"
echo "--- Creating or updating integrations pull request"
create_or_update_pull_request
5 changes: 2 additions & 3 deletions .buildkite/scripts/test_packages_with_serverless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ UPLOAD_SAFE_LOGS=${UPLOAD_SAFE_LOGS:-"0"}
SKIPPED_PACKAGES_FILE_PATH="${WORKSPACE}/skipped_packages.txt"
FAILED_PACKAGES_FILE_PATH="${WORKSPACE}/failed_packages.txt"

export SERVERLESS="true"
SERVERLESS_PROJECT=${SERVERLESS_PROJECT:-"observability"}

add_pr_comment() {
Expand All @@ -32,7 +31,7 @@ fi

add_bin_path

echo "--- install go"
echo "--- Install go"
with_go

echo "--- Install docker"
Expand All @@ -42,7 +41,7 @@ echo "--- Install docker-compose"
with_docker_compose_plugin

if [[ "${BUILDKITE_PULL_REQUEST}" != "false" ]]; then
echo "--- install gh cli"
echo "--- Install gh cli"
with_github_cli

add_pr_comment "${BUILDKITE_PULL_REQUEST}" "${BUILDKITE_BUILD_URL}"
Expand Down
2 changes: 0 additions & 2 deletions .buildkite/scripts/tooling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ upload_safe_logs() {
local source="$2"
local target="$3"

echo "--- Uploading safe logs to GCP bucket ${bucket}"

if ! ls ${source} 2>&1 > /dev/null ; then
echo "upload_safe_logs: artifacts files not found, nothing will be archived"
return
Expand Down
2 changes: 1 addition & 1 deletion .buildkite/scripts/unit_tests_macos_arm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -euo pipefail

add_bin_path

echo "--- install go"
echo "--- Install go"
with_go

echo "--- Running unit tests"
Expand Down
13 changes: 13 additions & 0 deletions scripts/stack_helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -euo pipefail

is_stack_created() {
local files=0
files=$(find ~/.elastic-package -type f -name "docker-compose.yml" | wc -l)
if [ "${files}" -gt 0 ]; then
return 0
fi
return 1
}

Comment on lines +5 to +13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helper function to know if elastic-package stack up command has been performed or not.

There could be packages that fail in elastic-package check command and if so, the Elastic stack has not been created.

This is helpful to avoid running commands like elastic-package stack <dump|down> that are going to fail.

16 changes: 14 additions & 2 deletions scripts/test-build-install-zip-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ set -euxo pipefail

cleanup() {
local r=$?
if [ "${r}" -ne 0 ]; then
# Ensure that the group where the failure happened is opened.
echo "^^^ +++"
fi
echo "~~~ elastic-package cleanup"

local output_path="build/elastic-stack-dump/install-zip"
if [ ${USE_SHELLINIT} -eq 1 ]; then
output_path="${output_path}-shellinit"
fi

# Dump stack logs
elastic-package stack dump -v --output ${output_path}
# Required containers could not be running, so ignore the error
elastic-package stack dump -v --output ${output_path} || true

# Take down the stack
elastic-package stack down -v
Expand Down Expand Up @@ -39,6 +45,7 @@ installAndVerifyPackage() {
# e.g. "apache-999.999.999" becomes "apache/999.999.999"
PACKAGE_NAME_VERSION="${PACKAGE_NAME_VERSION//-/\/}"

echo "--- Installing package: ${PACKAGE_NAME_VERSION}"
elastic-package install -v --zip "${zipFile}"

# check that the package is installed
Expand Down Expand Up @@ -90,6 +97,7 @@ if [ "${STACK_VERSION}" != "default" ]; then
ARG_VERSION="--version ${STACK_VERSION}"
fi

echo "--- Prepare Elastic stack"
# Update the stack
elastic-package stack update -v ${ARG_VERSION}

Expand All @@ -101,10 +109,14 @@ export ELASTIC_PACKAGE_LINKS_FILE_PATH

# Build packages
for d in test/packages/*/*/; do
# Added set +x in a sub-shell to avoid printing the testype command in the output
# This helps to keep the CI output cleaner
packageTestType=$(set +x ; testype "$d")
# Packages in false_positives can have issues.
if [ "$(testype "$d")" == "false_positives" ]; then
if [ "${packageTestType}" == "false_positives" ]; then
continue
fi
echo "--- Building zip package: ${d}"
elastic-package build -C "$d"
done

Expand Down
20 changes: 16 additions & 4 deletions scripts/test-build-install-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
set -euxo pipefail

cleanup() {
r=$?
local r=$?
if [ "${r}" -ne 0 ]; then
# Ensure that the group where the failure happened is opened.
echo "^^^ +++"
fi
echo "~~~ elastic-package cleanup"

# Dump stack logs
elastic-package stack dump -v --output build/elastic-stack-dump/build-zip
# Required containers could not be running, so ignore the error
elastic-package stack dump -v --output build/elastic-stack-dump/build-zip || true
Comment on lines +14 to +15
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of the error to try to avoid:
https://buildkite.com/elastic/elastic-package/builds/5786#01983b8a-52f4-4906-a5fe-7379469778ed/350-608

This will help to continue running the other commands in the cleanup function.


# Take down the stack
elastic-package stack down -v
Expand Down Expand Up @@ -36,16 +42,21 @@ export ELASTIC_PACKAGE_LINKS_FILE_PATH
go run ./scripts/gpgkey

for d in test/packages/*/*/; do
# Added set +x in a sub-shell to avoid printing the testype command in the output
# This helps to keep the CI output cleaner
packageTestType=$(set +x ; testype "$d")
# Packages in false_positives can have issues.
if [ "$(testype $d)" == "false_positives" ]; then
if [ "${packageTestType}" == "false_positives" ]; then
continue
fi
echo "--- Building package: ${d}"
elastic-package build -C "$d" --zip --sign -v
done

# Remove unzipped built packages, leave .zip files
rm -r build/packages/*/

echo "--- Prepare Elastic stack"
# Boot up the stack
elastic-package stack up -d -v

Expand All @@ -54,12 +65,13 @@ eval "$(elastic-package stack shellinit)"
# Install packages from working copy
for d in test/packages/*/*/; do
# Packages in false_positives can have issues.
if [ "$(testype $d)" == "false_positives" ]; then
if [ "$(testype "$d")" == "false_positives" ]; then
continue
fi
package_name=$(yq -r '.name' "${d}/manifest.yml")
package_version=$(yq -r '.version' "${d}/manifest.yml")

echo "--- Installing package: ${package_name} (${package_version})"
elastic-package install -C "$d" -v

# check that the package is installed
Expand Down
14 changes: 11 additions & 3 deletions scripts/test-build-zip.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/bin/bash

set -euxo pipefail

cleanup() {
r=$?
local r=$?
if [ "${r}" -ne 0 ]; then
# Ensure that the group where the failure happened is opened.
echo "^^^ +++"
fi
echo "~~~ elastic-package cleanup"

# Clean used resources
for d in test/packages/*/*/; do
Expand All @@ -30,10 +34,14 @@ export ELASTIC_PACKAGE_LINKS_FILE_PATH
go run ./scripts/gpgkey

for d in test/packages/*/*/; do
# Added set +x in a sub-shell to avoid printing the testype command in the output
# This helps to keep the CI output cleaner
packageTestType=$(set +x ; testype "$d")
# Packages in false_positives can have issues.
if [ "$(testype $d)" == "false_positives" ]; then
if [ "${packageTestType}" == "false_positives" ]; then
continue
fi
echo "--- Building zip package: ${d}"
elastic-package build -C "$d" --zip --sign -v
done

Expand Down
Loading