Skip to content

Commit

Permalink
[CI] Install qaf and run directly
Browse files Browse the repository at this point in the history
  • Loading branch information
picandocodigo committed Jan 14, 2025
1 parent f8f8b68 commit a2f187c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 32 deletions.
31 changes: 4 additions & 27 deletions .buildkite/create-serverless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,21 @@

set -euo pipefail

export EC_REGISTER_BACKEND=buildkite
export EC_ENV=qa
export EC_REGION=aws-eu-west-1
# Using BUILDKITE_JOB_ID for the name to make it unique:
export EC_PROJECT_NAME="$EC_PROJECT_PREFIX-$BUILDKITE_JOB_ID"

# fetch cloud creds used by qaf
CLOUD_ACCESS_KEY=$(vault read -field="$EC_ENV" $CLOUD_CREDENTIALS_PATH)
echo "{\"api_key\":{\"$EC_ENV\":\"$CLOUD_ACCESS_KEY\"}}" > "$(pwd)/cloud.json"

echo -e "--- Buildkite: ${BUILDKITE}"

run_qaf() {
cmd=$1
docker run --rm \
-e EC_REGISTER_BACKEND \
-e EC_ENV \
-e EC_REGION \
-e EC_PROJECT_NAME \
-e VAULT_TOKEN \
-e "BUILDKITE=${BUILDKITE}" \
-v "$(pwd)/cloud.json:/root/.elastic/cloud.json" \
docker.elastic.co/appex-qa/qaf:latest \
bash -c "$cmd"
}

# ensure serverless instance is deleted even if script errors
cleanup() {
echo -e "--- :elasticsearch: :broom::sparkles: Tear down serverless instance $EC_PROJECT_NAME"
run_qaf 'qaf elastic-cloud projects delete'
rm -rf "$(pwd)/cloud.json"
qaf elastic-cloud projects delete
rm -rf "~/.elastic/cloud.json"
}
trap cleanup EXIT

echo -e "--- :elasticsearch: Start serverless instance $EC_PROJECT_NAME"

run_qaf "qaf elastic-cloud projects create --project-type elasticsearch"
deployment=$(run_qaf "qaf elastic-cloud projects describe $EC_PROJECT_NAME --as-json --show-credentials")
qaf elastic-cloud projects create --project-type elasticsearch
deployment=$(qaf elastic-cloud projects describe $EC_PROJECT_NAME --as-json --show-credentials)

# Set ELASTICSEARCH_URL and API_KEY variables
export ES_API_SECRET_KEY=$(echo "$deployment" | jq -r '.credentials.api_key')
Expand Down
17 changes: 12 additions & 5 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ steps:
artifact_paths: "elasticsearch-api/tmp/*"
- label: ":elasticsearch: Serverless :rspec: API Tests :ruby: {{ matrix.ruby_source }} - {{ matrix.ruby }}"
agents:
provider: "gcp"
image: docker.elastic.co/appex-qa/qaf:latest
env:
RUBY_VERSION: "{{ matrix.ruby }}"
TEST_SUITE: 'serverless'
TEST_SUITE: serverless
RUBY_SOURCE: "{{ matrix.ruby_source }}"
QUIET: false
EC_PROJECT_PREFIX: 'ruby'
CLOUD_CREDENTIALS_PATH: 'secret/ci/elastic-elasticsearch-ruby/cloud-access'
EC_PROJECT_PREFIX: ruby
EC_REGISTER_BACKEND: buildkite
EC_REGION: aws-eu-west-1
EC_ENV: qa
matrix:
setup:
ruby:
Expand All @@ -57,7 +59,12 @@ steps:
- with:
ruby_source: 'jruby'
ruby: '9.4'
command: ./.buildkite/run-serverless-tests.sh
commands:
- mkdir ~/.elastic
- touch ~/.elastic/cloud.json
- CLOUD_ACCESS_KEY=$(vault read -field=qa secret/ci/elastic-elasticsearch-ruby/cloud-access)
- echo "{\"api_key\":{\"$EC_ENV\":\"$CLOUD_ACCESS_KEY\"}}" > "~/.elastic/cloud.json"
- ./.buildkite/run-serverless-tests.sh
- wait: ~
continue_on_failure: true
- label: "Log Results"
Expand Down

0 comments on commit a2f187c

Please sign in to comment.