|
| 1 | +name: Benchmark machine |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + docker_tag: |
| 7 | + description: The tag of docker image to pull |
| 8 | + default: 'latest' |
| 9 | + required: true |
| 10 | + |
| 11 | +env: |
| 12 | + INSTANCE_ID: ${{ secrets.BENCHMARK_INSTANCE_ID }} # remote AWS host to run benchmarking |
| 13 | + BENCHMARK_SSH_USER: ${{ secrets.BENCHMARK_SSH_USER }} |
| 14 | + BENCHMARK_SSH_KEYPATH: ${{ secrets.BENCHMARK_SSH_KEYPATH }} |
| 15 | + |
| 16 | +jobs: |
| 17 | + ## run the benchmarking remotely |
| 18 | + benchmark-machine: |
| 19 | + runs-on: self-hosted |
| 20 | + steps: |
| 21 | + - name: Checkout codes on ${{ github.ref }} |
| 22 | + uses: actions/checkout@v3 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + # TODO: maybe use GHA to start/stop remote instance |
| 27 | + - name: Start remote instance |
| 28 | + timeout-minutes: 10 |
| 29 | + id: start_instance |
| 30 | + run: | |
| 31 | + aws ec2 start-instances --instance-ids ${{ env.INSTANCE_ID }} |
| 32 | + sleep 5 |
| 33 | + instance_status="aws ec2 describe-instance-status --instance-ids ${{ env.INSTANCE_ID }} --query 'InstanceStatuses[0].InstanceStatus.Status' --output text" |
| 34 | + system_status="aws ec2 describe-instance-status --instance-ids ${{ env.INSTANCE_ID }} --query 'InstanceStatuses[0].SystemStatus.Status' --output text" |
| 35 | + SECONDS=0 |
| 36 | + while : ; do |
| 37 | + if [ "$(eval $instance_status)" = "ok" ] && [ "$(eval $system_status)" = "ok" ]; then |
| 38 | + break |
| 39 | + else |
| 40 | + sleep 20 |
| 41 | + fi |
| 42 | + done |
| 43 | + echo "Remote instance reachable now after $SECONDS seconds" |
| 44 | + remote_ip=`aws ec2 describe-instances --filters 'Name=instance-state-name,Values=running' 'Name=instance-id,Values=${{ env.INSTANCE_ID }}' --query 'Reservations[*].Instances[*].[PublicIpAddress]' --output text` |
| 45 | + echo "Running instances ip address: $remote_ip" |
| 46 | + echo "::set-output name=remote_ip::$remote_ip" |
| 47 | +
|
| 48 | + # exit status should propagate through ssh |
| 49 | + - name: Remotely benchmark machine |
| 50 | + timeout-minutes: 10 |
| 51 | + run: | |
| 52 | + echo "Running instances ip address: ${{ steps.start_instance.outputs.remote_ip }}" |
| 53 | + ssh -x -o StrictHostKeychecking=no "${{ steps.start_instance.outputs.remote_ip }}" -l ${{ env.BENCHMARK_SSH_USER }} -i ${{ env.BENCHMARK_SSH_KEYPATH }} \ |
| 54 | + docker pull litentry/litentry-parachain:${{ github.event.inputs.docker_tag }} && \ |
| 55 | + docker run --rm litentry/litentry-parachain:${{ github.event.inputs.docker_tag }} benchmark machine --chain=litmus-dev |
| 56 | +
|
| 57 | + - name: Stop remote instance |
| 58 | + if: always() |
| 59 | + run: | |
| 60 | + aws ec2 stop-instances --instance-ids ${{ env.INSTANCE_ID }} |
| 61 | + sleep 5 |
| 62 | + ret=`aws ec2 describe-instance-status --instance-ids ${{ env.INSTANCE_ID }} | jq '.InstanceStatuses[0].InstanceState.Name'` |
| 63 | + echo "Remote instance running state: $ret" |
0 commit comments