Skip to content

Commit d2710b2

Browse files
committed
Fix bugs in the build script. E.g. the IMAGE variable should be local, not global
1 parent 7e75263 commit d2710b2

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

images/build.sh

+33-34
Original file line numberDiff line numberDiff line change
@@ -32,69 +32,68 @@ EOF
3232

3333
# Retrieve an image's dependencies
3434
build_dep(){
35-
IMAGE=$1
35+
local IMAGE=$1
3636

3737
# Return if empty or scratch, those images have no deps
38-
if [[ $IMAGE == "" || $IMAGE == "scratch" ]]; then
39-
exit
40-
fi
38+
if [[ $IMAGE != "" && $IMAGE != "scratch" ]]; then
4139

42-
# Read dependencies from the custom file, they always takes precedence
43-
if [[ -f ./$IMAGE/deps ]]; then
40+
# Read dependencies from the custom file, they always takes precedence
41+
if [[ -f ./$IMAGE/deps ]]; then
4442

45-
# Read every line and build it
46-
for line in "$(cat ./$IMAGE/deps)"; do
47-
build $line
48-
done
49-
fi
43+
# Read every line and build it
44+
for line in "$(cat ./$IMAGE/deps)"; do
45+
build $line
46+
done
47+
fi
5048

5149

52-
# Check if there is an Dockerfile
53-
if [[ -f ./$IMAGE/Dockerfile ]]; then
50+
# Check if there is an Dockerfile
51+
if [[ -f ./$IMAGE/Dockerfile ]]; then
5452

55-
# Build the image that this image depends on from the Dockerfile
56-
build $(cat ./$IMAGE/Dockerfile | grep "FROM " | awk '{print $2}' | grep -o "[^:]*" | grep "/")
53+
# Build the image that this image depends on from the Dockerfile
54+
build $(cat ./$IMAGE/Dockerfile | grep "FROM " | awk '{print $2}' | cut -d: -f1)
55+
fi
5756
fi
5857
}
5958

6059
# Builds an image
6160
build() {
6261

63-
# Does that image exist?
64-
if [[ -z $(docker images | grep "$1" | grep "$VERSION") ]]; then
62+
# Does that image exist?
63+
if [[ -z $(docker images | grep "$1 " | grep " $VERSION ") ]]; then
6564

66-
# First, build all this image's dependencies
65+
# First, build all this image's dependencies
6766
echo "To build: $1"
6867
build_dep "$1"
6968

7069
# Then, build this image. Only build if the image directory exists, otherwise we assume it´s from Docker Hub
7170
if [[ -d $1 ]]; then
7271

73-
echo "Building: $1"
72+
echo "Building: $1"
7473

75-
# If the directory hasn't a build.sh file, then a normal docker build is invoked
76-
if [[ ! -f ./$1/build.sh ]]; then
74+
# If the directory hasn't a build.sh file, then a normal docker build is invoked
75+
if [[ ! -f ./$1/build.sh ]]; then
7776

78-
docker build -t $1 $1
79-
else
80-
# Then build the image via the build file
81-
time ./$1/build.sh
82-
fi
77+
docker build -t $1 $1
78+
else
79+
# Then build the image via the build file
80+
time ./$1/build.sh
81+
fi
8382

84-
# Tag the image with current version
85-
docker tag "$1" "$1":$VERSION
86-
fi
83+
# Tag the image with current version
84+
docker tag "$1" "$1":$VERSION
85+
fi
8786
else
8887
echo "Already built: $1"
8988
fi
9089
}
9190

92-
# If no args is specifyed, output usage
91+
# If no args is specified, output usage
9392
if [[ $# = 0 ]]; then
9493
usage
9594
else
96-
# Otherwise, build every arg
97-
for IMG in "$@"; do
98-
build $IMG
99-
done
95+
# Otherwise, build every arg
96+
for IMG in "$@"; do
97+
build $IMG
98+
done
10099
fi

0 commit comments

Comments
 (0)