Skip to content

Commit 7bf3b88

Browse files
committed
[CI] Create Serverless project
1 parent 3a03f49 commit 7bf3b88

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

.buildkite/create-serverless.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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/appex-qa/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+
trap cleanup EXIT
36+
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+
export ES_API_SECRET_KEY=$(echo "$deployment" | jq -r '.credentials.api_key')
44+
export ELASTICSEARCH_URL=$(echo "$deployment" | jq -r '.elasticsearch.url')
45+
46+
echo -e "--- :computer: Environment variables"
47+
echo -e "ELASTICSEARCH_URL $ELASTICSEARCH_URL"

.buildkite/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ steps:
4646
provider: "gcp"
4747
env:
4848
RUBY_VERSION: "{{ matrix.ruby }}"
49-
TEST_SUITE: 'api'
49+
TEST_SUITE: 'serverless'
5050
RUBY_SOURCE: "{{ matrix.ruby_source }}"
5151
QUIET: false
5252
EC_PROJECT_PREFIX: 'sl_ruby'

.buildkite/run-client.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ repo=`pwd`
99
export RUBY_VERSION=${RUBY_VERSION:-3.1}
1010
export TRANSPORT_VERSION=${TRANSPORT_VERSION:-8}
1111

12+
if [[ "$TEST_SUITE" == "serverless" ]]; then
13+
if [[ -z $EC_PROJECT_PREFIX ]]; then
14+
echo -e "\033[31;1mERROR:\033[0m Required environment variable [EC_PROJECT_PREFIX] not set\033[0m"
15+
exit 1
16+
fi
17+
18+
# Create a serverless project:
19+
source $script_path/create-serverless.sh
20+
21+
# Make sure we remove projects:
22+
trap cleanup EXIT
23+
fi
24+
1225
echo "--- :ruby: Building Docker image"
1326
docker build \
1427
--file $script_path/Dockerfile \

0 commit comments

Comments
 (0)