Skip to content

Commit

Permalink
[CI] Create Serverless project
Browse files Browse the repository at this point in the history
  • Loading branch information
picandocodigo committed Jan 3, 2025
1 parent 3a03f49 commit 7bf3b88
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
47 changes: 47 additions & 0 deletions .buildkite/create-serverless.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

set -euo pipefail

export EC_REGISTER_BACKEND=appex-qa-team-cluster
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"

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 \
-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"
}
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")

# Set ELASTICSEARCH_URL and API_KEY variables
export ES_API_SECRET_KEY=$(echo "$deployment" | jq -r '.credentials.api_key')
export ELASTICSEARCH_URL=$(echo "$deployment" | jq -r '.elasticsearch.url')

echo -e "--- :computer: Environment variables"
echo -e "ELASTICSEARCH_URL $ELASTICSEARCH_URL"
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ steps:
provider: "gcp"
env:
RUBY_VERSION: "{{ matrix.ruby }}"
TEST_SUITE: 'api'
TEST_SUITE: 'serverless'
RUBY_SOURCE: "{{ matrix.ruby_source }}"
QUIET: false
EC_PROJECT_PREFIX: 'sl_ruby'
Expand Down
13 changes: 13 additions & 0 deletions .buildkite/run-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ repo=`pwd`
export RUBY_VERSION=${RUBY_VERSION:-3.1}
export TRANSPORT_VERSION=${TRANSPORT_VERSION:-8}

if [[ "$TEST_SUITE" == "serverless" ]]; then
if [[ -z $EC_PROJECT_PREFIX ]]; then
echo -e "\033[31;1mERROR:\033[0m Required environment variable [EC_PROJECT_PREFIX] not set\033[0m"
exit 1
fi

# Create a serverless project:
source $script_path/create-serverless.sh

# Make sure we remove projects:
trap cleanup EXIT
fi

echo "--- :ruby: Building Docker image"
docker build \
--file $script_path/Dockerfile \
Expand Down

0 comments on commit 7bf3b88

Please sign in to comment.