Skip to content

Commit e71b2ff

Browse files
authored
Integration test runner (#17)
* Serverless integration test runner * Allow integration test pipeline to comment on PRs
1 parent 49be67c commit e71b2ff

24 files changed

+2150
-365
lines changed

.buildkite/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ARG NODE_VERSION=${NODE_VERSION:-18}
22
FROM node:$NODE_VERSION
33

4-
# Install required tools
4+
# Install zip util
55
RUN apt-get clean -y && \
66
apt-get -qy update && \
77
apt-get -y install zip && \
@@ -10,5 +10,7 @@ RUN apt-get clean -y && \
1010

1111
WORKDIR /usr/src/app
1212

13-
COPY . .
13+
COPY package*.json .
1414
RUN npm install --production=false
15+
16+
COPY . .

.buildkite/create-serverless.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
export EC_REGISTER_BACKEND=appex-qa-team-cluster
6+
export EC_ENV=qa
7+
export EC_REGION=aws-eu-west-1
8+
# Using BUILDKITE_JOB_ID for the name to make it unique:
9+
export EC_PROJECT_NAME="$EC_PROJECT_PREFIX-$BUILDKITE_JOB_ID"
10+
11+
# fetch cloud creds used by qaf
12+
CLOUD_ACCESS_KEY=$(vault read -field="$EC_ENV" "$CLOUD_CREDENTIALS_PATH")
13+
echo "{\"api_key\":{\"$EC_ENV\":\"$CLOUD_ACCESS_KEY\"}}" > "$(pwd)/cloud.json"
14+
15+
run_qaf() {
16+
cmd=$1
17+
docker run --rm \
18+
-e EC_REGISTER_BACKEND \
19+
-e EC_ENV \
20+
-e EC_REGION \
21+
-e EC_PROJECT_NAME \
22+
-e VAULT_TOKEN \
23+
-e BUILDKITE \
24+
-v "$(pwd)/cloud.json:/root/.elastic/cloud.json" \
25+
docker.elastic.co/employees/dolaru/qaf:latest \
26+
bash -c "$cmd"
27+
}
28+
29+
# ensure serverless instance is deleted even if script errors
30+
cleanup() {
31+
echo -e "--- :elasticsearch: :broom: :sparkles: Tear down serverless instance $EC_PROJECT_NAME"
32+
run_qaf 'qaf elastic-cloud projects delete'
33+
rm -rf "$(pwd)/cloud.json"
34+
}
35+
36+
start_serverless() {
37+
echo -e "--- :elasticsearch: Start serverless instance $EC_PROJECT_NAME"
38+
39+
run_qaf "qaf elastic-cloud projects create --project-type elasticsearch"
40+
deployment=$(run_qaf "qaf elastic-cloud projects describe $EC_PROJECT_NAME --as-json --show-credentials")
41+
42+
# Set ELASTICSEARCH_URL and API_KEY variables
43+
ES_API_SECRET_KEY=$(echo "$deployment" | jq -r '.credentials.api_key')
44+
export ES_API_SECRET_KEY
45+
ELASTICSEARCH_URL=$(echo "$deployment" | jq -r '.elasticsearch.url')
46+
export ELASTICSEARCH_URL
47+
48+
echo -e "--- :computer: Environment variables"
49+
echo -e "ELASTICSEARCH_URL $ELASTICSEARCH_URL"
50+
}

.buildkite/functions/cleanup.sh

Lines changed: 0 additions & 67 deletions
This file was deleted.

.buildkite/functions/imports.sh

Lines changed: 0 additions & 60 deletions
This file was deleted.

.buildkite/functions/wait-for-container.sh

Lines changed: 0 additions & 36 deletions
This file was deleted.

.buildkite/pipeline.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
---
12
steps:
2-
- label: ":elasticsearch: :javascript: Elasticsearch Serverless Node.js"
3-
command: "echo 'Hello, world!'"
3+
- key: integration
4+
label: ":elasticsearch: :javascript: Elasticsearch Serverless Node.js integration tests"
5+
agents:
6+
provider: "gcp"
7+
matrix:
8+
setup:
9+
nodejs:
10+
- "16"
11+
- "18"
12+
- "20"
13+
env:
14+
NODE_VERSION: "{{ matrix.nodejs }}"
15+
EC_PROJECT_PREFIX: "elasticsearch-serverless-js-node{{ matrix.nodejs }}"
16+
CLOUD_CREDENTIALS_PATH: "secret/ci/elastic-elasticsearch-serverless-js/cloud-access"
17+
GITHUB_TOKEN_PATH: "secret/ci/elastic-elasticsearch-serverless-js/github-token"
18+
command: "./.buildkite/run-tests.sh"
19+
artifact_paths: "./junit-output/junit-*.xml"
20+
- wait: ~
21+
continue_on_failure: true
22+
- key: junit
23+
label: ":junit: Test results"
24+
agents:
25+
provider: "gcp"
26+
image: family/core-ubuntu-2204
27+
plugins:
28+
- junit-annotate#v2.4.1:
29+
artifacts: "junit-output/junit-*.xml"
30+
job-uuid-file-pattern: "junit-(.*).xml"
31+
fail-build-on-error: true
32+
failure-format: file

.buildkite/run-client.sh

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,34 @@ script_path=$(dirname "$(realpath -s "$0")")
66
set -euo pipefail
77
repo=$(pwd)
88

9-
export NODE_VERSION=${NODE_VERSION:-18}
9+
export NODE_VERSION=${NODE_VERSION:-16}
1010

11-
echo "--- :javascript: Building Docker image"
11+
echo "--- :docker: Building Docker image"
1212
docker build \
1313
--file "$script_path/Dockerfile" \
14-
--tag elastic/elasticsearch-js \
14+
--tag elastic/elasticsearch-serverless-js \
1515
--build-arg NODE_VERSION="$NODE_VERSION" \
1616
.
1717

18-
echo "--- :javascript: Running $TEST_SUITE tests"
18+
echo "--- :javascript: Running tests"
19+
20+
GITHUB_TOKEN=$(vault read -field=token "$GITHUB_TOKEN_PATH")
21+
export GITHUB_TOKEN
22+
1923
mkdir -p "$repo/junit-output"
2024
docker run \
21-
--network="${network_name}" \
22-
--env "TEST_ES_SERVER=${elasticsearch_url}" \
23-
--env "ELASTIC_PASSWORD=${elastic_password}" \
24-
--env "TEST_SUITE=${TEST_SUITE}" \
25-
--env "ELASTIC_USER=elastic" \
26-
--env "BUILDKITE=true" \
27-
--volume "$repo/junit-output:/junit-output" \
28-
--name elasticsearch-js \
25+
-e "ELASTICSEARCH_URL" \
26+
-e "ES_API_SECRET_KEY" \
27+
-e "GITHUB_TOKEN" \
28+
-e "BUILDKITE" \
29+
--volume "$repo/junit-output:/usr/src/app/junit-output" \
30+
--name elasticsearch-serverless-js \
2931
--rm \
30-
elastic/elasticsearch-js \
31-
bash -c "npm run test:integration; [ -f ./$TEST_SUITE-report-junit.xml ] && mv ./$TEST_SUITE-report-junit.xml /junit-output/junit-$BUILDKITE_JOB_ID.xml || echo 'No JUnit artifact found'"
32+
elastic/elasticsearch-serverless-js \
33+
bash -c "npm run test:integration"
34+
35+
if [ -f "$repo/junit-output/serverless-report-junit.xml" ]; then
36+
mv "$repo/junit-output/serverless-report-junit.xml" "$repo/junit-output/junit-$BUILDKITE_JOB_ID.xml"
37+
else
38+
echo 'No JUnit artifact found'
39+
fi

0 commit comments

Comments
 (0)