Skip to content

Instantly share code, notes, and snippets.

@mago0
Created August 31, 2018 18:29
Show Gist options
  • Save mago0/70157a95b6fb1ab7615f5b56f94d6566 to your computer and use it in GitHub Desktop.
Save mago0/70157a95b6fb1ab7615f5b56f94d6566 to your computer and use it in GitHub Desktop.
# Check we have the jq binary to make parsing JSON responses a bit easier
command -v jq >/dev/null 2>&1 || \
{ echo >&2 "Please install http://stedolan.github.io/jq/download/ Aborting."; exit 1; }
# Look for an existing grid
grid_uuid=$(curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/grids \
| jq 'if ._embedded.grids[] > 0 then ._embedded.grids[0].uuid else empty end')
if [[ $grid_uuid == '' ]]; then
# Start grid
echo
echo "[$(date +%FT%T)+00:00] Starting grid"
grid_uuid=$(curl -u ${FLOOD_API_TOKEN}: -X POST https://api.flood.io/grids \
-H "Accept: application/vnd.flood.v2+json" \
-F "grid[region]=us-west-2" \
-F "grid[infrastructure]=hosted" \
-F "grid[aws_platform]=ec2_default_vpc" \
-F "grid[aws_vpc_identifier]=vpc-f85a4590" \
-F "grid[aws_tags]='project=flood.io'" \
-F "grid[instance_quantity]=1" \
-F "grid[stop_after]=60" \
-F "grid[instance_type]=m5.xlarge" \
-F "grid[credential_id]=xGKl8x" | jq -r ".uuid")
# Wait for grid to finish
echo "[$(date +%FT%T)+00:00] Waiting for grid $grid_uuid"
while [ $(curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/grids/$grid_uuid | \
jq -r '.status == "started"') == "false" ]; do
echo -n "."
sleep 3
done
fi
# Start a flood
echo
echo "[$(date +%FT%T)+00:00] Starting flood"
flood_uuid=$(curl -u ${FLOOD_API_TOKEN}: -X POST https://api.flood.io/floods \
-F "flood[tool]=flood-chrome" \
-F "flood[threads]=1" \
-F "flood[duration]=120" \
-F "flood_files[]=@./live-fe/test.ts" \
-F "flood[grids][][uuid]=${grid_uuid}" \
-F "flood[name]=FE-Live-2.0" | jq -r ".uuid")
# Wait for flood to finish
echo "[$(date +%FT%T)+00:00] Waiting for flood $flood_uuid"
while [ $(curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/floods/$flood_uuid | \
jq -r '.status == "finished"') = "false" ]; do
echo -n "."
sleep 3
done
# Get the summary report
flood_report=$(curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/floods/$flood_uuid/report | \
jq -r ".summary")
echo
echo "[$(date +%FT%T)+00:00] Detailed results at https://flood.io/$flood_uuid"
echo "$flood_report"
# Optionally store the CSV results
echo
echo "[$(date +%FT%T)+00:00] Storing CSV results at resuts.csv"
curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/floods/$flood_uuid/result.csv > result.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment