Add terminate-runner job in benchmarks.yml (#5611)

This commit is contained in:
Silvano Cerza 2023-08-25 10:14:39 +02:00 committed by GitHub
parent 66f615a3a4
commit cb894061f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,13 +34,15 @@ jobs:
env:
repo_token: ${{ secrets.HAYSTACK_BOT_TOKEN }}
run: |
cml runner launch \
--single \
--cloud aws \
--cloud-region ${{ env.AWS_REGION }} \
--cloud-type=p3.2xlarge \
--cloud-hdd-size=64 \
--labels=cml
OUTPUT=$(cml runner launch \
--cloud aws \
--cloud-region ${{ env.AWS_REGION }} \
--cloud-type=p3.2xlarge \
--cloud-hdd-size=64 \
--labels=cml 2>&1 | tee /dev/fd/2)
# Extract 'id' from the log and set it as an environment variable
ID_VALUE=$(echo "$OUTPUT" | jq -r '.message? | fromjson? | select(.id != null) | .id // empty')
echo "cml_runner_id=$ID_VALUE" >> "$GITHUB_OUTPUT"
run-reader-benchmarks:
needs: deploy-runner
@ -226,3 +228,24 @@ jobs:
with:
name: benchmark-results-opensearch
path: test/benchmarks/out/
terminate-runner:
if: always()
needs:
- deploy-runner
- run-opensearch-benchmarks
runs-on: ubuntu-latest
steps:
- name: AWS authentication
uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_CI_ROLE_ARN }}
- name: Terminate EC2 instance
env:
CML_RUNNER_ID: ${{needs.deploy-runner.outputs.cml_runner_id}}
run: |
# Get the instance ID using its Name tag and terminate the instance
INSTANCE_ID=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${{ env.CML_RUNNER_ID }}" --query "Reservations[*].Instances[*].[InstanceId]" --output text)
aws ec2 terminate-instances --instance-ids "$INSTANCE_ID"