-
Notifications
You must be signed in to change notification settings - Fork 5
/
test-build.sh
executable file
·44 lines (36 loc) · 1.29 KB
/
test-build.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
#!/bin/bash
function test_docker_build () {
dockerfile=$1
folder=${dockerfile%"/Dockerfile"};
quiet=${2:-true}
# Build image, tag with a random tag
tmpName="test-image-$RANDOM"
echo "* Building image: ${dockerfile}"
if [ $quiet = true ]; then
docker build $folder --file $dockerfile --quiet --tag $tmpName > /dev/null 2>&1
else
docker build $folder --file $dockerfile --tag $tmpName
fi
if [ $? -ne 0 ]; then echo " Build status: Failed"
else
echo " Build status: Success"
docker run -t -i --rm $tmpName sh -c "if node -v &> /dev/null; then node -v ; fi; if php -v &> /dev/null; then php -r 'echo \"PHP \" . PHP_VERSION;' ; fi; echo \"\""
fi
# run bash in container
# docker run -t -i $tmpName bash
# Remove temporary build tag and image
# docker rmi $tmpName > /dev/null 2>&1
}
# Build specific dockerfile, return full output
if [[ "$1" == *"Dockerfile"* ]]; then
test_docker_build $1 false
# No dockerfile supplied, build all Dockerfiles, return output
else
path=${1:-.}
echo "Building all Dockerfiles in $path"
# List folders containing Dockerfile
file_list=$(find $path -name "Dockerfile");
for dockerfile in $file_list
do test_docker_build $dockerfile
done;
fi