-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtag-and-push-images.sh
executable file
·41 lines (35 loc) · 1.34 KB
/
tag-and-push-images.sh
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
#!/bin/bash -e
# Usage: ./tag-and-push-images.sh ${docker-compose-service-name}
# examples:
# ./tag-and-push-images.sh alpine
# ./tag-and-push-images.sh bookworm
#
function main() {
target="${1}"
DEFAULT_TAG="bookworm"
MAJOR_VERSION="1"
IMAGE="lightswitch05/php-version-audit"
# Build and tag primary tag name
echo "Building ${target}"
docker compose build --pull "${target}"
echo "Pushing ${IMAGE}:${target}"
docker push "${IMAGE}:${target}"
# Version-based tag name with OS
echo "Tagging ${IMAGE}:${target} as ${IMAGE}:${MAJOR_VERSION}-${target}"
docker tag "${IMAGE}:${target}" "${IMAGE}:${MAJOR_VERSION}-${target}"
echo "Pushing ${IMAGE}:${MAJOR_VERSION}-${target}"
docker push "${IMAGE}:${MAJOR_VERSION}-${target}"
# Latest tag name & version-only tag
if [[ "${target}" = "${DEFAULT_TAG}" ]]; then
echo "Tagging ${IMAGE}:${target}" "${IMAGE}:latest"
docker tag "${IMAGE}:${target}" "${IMAGE}:latest"
echo "Pushing ${IMAGE}:latest"
docker push "${IMAGE}:latest"
# Version-based tag name with OS
echo "Tagging ${IMAGE}:${target} as ${IMAGE}:${MAJOR_VERSION}"
docker tag "${IMAGE}:${target}" "${IMAGE}:${MAJOR_VERSION}"
echo "Pushing ${IMAGE}:${MAJOR_VERSION}"
docker push "${IMAGE}:${MAJOR_VERSION}"
fi
}
main "$@"