Skip to content

Commit 8ddbcd1

Browse files
committed
apps: Add logic to optionally build things in subdirectories
When users want to use something like submodules, they'll wind up with repository structure looking like: repo: submodule-foo/ ui/Dockerfile docker-compose.yml This change will allow us to build a container named "submodule-foo-ui" Signed-off-by: Andy Doan <andy@foundries.io>
1 parent b1d01ac commit 8ddbcd1

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

apps/build.sh

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ fi
8787
if [ -z "$IMAGES" ] ; then
8888
# Look through the first level of subdirectories for Dockerfile
8989
IMAGES=$(find ./ -mindepth 2 -maxdepth 2 -name Dockerfile | cut -d / -f2)
90+
# Check top-level directories for .ci-search-subdirs marker;
91+
# images found under subdirectories get appended
92+
for dir in $(find ./ -mindepth 2 -maxdepth 2 -name .ci-search-subdirs | cut -d / -f2) ; do
93+
IMAGES="$IMAGES $(find ./$dir -mindepth 2 -maxdepth 2 -name Dockerfile | sed 's|^\./||; s|/Dockerfile$||')"
94+
done
9095
fi
9196

9297

@@ -107,6 +112,9 @@ for x in $IMAGES ; do
107112
echo $x | grep -q -E \\.disabled$ && continue
108113
unset TEST_JUNIT_RESULTS CHANGED SKIP_ARCHS MANIFEST_PLATFORMS EXTRA_TAGS_$ARCH TEST_CMD BUILD_CONTEXT DOCKERFILE
109114

115+
# For subdirectory images (e.g. foo/bar), replace / with - for the container name
116+
name=$(echo $x | tr '/' '-')
117+
110118
conf=$x/docker-build.conf
111119
if [ -f $conf ] ; then
112120
echo "Sourcing docker-build.conf for build rules in $x"
@@ -131,7 +139,7 @@ for x in $IMAGES ; do
131139
# allow the docker-build.conf to override our manifest platforms
132140
MANIFEST_PLATFORMS="${MANIFEST_PLATFORMS-${MANIFEST_PLATFORMS_DEFAULT}}"
133141

134-
ct_base="${hub_fio}/${FACTORY}/$x"
142+
ct_base="${hub_fio}/${FACTORY}/$name"
135143

136144
docker_cmd="$docker_build -t ${ct_base}:$TAG-$ARCH -t ${ct_base}:$LATEST-$ARCH --force-rm"
137145
if [ -z "$NOCACHE" ] ; then
@@ -182,7 +190,7 @@ for x in $IMAGES ; do
182190
run eval "$docker_cmd -f $DOCKERFILE $BUILD_CONTEXT"
183191

184192
# Publish a list of md5sum checksums for the source code of each image build
185-
find ${BUILD_CONTEXT} -type f -exec md5sum '{}' \; > /archive/${x}-md5sum.txt
193+
find ${BUILD_CONTEXT} -type f -exec md5sum '{}' \; > /archive/${name}-md5sum.txt
186194
echo "Build step $((completed+1)) of $total is complete"
187195

188196
run docker manifest create ${ct_base}:${H_BUILD}_$TAG ${ct_base}:$TAG-$ARCH
@@ -198,12 +206,12 @@ for x in $IMAGES ; do
198206
elif [ "${t}" = "arm" ]; then
199207
variant="--variant v7"
200208
fi
201-
tmp=$HOME/.docker/manifests/${hub_fio}_${FACTORY}_${x}-${H_BUILD}_${TAG}
202-
cp ${tmp}/${hub_fio}_${FACTORY}_${x}-${TAG}-${ARCH} ${tmp}/${hub_fio}_${FACTORY}_${x}-${TAG}-${t}
209+
tmp=$HOME/.docker/manifests/${hub_fio}_${FACTORY}_${name}-${H_BUILD}_${TAG}
210+
cp ${tmp}/${hub_fio}_${FACTORY}_${name}-${TAG}-${ARCH} ${tmp}/${hub_fio}_${FACTORY}_${name}-${TAG}-${t}
203211
run docker manifest annotate ${ct_base}:${H_BUILD}_${TAG} ${ct_base}:${TAG}-$t --arch $t "${variant}"
204212

205-
tmp=$HOME/.docker/manifests/${hub_fio}_${FACTORY}_${x}-${LATEST}
206-
cp ${tmp}/${hub_fio}_${FACTORY}_${x}-${TAG}-${ARCH} ${tmp}/${hub_fio}_${FACTORY}_${x}-${TAG}-${t}
213+
tmp=$HOME/.docker/manifests/${hub_fio}_${FACTORY}_${name}-${LATEST}
214+
cp ${tmp}/${hub_fio}_${FACTORY}_${name}-${TAG}-${ARCH} ${tmp}/${hub_fio}_${FACTORY}_${name}-${TAG}-${t}
207215
run docker manifest annotate ${ct_base}:${LATEST} ${ct_base}:${TAG}-$t --arch $t "${variant}"
208216
done
209217

@@ -222,26 +230,26 @@ for x in $IMAGES ; do
222230
status Running test command inside container: $TEST_CMD
223231
if [ -n "$TEST_JUNIT_RESULTS" ] ; then
224232
# The test command produce junit xml file(s)
225-
testdir="/tmp/$x-test"
233+
testdir="/tmp/$name-test"
226234
mkdir $testdir
227-
docker run -v ${testdir}:${TEST_JUNIT_RESULTS} --rm --entrypoint="" ${ct_base}:$TAG-$ARCH $TEST_CMD > /archive/$x-test.log 2>&1
235+
docker run -v ${testdir}:${TEST_JUNIT_RESULTS} --rm --entrypoint="" ${ct_base}:$TAG-$ARCH $TEST_CMD > /archive/$name-test.log 2>&1
228236
# we need to copy these to /archive in a way they won't
229237
# collide with a junit.xml from another test run:
230238
for result in $(ls $testdir) ; do
231239
# Jobserv will look at all /archive/junit.xml* files
232-
cp $testdir/$result /archive/$result.$x
240+
cp $testdir/$result /archive/$result.$name
233241
done
234242
else
235243
if [ ! -f /archive/junit.xml ] ; then
236244
echo '<testsuite name="unit-tests">' > /archive/junit.xml
237245
fi
238-
echo "<testcase name=\"test-$x\">" >> /archive/junit.xml
246+
echo "<testcase name=\"test-$name\">" >> /archive/junit.xml
239247
echo " docker run --rm --entrypoint=\"\" ${ct_base}:$TAG-$ARCH $TEST_CMD"
240-
if ! docker run --rm --entrypoint="" ${ct_base}:$TAG-$ARCH $TEST_CMD > /archive/$x-test.log 2>&1 ; then
241-
status "Testing for $x failed"
248+
if ! docker run --rm --entrypoint="" ${ct_base}:$TAG-$ARCH $TEST_CMD > /archive/$name-test.log 2>&1 ; then
249+
status "Testing for $name failed"
242250
echo "<failure>" >> /archive/junit.xml
243251
# convert < and > to &lt and &gt and decolorize the output (remove ansi escapes for color)
244-
cat /archive/$x-test.log | sed -e 's/</\&lt;/g' -e 's/>/\&gt;/g' | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGK]//g" >> /archive/junit.xml
252+
cat /archive/$name-test.log | sed -e 's/</\&lt;/g' -e 's/>/\&gt;/g' | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGK]//g" >> /archive/junit.xml
245253
echo "</failure>" >> /archive/junit.xml
246254
fi
247255
echo "</testcase>" >> /archive/junit.xml

0 commit comments

Comments
 (0)