Skip to content

Commit a9efa3e

Browse files
authored
[Buildkite] Add pipeline to test with Elastic serverless daily (elastic#1807)
Add pipeline to test with an Elastic serverless project daily. It also adds the required settings to trigger this pipeline from a Pull Request.
1 parent eba9ed5 commit a9efa3e

13 files changed

+480
-90
lines changed

.buildkite/hooks/pre-command

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ set -euo pipefail
66
GO_VERSION=$(cat .go-version)
77
export GO_VERSION
88

9+
export SERVERLESS=${SERVERLESS:-"false"}
10+
export WORKSPACE=$(pwd)
11+
12+
913
GCP_SERVICE_ACCOUNT_SECRET_PATH=secret/ci/elastic-elastic-package/gcp-service-account
1014
AWS_SERVICE_ACCOUNT_SECRET_PATH=kv/ci-shared/platform-ingest/aws_account_auth
1115
GITHUB_TOKEN_VAULT_PATH=kv/ci-shared/platform-ingest/github_token
1216
PRIVATE_CI_GCS_CREDENTIALS_PATH=kv/ci-shared/platform-ingest/gcp-platform-ingest-ci-service-account
1317

18+
EC_TOKEN_PATH=kv/ci-shared/platform-ingest/platform-ingest-ec-qa
19+
EC_DATA_PATH=secret/ci/elastic-elastic-package/ec_data
20+
1421
# variables required for terraform
1522
export ENVIRONMENT="ci"
1623
REPO=$(repo_name "${BUILDKITE_REPO}")
@@ -46,12 +53,24 @@ export CREATED_DATE
4653
# Secrets must be redacted
4754
# https://buildkite.com/docs/pipelines/managing-log-output#redacted-environment-variables
4855

56+
export TMP_FOLDER_TEMPLATE_BASE="tmp.${REPO}"
57+
export TMP_FOLDER_TEMPLATE="${TMP_FOLDER_TEMPLATE_BASE}.XXXXXXXXX"
58+
4959
is_step_required_to_upload_safe_logs() {
50-
if [[ "$BUILDKITE_PIPELINE_SLUG" != "elastic-package" ]]; then
60+
if [[ "$BUILDKITE_PIPELINE_SLUG" != "elastic-package" && "$BUILDKITE_PIPELINE_SLUG" != "elastic-package-test-serverless" ]]; then
5161
return 1
5262
fi
53-
if [[ "$BUILDKITE_STEP_KEY" =~ ^integration-parallel || "$BUILDKITE_STEP_KEY" =~ ^integration-false_positives ]]; then
54-
return 0
63+
64+
if [[ "$BUILDKITE_PIPELINE_SLUG" == "elastic-package" ]]; then
65+
if [[ "$BUILDKITE_STEP_KEY" =~ ^integration-parallel || "$BUILDKITE_STEP_KEY" =~ ^integration-false_positives ]]; then
66+
return 0
67+
fi
68+
fi
69+
70+
if [[ "$BUILDKITE_PIPELINE_SLUG" == "elastic-package-test-serverless" ]]; then
71+
if [[ "$BUILDKITE_STEP_KEY" == "test-serverless" ]]; then
72+
return 0
73+
fi
5574
fi
5675
return 1
5776
}
@@ -139,3 +158,17 @@ if [[ "$BUILDKITE_PIPELINE_SLUG" == "elastic-package-cloud-cleanup" && "$BUILDKI
139158
export ELASTIC_PACKAGE_GCP_EMAIL_SECRET
140159
fi
141160

161+
162+
if [[ "${BUILDKITE_PIPELINE_SLUG}" == "elastic-package-test-serverless" ]]; then
163+
if [[ "${BUILDKITE_STEP_KEY}" == "test-serverless" ]]; then
164+
EC_API_KEY_SECRET=$(retry 5 vault kv get -field apiKey "${EC_TOKEN_PATH}")
165+
export EC_API_KEY_SECRET
166+
EC_HOST_SECRET=$(retry 5 vault kv get -field url "${EC_TOKEN_PATH}")
167+
export EC_HOST_SECRET
168+
EC_REGION_SECRET=$(retry 5 vault read -field region_qa "${EC_DATA_PATH}")
169+
export EC_REGION_SECRET
170+
171+
GITHUB_TOKEN=$(retry 5 vault kv get -field token ${GITHUB_TOKEN_VAULT_PATH})
172+
export GITHUB_TOKEN
173+
fi
174+
fi

.buildkite/hooks/pre-exit

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ source .buildkite/scripts/tooling.sh
44

55
set -euo pipefail
66

7+
if [[ "${BUILDKITE_PIPELINE_SLUG}" == "elastic-package-test-serverless" && "${BUILDKITE_STEP_KEY}" == "test-serverless" ]]; then
8+
echo "--- Take down the Elastic stack"
9+
# BUILDKITE resets PATH contents in pre-exit hook, but elastic-package
10+
# is already installed in the test_serverless pipeline step, accessing
11+
# directly to the binary
12+
EC_API_KEY="${EC_API_KEY_SECRET}" EC_HOST="${EC_HOST_SECRET}" "${HOME}"/go/bin/elastic-package stack down -v
13+
fi
14+
15+
echo "--- Cleanup"
16+
cleanup
717
unset_secrets
818

919
# integrations-parallel-gcp
@@ -15,4 +25,3 @@ unset ELASTIC_PACKAGE_AWS_ACCESS_KEY
1525
unset ELASTIC_PACKAGE_AWS_SECRET_KEY
1626
unset AWS_ACCESS_KEY_ID
1727
unset AWS_SECRET_ACCESS_KEY
18-

.buildkite/pipeline.serverless.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
env:
2+
NOTIFY_TO: "[email protected]"
3+
SETUP_GVM_VERSION: 'v0.5.2' # https://github.com/andrewkroh/gvm/issues/44#issuecomment-1013231151
4+
DOCKER_COMPOSE_VERSION: "v2.24.1"
5+
DOCKER_VERSION: "26.1.0"
6+
KIND_VERSION: 'v0.20.0'
7+
K8S_VERSION: 'v1.29.0'
8+
LINUX_AGENT_IMAGE: "golang:${GO_VERSION}"
9+
GH_CLI_VERSION: "2.29.0"
10+
# Elastic package settings
11+
# Manage docker output/logs
12+
ELASTIC_PACKAGE_COMPOSE_DISABLE_VERBOSE_OUTPUT: "true"
13+
# Default license to use by `elastic-package build`
14+
ELASTIC_PACKAGE_REPOSITORY_LICENSE: "licenses/Elastic-2.0.txt"
15+
# Link definitions path (full path to be set in the corresponding step)
16+
ELASTIC_PACKAGE_LINKS_FILE_PATH: "links_table.yml"
17+
# Disable comparison of results in pipeline tests to avoid errors related to GeoIP fields
18+
ELASTIC_PACKAGE_SERVERLESS_PIPELINE_TEST_DISABLE_COMPARE_RESULTS: "true"
19+
20+
steps:
21+
- input: "Input values for the variables"
22+
key: "input-variables"
23+
fields:
24+
- select: "SERVERLESS_PROJECT"
25+
key: "SERVERLESS_PROJECT"
26+
options:
27+
- label: "observability"
28+
value: "observability"
29+
- label: "security"
30+
value: "security"
31+
default: "observability"
32+
if: "build.source == 'ui'"
33+
34+
- wait: ~
35+
if: "build.source == 'ui'"
36+
allow_dependency_failure: false
37+
38+
- label: ":elastic: Serverless Integration tests"
39+
key: test-serverless
40+
command: ".buildkite/scripts/test_packages_with_serverless.sh"
41+
env:
42+
SERVERLESS_PROJECT: "${SERVERLESS_PROJECT:-observability}"
43+
UPLOAD_SAFE_LOGS: 1
44+
artifact_paths:
45+
- build/test-results/*.xml
46+
- build/test-coverage/coverage-*.xml
47+
48+
- wait: ~
49+
continue_on_failure: true
50+
51+
- label: ":junit: Junit annotate"
52+
plugins:
53+
- junit-annotate#v2.4.1:
54+
artifacts: "build/test-results/*.xml"
55+
agents:
56+
provider: "gcp" # junit plugin requires docker
57+
58+
notify:
59+
- email: "$NOTIFY_TO"
60+
if: "build.state == 'failed' && build.env('BUILDKITE_PULL_REQUEST') == 'false'"

.buildkite/pull-requests.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@
3131
"skip_target_branches": [ ],
3232
"skip_ci_on_only_changed": [ ],
3333
"always_require_ci_on_changed": [ ]
34+
},
35+
{
36+
"enabled": true,
37+
"pipelineSlug": "elastic-package-test-serverless",
38+
"allow_org_users": true,
39+
"allowed_repo_permissions": ["admin", "write"],
40+
"allowed_list": [ ],
41+
"set_commit_status": false,
42+
"build_on_commit": false,
43+
"build_on_comment": true,
44+
"trigger_comment_regex": "^(?:(?:buildkite\\W+)?(?:test)\\W+(?:serverless))$",
45+
"always_trigger_comment_regex": "^(?:(?:buildkite\\W+)?(?:test)\\W+(?:serverless))$",
46+
"skip_ci_labels": [ ],
47+
"skip_target_branches": [ ],
48+
"skip_ci_on_only_changed": [ ],
49+
"always_require_ci_on_changed": [ ]
3450
}
3551
]
3652
}

.buildkite/scripts/integration_tests.sh

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ source .buildkite/scripts/tooling.sh
55

66
set -euo pipefail
77

8-
WORKSPACE="$(pwd)"
9-
TMP_FOLDER_TEMPLATE_BASE="tmp.elastic-package"
10-
11-
cleanup() {
8+
ensure_logout() {
129
local error_code=$?
1310

1411
if [ $error_code != 0 ] ; then
@@ -18,14 +15,9 @@ cleanup() {
1815
fi
1916
fi
2017

21-
echo "Deleting temporal files..."
22-
cd "${WORKSPACE}"
23-
rm -rf "${TMP_FOLDER_TEMPLATE_BASE}.*"
24-
echo "Done."
25-
2618
exit $error_code
2719
}
28-
trap cleanup EXIT
20+
trap ensure_logout EXIT
2921

3022
usage() {
3123
echo "$0 [-t <target>] [-h]"
@@ -39,22 +31,25 @@ PARALLEL_TARGET="test-check-packages-parallel"
3931
FALSE_POSITIVES_TARGET="test-check-packages-false-positives"
4032
KIND_TARGET="test-check-packages-with-kind"
4133
SYSTEM_TEST_FLAGS_TARGET="test-system-test-flags"
42-
TMP_FOLDER_TEMPLATE="${TMP_FOLDER_TEMPLATE_BASE}.XXXXXXXXX"
4334
GOOGLE_CREDENTIALS_FILENAME="google-cloud-credentials.json"
4435
ELASTIC_PACKAGE_TEST_ENABLE_INDEPENDENT_AGENT=${ELASTIC_PACKAGE_TEST_ENABLE_INDEPENDENT_AGENT:-"false"}
4536

4637
REPO_NAME=$(repo_name "${BUILDKITE_REPO}")
47-
REPO_BUILD_TAG="${REPO_NAME}/$(buildkite_pr_branch_build_id)"
38+
export REPO_BUILD_TAG="${REPO_NAME}/$(buildkite_pr_branch_build_id)"
4839
TARGET=""
4940
PACKAGE=""
50-
while getopts ":t:p:h" o; do
41+
SERVERLESS="false"
42+
while getopts ":t:p:sh" o; do
5143
case "${o}" in
5244
t)
5345
TARGET=${OPTARG}
5446
;;
5547
p)
5648
PACKAGE=${OPTARG}
5749
;;
50+
s)
51+
SERVERLESS="true"
52+
;;
5853
h)
5954
usage
6055
exit 0
@@ -78,57 +73,37 @@ if [[ "${TARGET}" == "" ]]; then
7873
exit 1
7974
fi
8075

81-
google_cloud_auth_safe_logs() {
82-
local gsUtilLocation=""
83-
gsUtilLocation=$(mktemp -d -p "${WORKSPACE}" -t "${TMP_FOLDER_TEMPLATE}")
84-
85-
local secretFileLocation=${gsUtilLocation}/${GOOGLE_CREDENTIALS_FILENAME}
86-
87-
echo "${PRIVATE_CI_GCS_CREDENTIALS_SECRET}" > "${secretFileLocation}"
88-
89-
google_cloud_auth "${secretFileLocation}"
90-
}
91-
92-
upload_safe_logs() {
93-
local bucket="$1"
94-
local source="$2"
95-
local target="$3"
96-
97-
if ! ls ${source} 2>&1 > /dev/null ; then
98-
echo "upload_safe_logs: artifacts files not found, nothing will be archived"
99-
return
100-
fi
101-
102-
google_cloud_auth_safe_logs
103-
104-
gsutil cp ${source} "gs://${bucket}/buildkite/${REPO_BUILD_TAG}/${target}"
105-
106-
google_cloud_logout_active_account
107-
}
108-
10976
add_bin_path
11077

111-
echo "--- install go"
112-
with_go
78+
if [[ "$SERVERLESS" == "false" ]]; then
79+
# If packages are tested with Serverless, these action are already performed
80+
# here: .buildkite/scripts/test_packages_with_serverless.sh
81+
echo "--- install go"
82+
with_go
11383

114-
echo "--- install docker"
115-
with_docker
84+
echo "--- install docker"
85+
with_docker
11686

117-
echo "--- install docker-compose plugin"
118-
with_docker_compose_plugin
87+
echo "--- install docker-compose plugin"
88+
with_docker_compose_plugin
89+
fi
11990

12091
if [[ "${TARGET}" == "${KIND_TARGET}" || "${TARGET}" == "${SYSTEM_TEST_FLAGS_TARGET}" ]]; then
12192
echo "--- install kubectl & kind"
12293
with_kubernetes
12394
fi
12495

125-
echo "--- Run integration test ${TARGET}"
96+
label="${TARGET}"
97+
if [ -n "${PACKAGE}" ]; then
98+
label="${label} - ${PACKAGE}"
99+
fi
100+
echo "--- Run integration test ${label}"
126101
if [[ "${TARGET}" == "${PARALLEL_TARGET}" ]] || [[ "${TARGET}" == "${FALSE_POSITIVES_TARGET}" ]]; then
127102
make install
128103

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

@@ -162,7 +137,7 @@ if [[ "${TARGET}" == "${PARALLEL_TARGET}" ]] || [[ "${TARGET}" == "${FALSE_POSIT
162137
fi
163138

164139
if [ $testReturnCode != 0 ]; then
165-
echo "make PACKAGE_UDER_TEST=${PACKAGE} ${TARGET} failed with ${testReturnCode}"
140+
echo "make SERVERLESS=${SERVERLESS} PACKAGE_UNDER_TEST=${PACKAGE} ${TARGET} failed with ${testReturnCode}"
166141
exit ${testReturnCode}
167142
fi
168143

.buildkite/scripts/release.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#!/bin/bash
22

3+
source .buildkite/scripts/install_deps.sh
4+
source .buildkite/scripts/tooling.sh
5+
36
set -euo pipefail
47

58
cleanup() {
69
rm -rf "${WORKSPACE}"
710
}
811
trap cleanup exit
912

10-
WORKSPACE="/tmp/bin-buildkite/"
13+
export WORKSPACE="/tmp/bin-buildkite/"
1114

1215
VERSION=""
13-
source .buildkite/scripts/install_deps.sh
14-
source .buildkite/scripts/tooling.sh
1516

1617
add_bin_path
1718
with_go

.buildkite/scripts/test-with-integrations.sh

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,6 @@ source .buildkite/scripts/install_deps.sh
33

44
set -euo pipefail
55

6-
WORKSPACE="$(pwd)"
7-
8-
TMP_FOLDER_TEMPLATE_BASE="tmp.${GITHUB_PR_BASE_REPO}"
9-
TMP_FOLDER_TEMPLATE="${TMP_FOLDER_TEMPLATE_BASE}.XXXXXXXXX"
10-
11-
cleanup() {
12-
echo "Deleting temporal files..."
13-
cd "${WORKSPACE}"
14-
rm -rf "${TMP_FOLDER_TEMPLATE_BASE}.*"
15-
echo "Done."
16-
}
17-
18-
trap cleanup EXIT
19-
206
add_bin_path
217

228
echo "--- install gh cli"
@@ -179,10 +165,10 @@ add_pr_comment() {
179165
local source_pr_number="$1"
180166
local integrations_pr_link="$2"
181167

182-
retry 3 \
183-
gh pr comment "${source_pr_number}" \
184-
--body "Created or updated PR in integrations repository to test this version. Check ${integrations_pr_link}" \
185-
--repo "${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}"
168+
add_github_comment \
169+
"${GITHUB_PR_BASE_OWNER}/${GITHUB_PR_BASE_REPO}" \
170+
"${source_pr_number}" \
171+
"Created or updated PR in integrations repository to test this version. Check ${integrations_pr_link}"
186172
}
187173

188174

0 commit comments

Comments
 (0)