Skip to content

Commit fbd1e57

Browse files
committed
Merge remote-tracking branch 'origin/main' into profile-resources-refactor
2 parents 6aac244 + a08a960 commit fbd1e57

17 files changed

+442
-121
lines changed

.buildkite/hooks/pre-command

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,17 @@ GCP_SERVICE_ACCOUNT_SECRET_PATH=secret/ci/elastic-elastic-package/gcp-service-ac
2626
AWS_SERVICE_ACCOUNT_SECRET_PATH=kv/ci-shared/platform-ingest/aws_account_auth
2727
GITHUB_TOKEN_VAULT_PATH=kv/ci-shared/platform-ingest/github_token
2828
JENKINS_API_TOKEN_PATH=kv/ci-shared/platform-ingest/jenkins_api_tokens
29+
SIGNING_PACKAGES_GCS_CREDENTIALS_PATH=kv/ci-shared/platform-ingest/signing_packages_gcs_artifacts_credentials
30+
PACKAGE_UPLOADER_GCS_CREDENTIALS_PATH=kv/ci-shared/platform-ingest/package_storage_uploader
31+
PRIVATE_CI_GCS_CREDENTIALS_PATH=kv/ci-shared/platform-ingest/private_ci_artifacts_gcs_credentials
2932

3033
# Secrets must be redacted
3134
# https://buildkite.com/docs/pipelines/managing-log-output#redacted-environment-variables
3235

