Skip to content

Commit fb0a488

Browse files
Merge pull request nodejs#668 from LaurentGoderre/build-function
Added a build function to test-build.sh
2 parents 0189f0f + 42541fe commit fb0a488

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

test-build.sh

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@ set -uo pipefail
66

77
. functions.sh
88

9+
function build () {
10+
local version
11+
local tag
12+
local variant
13+
local full_tag
14+
local path
15+
version="$1"; shift
16+
variant="$1"; shift
17+
tag="$1"; shift
18+
19+
if [ -z "$variant" ]; then
20+
full_tag="$tag"
21+
path="$version/$variant"
22+
else
23+
full_tag="$tag-$variant"
24+
path="$version/$variant"
25+
fi
26+
27+
info "Building $full_tag..."
28+
29+
if ! docker build -t node:"$full_tag" "$path"; then
30+
fatal "Build of $full_tag failed!"
31+
fi
32+
info "Build of $full_tag succeeded."
33+
34+
info "Testing $full_tag"
35+
docker run --rm -v "$PWD/test-image.sh:/usr/local/bin/test.sh" node:"$full_tag" test.sh "$full_version"
36+
}
37+
938
cd "$(cd "${0%/*}" && pwd -P)" || exit;
1039

1140
IFS=' ' read -ra versions <<< "$(get_versions . "$@")"
@@ -20,14 +49,7 @@ for version in "${versions[@]}"; do
2049
tag=$(get_tag "$version")
2150
full_version=$(get_full_version "$version")
2251

23-
info "Building $tag..."
24-
25-
if ! docker build -t node:"$tag" "$version"; then
26-
fatal "Build of $tag failed!"
27-
fi
28-
info "Build of $tag succeeded."
29-
30-
docker run --rm -v "$PWD/test-image.sh:/usr/local/bin/test.sh" node:"$tag" test.sh "$full_version"
52+
build "$version" "" "$tag"
3153

3254
# Get supported variants according to the target architecture.
3355
# See details in function.sh
@@ -37,14 +59,7 @@ for version in "${versions[@]}"; do
3759
# Skip non-docker directories
3860
[ -f "$version/$variant/Dockerfile" ] || continue
3961

40-
info "Building $tag-$variant variant..."
41-
42-
if ! docker build -t node:"$tag-$variant" "$version/$variant"; then
43-
fatal "Build of $tag-$variant failed!"
44-
fi
45-
info "Build of $tag-$variant succeeded."
46-
47-
docker run --rm -v "$PWD/test-image.sh:/usr/local/bin/test.sh" node:"$tag-$variant" test.sh "$full_version"
62+
build "$version" "$variant" "$tag"
4863
done
4964

5065
done

0 commit comments

Comments
 (0)