Skip to content

Commit 66cea9b

Browse files
committed
Push images to separate repos
Problem: All of the images were being pushed to chekote/php. This caused issues with automated tools such as Dependabot, as they would not be able to tell what newer image it should update to. It would simply choose the latest, which could result in a project using a Behat image being updated to a Laravel image (or visa versa) Fix: Re-organize the tags so that they are within repos that contain logical groupings. For example, Images for Laravel 10 will be exclusively in the chekote/laravel10.x repo.
1 parent 6ceb4a2 commit 66cea9b

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

bin/build

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
88
. "$ROOT"/bin/lib/log.sh
99
. "$ROOT"/bin/lib/out.sh
1010

11-
REPO=chekote/php
11+
OWNER=chekote
1212

1313
PATCH_VERSION=
1414

@@ -41,12 +41,12 @@ versionBetween() {
4141
# 1 the 1st version to compare
4242
# 2 the 2nd version to compare
4343
# Globals:
44-
# REPO the name of Docker Hub repo where the images are hosted
44+
# OWNER the name of Docker Hub user where the images are hosted
4545
# Return:
4646
# 0 if the 1st version is greater than the 2nd. 1 if not.
4747
#######################################
4848
versionGreaterThan() {
49-
docker container run --rm "$REPO:7" php -r "version_compare('$1', '$2', '>') ? exit(0) : exit(1);";
49+
docker container run --rm "$OWNER/php:7" php -r "version_compare('$1', '$2', '>') ? exit(0) : exit(1);";
5050
return $?
5151
}
5252

@@ -60,7 +60,7 @@ versionGreaterThan() {
6060
# 0 if the 1st version is less than the 2nd. 1 if not.
6161
#######################################
6262
versionLessThan() {
63-
docker container run --rm "$REPO:7" php -r "version_compare('$1', '$2', '<') ? exit(0) : exit(1);";
63+
docker container run --rm "$OWNER/php:7" php -r "version_compare('$1', '$2', '<') ? exit(0) : exit(1);";
6464
return $?
6565
}
6666

@@ -85,29 +85,35 @@ assertVersionAtLeast() {
8585
# 1 the image to build. Must have a matching .docker file in the root of the project.
8686
# Globals:
8787
# IMAGE the name of the image currently being build
88-
# REPO the name of Docker Hub repo where the images are hosted
8988
# MAJOR_VERSION the major PHP version to build images for
9089
# MINOR_VERSION the minor PHP version to build images for
9190
# PATCH_VERSION the patch PHP version that was built
9291
#######################################
9392
buildImage() {
9493
IMAGE="$1"
95-
local MAJOR_TAG MINOR_TAG PATCH_TAG LATEST_TAG
94+
local MAJOR_TAG MINOR_TAG PATCH_TAG LATEST_TAG repo
95+
96+
TAG_SUFFIX=$([[ "$IMAGE" == "php" ]] && echo "" || echo "php")
9697

9798
MAJOR_TAG="$MAJOR_VERSION"
9899
MINOR_TAG="$MAJOR_VERSION.$MINOR_VERSION"
99100

100-
buildMultiArchImage "$IMAGE" "$REPO:$MAJOR_TAG"
101+
MAJOR_TAG="$TAG_SUFFIX$MAJOR_VERSION"
102+
MINOR_TAG="$MAJOR_TAG.$MINOR_VERSION"
103+
104+
repo="$OWNER/$IMAGE"
105+
106+
buildMultiArchImage "$IMAGE" "$repo:$MAJOR_TAG"
101107
if [ "$IMAGE" = "php" ]; then
102-
updatePatchVersion
108+
updatePatchVersion "$IMAGE"
103109
fi
104110

105-
PATCH_TAG="$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION"
106-
LATEST_TAG="$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION-$(date '+%Y-%m-%d-%H-%M-%S')"
111+
PATCH_TAG="$MINOR_TAG.$PATCH_VERSION"
112+
LATEST_TAG="$PATCH_TAG-$(date '+%Y-%m-%d-%H-%M-%S')"
107113

108-
buildMultiArchImage "$IMAGE" "$REPO:$MINOR_TAG"
109-
buildMultiArchImage "$IMAGE" "$REPO:$PATCH_TAG"
110-
buildMultiArchImage "$IMAGE" "$REPO:$LATEST_TAG"
114+
buildMultiArchImage "$IMAGE" "$repo:$MINOR_TAG"
115+
buildMultiArchImage "$IMAGE" "$repo:$PATCH_TAG"
116+
buildMultiArchImage "$IMAGE" "$repo:$LATEST_TAG"
111117
}
112118

113119
#######################################
@@ -152,14 +158,20 @@ tagImage() {
152158
#######################################
153159
# Extracts the patch version from PHP major version image
154160
#
161+
# Arguments
162+
# 1 the image to get the patch version from
163+
#
155164
# Globals:
156165
# PATCH_VERSION the patch PHP version. e.g. 27 for 7.2.27
157166
#######################################
158167
updatePatchVersion() {
159-
PATCH_VERSION=$(docker run --rm "$REPO:$MAJOR_VERSION" php -r '
168+
local IMAGE="$1"
169+
170+
PATCH_VERSION=$(docker run --rm "$OWNER/$IMAGE:$MAJOR_VERSION" php -r '
160171
$version = ($dashPos = strpos(PHP_VERSION, "-")) === false ? PHP_VERSION : substr(PHP_VERSION, 0, $dashPos);
161172
echo explode(".", $version)[2];
162173
')
174+
163175
log.info "PHP Patch Version: $PATCH_VERSION"
164176
}
165177

0 commit comments

Comments
 (0)