Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions .buildkite/setup-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,39 @@ if [ -z "${CLOUD_CREDENTIALS_PATH:-}" ]; then
return 0
fi

CI_CONFIG_DIR=$(mktemp -d)
chmod 0700 "$CI_CONFIG_DIR"
CI_CONFIG_FILE="$CI_CONFIG_DIR/elastic-cli-ci.json"
install -m 0600 /dev/null "$CI_CONFIG_FILE"

cleanup_cloud_config() {
rm -rf "$CI_CONFIG_DIR"
}
# trap fires when the sourcing shell exits, removing the temp config for the lifetime of the CI job
trap cleanup_cloud_config EXIT

echo "--- Reading Cloud credentials from Vault"
EC_API_KEY=$(vault read -field=api_key "$CLOUD_CREDENTIALS_PATH")

if [ -z "$EC_API_KEY" ]; then
echo "Failed to read Cloud API key from Vault"
echo "Vault returned an empty Cloud API key" >&2
return 1
fi

echo "--- Generating .elasticrc.yml for CI"
cat > "$HOME/.elasticrc.yml" <<EOF
contexts:
ci:
cloud:
url: https://admin.qa.cld.elstc.co
auth:
api_key: ${EC_API_KEY}
current_context: ci
EOF
echo "--- Generating CI config"
printf '%s' "$EC_API_KEY" | node -e '
const key = require("node:fs").readFileSync(0, "utf-8").trim()
process.stdout.write(JSON.stringify({
contexts: { ci: { cloud: {
url: "https://admin.qa.cld.elstc.co",
auth: { api_key: key },
} } },
current_context: "ci",
}) + "\n")
' > "$CI_CONFIG_FILE"

unset EC_API_KEY
export ELASTIC_CLOUD_ADMIN_API=true
export ELASTIC_CLI_CONFIG_FILE="$CI_CONFIG_FILE"

echo "Cloud config written to ~/.elasticrc.yml (admin API mode enabled)"
echo "Cloud config written to $CI_CONFIG_FILE (admin API mode enabled)"
Loading