-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·69 lines (62 loc) · 2.86 KB
/
build.sh
File metadata and controls
executable file
·69 lines (62 loc) · 2.86 KB
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
65
66
67
68
69
#!/bin/bash -e
# extract all versions of PHP from local files named Dockerfile.VERSION-*
# example: Dockerfile.7.1.30-apache-stretch -> 7.1.30 / Dockerfile.8.3.12-frankenphp.1.2.5-bookworm -> 8.3.12
versions=$(ls Dockerfile.* | awk '{gsub(/^Dockerfile\./, ""); print}')
# sort the versions in descending order
IFS=$'\n' versions=($(sort -rV <<<"${versions[*]}"))
read -p "❓ Enter the version of PHP (e.g. 7.4.0 or empty to list available versions): " VERSION
# if the version is empty, set the default version to latest
if [ -z "$VERSION" ]; then
# list all versions of PHP, and let the user choose one with a select, default is the latest version
PS3="❓ Select a version of PHP (or 'd': default ${versions[0]} / 'h': help / 'l': list / 'q': quit): "
select VERSION in "${versions[@]}"; do
if [ "$REPLY" == "q" ]; then
echo "👋 Exiting"
exit 0
elif [ "$REPLY" == "l" ]; then
echo "📜 Available versions:"
for version in "${versions[@]}"; do
echo " - $version"
done
elif [ "$REPLY" == "h" ]; then
echo "ℹ️ Help:"
echo " - q: quit"
echo " - l: list available versions"
echo " - h: help"
echo " - d: default version"
elif [ "$REPLY" == "d" ]; then
VERSION=${versions[0]}
break
elif [ -n "$REPLY" ] && [ "$REPLY" -ge 1 ] && [ "$REPLY" -le "${#versions[@]}" ]; then
# if the user input is not empty, but user input is not between 1 and the number of elements in the array, exit the script
break
# else if user just typed enter, set the version to the first element in the array
elif [ -z "$REPLY" ]; then
VERSION=${versions[0]}
break
else
echo "❌ Invalid option: $REPLY"
fi
done
else
# check if the version is in the list of available versions
if [[ ! " ${versions[@]} " =~ " ${VERSION} " ]]; then
echo "❌ Invalid version of PHP: ${VERSION}"
exit 1
fi
fi
echo "🔨 Building PHP version: ${VERSION}"
# ask for confirmation [Y/n]
read -p "❓ Do you want to continue? [Y/n]: " confirm
# if user input (case insensitive) is not 'y', empty, or 'yes' exit the script
if [[ ! $confirm =~ ^[Yy]$|^$|^yes$ ]]; then
echo "👋 Exiting"
exit 0
fi
# build the image with the specified version of PHP
docker buildx build -f Dockerfile.${VERSION} . --progress plain --platform=linux/amd64 -t sigmapix/php:${VERSION}-amd64 --push
docker buildx build -f Dockerfile.${VERSION} . --progress plain --platform=linux/arm64 -t sigmapix/php:${VERSION}-arm64 --push
docker manifest create --amend sigmapix/php:${VERSION} sigmapix/php:${VERSION}-arm64 sigmapix/php:${VERSION}-amd64
docker manifest push --purge sigmapix/php:${VERSION}
echo "🎉 Build completed successfully! 🎉"
exit 0