36+
if [[ "$BUILDKITE_PIPELINE_SLUG" == "elastic-package" && "$BUILDKITE_STEP_KEY" =~ ^integration-parallel ]]; then
37+
export PRIVATE_CI_GCS_CREDENTIALS_SECRET=$(retry 5 vault kv get -field plaintext ${PRIVATE_CI_GCS_CREDENTIALS_PATH})
38+
fi
39+
3340
if [[ "$BUILDKITE_PIPELINE_SLUG" == "elastic-package" && "$BUILDKITE_STEP_KEY" == "integration-parallel-gcp" ]]; then
3441
export ELASTIC_PACKAGE_GCP_PROJECT_SECRET=$(retry 5 vault read -field projectId ${GCP_SERVICE_ACCOUNT_SECRET_PATH})
3542
export ELASTIC_PACKAGE_GCP_CREDENTIALS_SECRET=$(retry 5 vault read -field credentials ${GCP_SERVICE_ACCOUNT_SECRET_PATH})
@@ -56,4 +63,10 @@ if [[ "$BUILDKITE_PIPELINE_SLUG" == "elastic-package-package-storage-publish" &&
5663
export JENKINS_USERNAME_SECRET=$(retry 5 vault kv get -field username ${JENKINS_API_TOKEN_PATH})
5764
export JENKINS_HOST_SECRET=$(retry 5 vault kv get -field internal_ci_host ${JENKINS_API_TOKEN_PATH})
5865
export JENKINS_TOKEN=$(retry 5 vault kv get -field internal_ci ${JENKINS_API_TOKEN_PATH})
66+
67+
# signing job
68+
export SIGNING_PACKAGES_GCS_CREDENTIALS_SECRET=$(retry 5 vault kv get -field value ${SIGNING_PACKAGES_GCS_CREDENTIALS_PATH})
69+
70+
# publishing job
71+
export PACKAGE_UPLOADER_GCS_CREDENTIALS_SECRET=$(retry 5 vault kv get -field value ${PACKAGE_UPLOADER_GCS_CREDENTIALS_PATH})
5972
fi
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
steps:
2-
- label: "Example Test"
3-
command: echo "Hello!"
1+
env:
2+
SETUP_GVM_VERSION: 'v0.5.0' # https://github.com/andrewkroh/gvm/issues/44#issuecomment-1013231151
43

4+
steps:
55
- label: ":go: Build package"
66
key: build-package
77
command:
@@ -11,10 +11,15 @@ steps:
1111
image: "golang:1.19.5"
1212
cpu: "8"
1313
memory: "4G"
14+
artifact_paths:
15+
- build/packages/*.zip
1416

15-
- label: "Test"
17+
- label: "Sign and Publish package"
1618
key: sign-publish
1719
command: ".buildkite/scripts/signAndPublishPackage.sh"
20+
depends_on:
21+
- build-package
22+
timeout_in_minutes: 30
1823
agents:
1924
provider: "gcp"
2025
image: family/core-ubuntu-2004

.buildkite/pipeline.trigger.integration.tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ for package in $(find . -maxdepth 1 -mindepth 1 -type d) ; do
5656
echo " - label: \":go: Running integration test: ${package_name}\""
5757
echo " key: \"integration-parallel-${package_name}\""
5858
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-check-packages-parallel -p ${package_name}"
59+
echo " env:"
60+
echo " UPLOAD_SAFE_LOGS: 1"
5961
echo " agents:"
6062
echo " provider: \"gcp\""
6163
echo " artifact_paths:"

.buildkite/pipeline.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
env:
22
SETUP_GVM_VERSION: 'v0.5.0' # https://github.com/andrewkroh/gvm/issues/44#issuecomment-1013231151
33
DOCKER_COMPOSE_VERSION: "1.25.5" # "v2.15.1"
4+
ELASTIC_PACKAGE_COMPOSE_DISABLE_ANSI: "true"
45
KIND_VERSION: 'v0.17.0'
56
K8S_VERSION: 'v1.26.0'
67

@@ -56,11 +57,8 @@ steps:
5657

5758
- label: ":github: Release"
5859
key: "release"
59-
# build.tag != null && build.branch == "main"
6060
if: |
6161
build.tag =~ /^v[0-9]+[.][0-9]+[.][0-9]+$$/
6262
command: ".buildkite/scripts/release.sh"
6363
agents:
64-
image: "golang:1.19.5"
65-
cpu: "8"
66-
memory: "4G"
64+
provider: "gcp"

.buildkite/scripts/install_deps.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
source .buildkite/scripts/tooling.sh
6+
7+
add_bin_path(){
8+
mkdir -p ${WORKSPACE}/bin
9+
export PATH="${WORKSPACE}/bin:${PATH}"
10+
}
11+
12+
with_kubernetes() {
13+
mkdir -p ${WORKSPACE}/bin
14+
retry 5 curl -sSLo ${WORKSPACE}/bin/kind "https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64"
15+
chmod +x ${WORKSPACE}/bin/kind
16+
kind version
17+
which kind
18+
19+
mkdir -p ${WORKSPACE}/bin
20+
retry 5 curl -sSLo ${WORKSPACE}/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl"
21+
chmod +x ${WORKSPACE}/bin/kubectl
22+
kubectl version --client
23+
which kubectl
24+
}
25+
26+
with_go() {
27+
mkdir -p ${WORKSPACE}/bin
28+
retry 5 curl -sL -o ${WORKSPACE}/bin/gvm "https://github.com/andrewkroh/gvm/releases/download/${SETUP_GVM_VERSION}/gvm-linux-amd64"
29+
chmod +x ${WORKSPACE}/bin/gvm
30+
eval "$(gvm $(cat .go-version))"
31+
go version
32+
which go
33+
export PATH="$(go env GOPATH)/bin:${PATH}"
34+
}
35+
36+
with_docker_compose() {
37+
mkdir -p ${WORKSPACE}/bin
38+
retry 5 curl -SL -o ${WORKSPACE}/bin/docker-compose "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-linux-x86_64"
39+
chmod +x ${WORKSPACE}/bin/docker-compose
40+
docker-compose version
41+
}

.buildkite/scripts/integration_tests.sh

Lines changed: 63 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
#!/bin/bash
2-
32
set -euo pipefail
43

5-
PARALLEL_TARGET="test-check-packages-parallel"
6-
KIND_TARGET="test-check-packages-with-kind"
4+
WORKSPACE="$(pwd)"
5+
TMP_FOLDER_TEMPLATE_BASE="tmp.elastic-package"
6+
7+
cleanup() {
8+
echo "Deleting temporal files..."
9+
cd ${WORKSPACE}
10+
rm -rf "${TMP_FOLDER_TEMPLATE_BASE}.*"
11+
echo "Done."
12+
}
13+
trap cleanup EXIT
714

815
usage() {
916
echo "$0 [-t <target>] [-h]"
@@ -13,38 +20,18 @@ usage() {
1320
echo -e "\t-h: Show this message"
1421
}
1522

16-
with_kubernetes() {
17-
# FIXME add retry logic
18-
mkdir -p ${WORKSPACE}/bin
19-
curl -sSLo ${WORKSPACE}/bin/kind "https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64"
20-
chmod +x ${WORKSPACE}/bin/kind
21-
kind version
22-
which kind
23-
24-
mkdir -p ${WORKSPACE}/bin
25-
curl -sSLo ${WORKSPACE}/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl"
26-
chmod +x ${WORKSPACE}/bin/kubectl
27-
kubectl version --client
28-
which kubectl
29-
}
23+
source .buildkite/scripts/install_deps.sh
24+
source .buildkite/scripts/tooling.sh
3025

31-
with_go() {
32-
# FIXME add retry logic
33-
mkdir -p ${WORKSPACE}/bin
34-
curl -sL -o ${WORKSPACE}/bin/gvm "https://github.com/andrewkroh/gvm/releases/download/${SETUP_GVM_VERSION}/gvm-linux-amd64"
35-
chmod +x ${WORKSPACE}/bin/gvm
36-
eval "$(gvm $(cat .go-version))"
37-
go version
38-
which go
39-
}
26+
PARALLEL_TARGET="test-check-packages-parallel"
27+
KIND_TARGET="test-check-packages-with-kind"
28+
TMP_FOLDER_TEMPLATE="${TMP_FOLDER_TEMPLATE_BASE}.XXXXXXXXX"
29+
GOOGLE_CREDENTIALS_FILENAME="google-cloud-credentials.json"
4030

41-
with_docker_compose() {
42-
# FIXME add retry logic
43-
mkdir -p ${WORKSPACE}/bin
44-
curl -SL -o ${WORKSPACE}/bin/docker-compose "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-linux-x86_64"
45-
chmod +x ${WORKSPACE}/bin/docker-compose
46-
docker-compose version
47-
}
31+
JOB_GCS_BUCKET_INTERNAL="fleet-ci-temp-internal"
32+
33+
REPO_NAME=$(repoName "${BUILDKITE_REPO}")
34+
REPO_BUILD_TAG="${REPO_NAME}/${BUILDKITE_BUILD_NUMBER}"
4835

4936
TARGET=""
5037
PACKAGE=""
@@ -79,14 +66,39 @@ if [[ "${TARGET}" == "" ]]; then
7966
exit 1
8067
fi
8168

82-
echo "Current path: $(pwd)"
83-
WORKSPACE="$(pwd)"
84-
export PATH="${WORKSPACE}/bin:${PATH}"
85-
echo "Path: $PATH"
69+
google_cloud_auth_safe_logs() {
70+
local gsUtilLocation=$(mktemp -d -p . -t ${TMP_FOLDER_TEMPLATE})
71+
local secretFileLocation=${gsUtilLocation}/${GOOGLE_CREDENTIALS_FILENAME}
72+
73+
echo "${PRIVATE_CI_GCS_CREDENTIALS_SECRET}" > ${secretFileLocation}
74+
75+
google_cloud_auth "${secretFileLocation}"
76+
77+
echo "${gsUtilLocation}"
78+
}
79+
80+
upload_safe_logs() {
81+
local bucket="$1"
82+
local source="$2"
83+
local target="$3"
84+
85+
if ! ls ${source} 2>&1 > /dev/null ; then
86+
echo "upload_safe_logs: artifacts files not found, nothing will be archived"
87+
return
88+
fi
89+
90+
local gsUtilLocation=$(google_cloud_auth_safe_logs)
91+
92+
gsutil cp ${source} "gs://${bucket}/buildkite/${REPO_BUILD_TAG}/${target}"
93+
94+
rm -rf "${gsUtilLocation}"
95+
unset GOOGLE_APPLICATIONS_CREDENTIALS
96+
}
97+
98+
add_bin_path
8699

87100
echo "--- install go"
88101
with_go
89-
export PATH="$(go env GOPATH)/bin:${PATH}"
90102

91103
echo "--- install docker-compose"
92104
with_docker_compose
@@ -100,6 +112,19 @@ echo "--- Run integration test ${TARGET}"
100112
if [[ "${TARGET}" == "${PARALLEL_TARGET}" ]]; then
101113
make install
102114
make PACKAGE_UNDER_TEST=${PACKAGE} ${TARGET}
115+
116+
if [[ "${UPLOAD_SAFE_LOGS}" -eq 1 ]] ; then
117+
upload_safe_logs \
118+
"${JOB_GCS_BUCKET_INTERNAL}" \
119+
"build/elastic-stack-dump/check-${PACKAGE}/logs/elastic-agent-internal/*" \
120+
"insecure-logs/${PACKAGE}/"
121+
122+
upload_safe_logs \
123+
"${JOB_GCS_BUCKET_INTERNAL}" \
124+
"build/container-logs/*.log" \
125+
"insecure-logs/${PACKAGE}/container-logs/"
126+
fi
127+
make check-git-clean
103128
exit 0
104129
fi
105130

.buildkite/scripts/release.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
set -euo pipefail
44

5+
cleanup() {
6+
rm -rf ${WORKSPACE}
7+
}
8+
trap cleanup exit
9+
10+
WORKSPACE="/tmp/bin-buildkite/"
11+
12+
VERSION=""
13+
source .buildkite/scripts/install_deps.sh
14+
source .buildkite/scripts/tooling.sh
15+
16+
add_bin_path
17+
with_go
18+
519
echo "--- fetching tags"
620
# Ensure that tags are present so goreleaser can build the changelog from the last release.
721
git rev-parse --is-shallow-repository
@@ -10,4 +24,3 @@ git fetch origin --tags
1024
echo "--- running goreleaser"
1125
# Run latest version of goreleaser
1226
curl -sL https://git.io/goreleaser | bash
13-

0 commit comments

Comments
 (0)