32
32
33
33
# Retrieve an image's dependencies
34
34
build_dep (){
35
- IMAGE=$1
35
+ local IMAGE=$1
36
36
37
37
# 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
41
39
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
44
42
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
50
48
51
49
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
54
52
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
57
56
fi
58
57
}
59
58
60
59
# Builds an image
61
60
build () {
62
61
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
65
64
66
- # First, build all this image's dependencies
65
+ # First, build all this image's dependencies
67
66
echo " To build: $1 "
68
67
build_dep " $1 "
69
68
70
69
# Then, build this image. Only build if the image directory exists, otherwise we assume it´s from Docker Hub
71
70
if [[ -d $1 ]]; then
72
71
73
- echo " Building: $1 "
72
+ echo " Building: $1 "
74
73
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
77
76
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
83
82
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
87
86
else
88
87
echo " Already built: $1 "
89
88
fi
90
89
}
91
90
92
- # If no args is specifyed , output usage
91
+ # If no args is specified , output usage
93
92
if [[ $# = 0 ]]; then
94
93
usage
95
94
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
100
99
fi
0 commit comments