1
1
#! /bin/sh
2
- # shellcheck shell=dash
3
2
4
3
#
5
4
# Builds images for each Dockerfile found recursively in the given directory.
@@ -31,19 +30,16 @@ normalize() {
31
30
32
31
# Build and tag the image based on the git branches in the current directory:
33
32
build_versions () {
34
- local image=" $1 "
33
+ image=" $1 "
35
34
shift
36
35
if [ ! -d ' .git' ]; then
37
36
# Not a git repository, so simply build a "latest" image version:
38
37
docker build -t " $image " " $@ " .
39
38
return $?
40
39
fi
41
- local current_branch
42
40
current_branch=$( git rev-parse --abbrev-ref HEAD)
43
41
# Iterate over all branches:
44
- local branches
45
42
branches=$( git for-each-ref --format=' %(refname:short)' refs/heads/)
46
- local branch
47
43
for branch in $branches ; do
48
44
git checkout " $branch "
49
45
# Tag master as "latest":
@@ -60,33 +56,29 @@ build_versions() {
60
56
61
57
# Builds an image for each git branch of the given Dockerfile directory:
62
58
build () {
63
- local cwd=" $PWD "
64
- local file
59
+ cwd=" $PWD "
65
60
file=" $( basename " $1 " ) "
66
- local dir
67
61
dir=" $( dirname " $1 " ) "
68
62
cd " $dir " || return 1
69
- local organization=" $DOCKER_ORG "
63
+ organization=" $DOCKER_ORG "
70
64
if [ -z " $organization " ]; then
71
65
# Use the parent folder for the organization/user name:
72
66
organization=" $( cd .. && normalize " $( basename " $PWD " ) " ) "
73
67
fi
74
68
if [ -n " $DOCKER_HUB " ]; then
75
69
organization=" $DOCKER_HUB /$organization "
76
70
fi
77
- local image
78
71
# Use the current folder for the image name:
79
72
image=" $organization /$( normalize " $( basename " $PWD " ) " ) "
80
73
# Check if the image depends on another image of the same organization:
81
- local from
82
74
from=$( grep " ^FROM $organization /" " $file " | awk ' {print $2}' )
83
75
# If it does, only build if the image is already available:
84
76
if [ -z " $from " ] || docker inspect " $from " > /dev/null 2>&1 ; then
85
77
build_versions " $image " -f " $file "
86
78
else
87
79
echo " $image requires $from ..." >&2 && false
88
80
fi
89
- local status=$?
81
+ status=$?
90
82
cd " $cwd " || return 1
91
83
return $status
92
84
}
@@ -105,7 +97,6 @@ build_images() {
105
97
echo ' Could not resolve image dependencies.' >&2
106
98
return 1
107
99
fi
108
- local file
109
100
for file; do
110
101
# Shift the arguments list to remove the current Dockerfile:
111
102
shift
@@ -130,8 +121,7 @@ NEWLINE='
130
121
131
122
# Parses the arguments, finds Dockerfiles and starts the builds:
132
123
init () {
133
- local args=' '
134
- local arg
124
+ args=' '
135
125
for arg; do
136
126
if [ -d " $arg " ]; then
137
127
# Search for Dockerfiles and add them to the list:
0 commit comments