-
Notifications
You must be signed in to change notification settings - Fork 2
/
build
executable file
·64 lines (48 loc) · 2.22 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash -ex
set -o allexport;
[[ -f .env ]] && source .env;
[[ ! -z "$CI" ]] && sed -i '/platform: linux/d' docker-compose.yml
ROLES=(`yq e '.services[].build.target' docker-compose.yml`);
TS=${4:-`date +%y.%m`};
PUSH=${1:-nopush};
PHPVERSIONS=(${2:-8.2 8.1 8.0});
X_ARCHES=(${3:-amd64 arm64});
([[ "$PUSH" == "help" ]] || [[ "$PUSH" == "--help" ]] || [[ "$PUSH" == "-h" ]]) && cat <<TXT && exit;
NAME
build Build multiple images: ((${ROLES[*]}) x (${PHPVERSIONS[*]}) x (${X_ARCHES[*]}) @ $TS)
SYNOPSIS
build <should-push> <phpversions> <arches> <semver>
ARGUMENTS
should-push Optional. Default "nopush". If after building each image, it should be pushed to its remote.
phpversions Optional. Default "$PHPVERSIONS". Specifies a list of PHP versions to be built.
arches Optional. Default "$X_ARCHES". Specifies the list of platform architectures to build for.
semver Optional. Default "$TS" (current YY-mm). Specifies the semantic version tag of the images.
TXT
function __build() {
echo -n "$ORG/php-$PHPVS:*-$TS-$X_ARCH" >> build.log;
docker compose -f docker-compose.yml build;
echo -e " \xE2\x9C\x94" >> build.log;
}
function __alias() {
echo -n "$ALIAS" >> build.log;
docker manifest rm "$ALIAS" || true; # remove if previously exists, ignore if it didn't
docker manifest create "$ALIAS" "$ORG/php-$PHPVS:$ROLE-$TS-amd64" "$ORG/php-$PHPVS:$ROLE-$TS-arm64";
docker manifest annotate "$ALIAS" "$ORG/php-$PHPVS:$ROLE-$TS-amd64" --os linux --arch amd64;
docker manifest annotate "$ALIAS" "$ORG/php-$PHPVS:$ROLE-$TS-arm64" --os linux --arch arm64;
docker manifest push "$ALIAS";
echo -e " \xE2\x9C\x94" >> build.log;
}
echo "(${ROLES[*]}) x (${PHPVERSIONS[*]}) x (${X_ARCHES[*]}) @ $TS" > build.log;
for PHPVS in "${PHPVERSIONS[@]}"; do for X_ARCH in "${X_ARCHES[@]}"; do
__build
done done
[[ "push" != "$PUSH" ]] && exit 0;
for PHPVS in "${PHPVERSIONS[@]}"; do for ROLE in "${ROLES[@]}"; do
for X_ARCH in "${X_ARCHES[@]}"; do
docker push $ORG/php-$PHPVS:$ROLE-$TS-$X_ARCH;
done
ALIASES=$(envsubst < aliases.yml);
for ALIAS in $(yq e '(.["'$ORG/php-$PHPVS:$ROLE-$TS'"])' -o tsv <<<$ALIASES); do
__alias
done
done done