Skip to content

Commit 1d16f66

Browse files
committed
Get run-tests script working
Pulls secrets in from all the necessary places, uses them securely, and ensures serverless QA instance gets deleted even if the script fails.
1 parent e00eb3b commit 1d16f66

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

.buildkite/rest-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ steps:
3030
- "3.10"
3131
- "3.11"
3232
connection_class:
33-
- urrlib3
33+
- urllib3
3434
- requests
3535
command: ./.buildkite/run-tests
3636
artifact_paths: "junit/*-junit.xml"

.buildkite/run-tests

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,39 @@ export PYTHON_CONNECTION_CLASS="${PYTHON_CONNECTION_CLASS:=urllib3}"
77

88
set -euo pipefail
99

10+
# fetch cloud creds used by qaf
11+
CLOUD_ACCESS_KEY=$(vault read -field="$EC_ENV" secret/ci/elastic-elasticsearch-serverless-python/cloud-access)
12+
echo "{\"api_key\":{\"$EC_ENV\":\"$CLOUD_ACCESS_KEY\"}}" > "$(pwd)/cloud.json"
13+
14+
# ensure serverless instance is deleted even if script errors
15+
cleanup() {
16+
echo -e "--- :elasticsearch: Tear down serverless instance EC_PROJECT_NAME"
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+
-v "$(pwd)/cloud.json:/root/.elastic/cloud.json" \
24+
docker.elastic.co/employees/dolaru/qaf:latest \
25+
bash -c 'qaf elastic-cloud projects delete'
26+
}
27+
trap cleanup EXIT
28+
1029
echo -e "--- :elasticsearch: Start serverless instance"
30+
1131
deployment=$(docker run --rm \
1232
-e EC_REGISTER_BACKEND \
1333
-e EC_ENV \
1434
-e EC_REGION \
1535
-e EC_PROJECT_NAME \
36+
-e VAULT_TOKEN \
37+
-v "$(pwd)/cloud.json:/root/.elastic/cloud.json" \
1638
docker.elastic.co/employees/dolaru/qaf:latest \
1739
bash -c 'qaf elastic-cloud projects create --project-type elasticsearch && \
1840
qaf elastic-cloud projects describe --as-json --show-credentials') \
1941

20-
ES_API_KEY=$(echo "$deployment" | jq -r '.credentials.api_key')
21-
export ES_API_KEY
42+
ES_API_SECRET_KEY=$(echo "$deployment" | jq -r '.credentials.api_key')
2243
ELASTICSEARCH_URL=$(echo "$deployment" | jq -r '.elasticsearch.url')
2344
export ELASTICSEARCH_URL
2445

@@ -39,23 +60,18 @@ docker build \
3960

4061
echo -e "--- :docker: :python: Run integration tests for Python $PYTHON_VERSION"
4162

63+
GITHUB_TOKEN=$(vault read -field=token secret/ci/elastic-elasticsearch-serverless-python/github-token)
64+
export GITHUB_TOKEN
65+
4266
docker run \
4367
-e ELASTICSEARCH_URL \
44-
-e ES_API_KEY \
68+
-e "ES_API_KEY=$ES_API_SECRET_KEY" \
4569
-e PYTHON_CONNECTION_CLASS \
4670
-e STACK_VERSION \
4771
-e TEST_SUITE \
72+
-e GITHUB_TOKEN \
4873
--name elasticsearch-serverless-python-tests \
4974
--volume "$(pwd)/junit:/code/elasticsearch-serverless-python/junit" \
5075
--rm \
5176
elasticsearch-serverless-python \
5277
nox -s "test-$PYTHON_VERSION"
53-
54-
echo -e "--- :elasticsearch: Tear down serverless instance"
55-
deployment=$(docker run --rm \
56-
-e EC_REGISTER_BACKEND \
57-
-e EC_ENV \
58-
-e EC_REGION \
59-
-e EC_PROJECT_NAME \
60-
docker.elastic.co/employees/dolaru/qaf:latest \
61-
bash -c 'qaf elastic-cloud projects delete') \

0 commit comments

Comments
 (0)