forked from eficode-academy/go-roman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·48 lines (41 loc) · 1.35 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# Run this after build.sh.
# Expects these environment variables:
#
# IMAGEID - The docker image id to test
# DOCKER_USERNAME - The docker username for naming repositories
#
# Can run this as to use the file generated from build.sh:
#
# env $(cat props.env | xargs) ./test.sh
#Fail on non-zero
set -e
# Host port mapping for testing-app
hostport=8001
# Check if testing-app is running, if so, kill it
cid=$(sudo docker ps --filter="name=testing-app" -q -a)
if [ ! -z "$cid" ]
then
sudo docker rm -f testing-app
fi
# Run the container, name it testing-app
echo Running the container, with --name=testing-app
testing_cid=$(sudo docker run -d --name testing-app -p $hostport:8000 $IMAGEID)
echo "testing_cid=$testing_cid" >> props.env
# Get the container IP address, and run siege engine on it for 60 seconds
cip=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${testing_cid})
sudo docker run --rm rufus/siege-engine -b -t60S http://$cip:8000/ > output 2>&1
# Check service availability
echo Checking service availability...
avail=$(cat output | grep Availability | awk '{print $2}')
echo $avail
# shell uses = to compare strings, bash ==
if [ "$avail" = "100.00" ]
then
echo "Availability high enough"
sudo docker tag $IMAGEID ${DOCKER_USERNAME}/http-app:stable
exit 0
else
echo "Availability too low"
exit 1
fi