Skip to content

Commit e87ce2e

Browse files
committed
Try some build tweaks
1 parent d554db7 commit e87ce2e

2 files changed

Lines changed: 28 additions & 38 deletions

File tree

hooks/build

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,38 @@
33

44
# grab latest tags
55
PHP_TAGS=$(curl 'https://registry.hub.docker.com/v2/repositories/library/php/tags?page_size=1024' | grep -Po "[0-9]+\.[0-9]+\.[0-9]+-apache" | sed 's/-apache//' | sort | uniq)
6+
IS_MASTER_BUILD=$([ "$SOURCE_BRANCH" == "master" ] && echo 1 || echo 0)
67

7-
if [ $DOCKER_TAG == "latest" ]; then
8+
echo "##### Build default image - ${IMAGE_NAME} #####"
9+
docker build --build-arg PHP_VERSION_TAG=${PHP_VERSION_TAG} -f $DOCKERFILE_PATH -t ${IMAGE_NAME} .
810

9-
docker build --build-arg PHP_VERSION_TAG=${PHP_VERSION_TAG} -f $DOCKERFILE_PATH -t ${IMAGE_NAME} .
10-
11-
for PHP_MAJOR in $(echo "$PHP_TAGS" | grep -Po "^[0-9]+" | sort | uniq); do
12-
echo "##### Build ${PHP_MAJOR}-latest (x-latest) #####"
13-
docker build --build-arg PHP_VERSION_TAG=${PHP_MAJOR}-apache -f ${DOCKERFILE_PATH} -t ${DOCKER_REPO}:${PHP_MAJOR}-latest .
14-
done
11+
if [ $IS_MASTER_BUILD -eq 1 ]; then
1512

1613
for PHP_MINOR in $(echo "$PHP_TAGS" | grep -Po "^[0-9]+\.[0-9]+" | sort | uniq); do
17-
echo "##### Build ${PHP_MINOR}-latest (x.y-latest) #####"
18-
docker build --build-arg PHP_VERSION_TAG=${PHP_MINOR}-apache -f ${DOCKERFILE_PATH} -t ${DOCKER_REPO}:${PHP_MINOR}-latest .
14+
echo "##### Build ${PHP_MINOR} #####"
15+
docker build --build-arg PHP_VERSION_TAG=${PHP_MINOR}-apache -f ${DOCKERFILE_PATH} -t ${DOCKER_REPO}:${PHP_MINOR} .
1916
done
2017

2118
for PHP_VERSION in $(echo "$PHP_TAGS"); do
2219
echo "##### Build $PHP_VERSION (x.y.z) #####"
23-
docker build --build-arg PHP_VERSION_TAG=${PHP_VERSION}-apache -f ${DOCKERFILE_PATH} -t ${DOCKER_REPO}:${PHP_VERSION}-latest .
20+
docker build --build-arg PHP_VERSION_TAG=${PHP_VERSION}-apache -f ${DOCKERFILE_PATH} -t ${DOCKER_REPO}:${PHP_VERSION} .
2421
done
2522

2623
else
2724

28-
# I think we kind of have to build that default ~UI~ box. Naming it x-*
29-
docker build --build-arg PHP_VERSION_TAG=${PHP_VERSION_TAG} -f ${DOCKERFILE_PATH} -t ${DOCKER_REPO}:${DOCKER_TAG} .
30-
31-
for PHP_MAJOR in $(echo "$PHP_TAGS" | grep -Po "^[0-9]+" | sort | uniq); do
32-
echo "##### Build ${PHP_MAJOR}-${DOCKER_TAG} (phpVersion-basePhpApacheVersion) #####"
33-
docker build --build-arg PHP_VERSION_TAG=${PHP_MAJOR}-apache -f ${DOCKERFILE_PATH} -t ${DOCKER_REPO}:${PHP_MAJOR}-${DOCKER_TAG} .
34-
done
25+
CURRENT_RELEASE=$(echo $SOURCE_BRANCH | cut -c2-)
3526

3627
for PHP_MINOR in $(echo "$PHP_TAGS" | grep -Po "^[0-9]+\.[0-9]+" | sort | uniq); do
37-
echo "##### Build ${PHP_MINOR}-latest (x.y-latest) #####"
38-
docker build --build-arg PHP_VERSION_TAG=${PHP_MINOR}-apache -f ${DOCKERFILE_PATH} -t ${DOCKER_REPO}:${PHP_MINOR}-${DOCKER_TAG} .
28+
SHORT_DOCKER_TAG=$(echo $CURRENT_RELEASE | cut -d'.' -f-2)
29+
CUSTOM_IMAGE_NAME="${DOCKER_REPO}:php${PHP_MINOR}-v${SHORT_DOCKER_TAG}"
30+
echo "##### Build $CUSTOM_IMAGE_NAME #####"
31+
docker build --build-arg PHP_VERSION_TAG=${PHP_MINOR}-apache -f ${DOCKERFILE_PATH} -t ${CUSTOM_IMAGE_NAME} .
3932
done
4033

4134
for PHP_VERSION in $(echo "$PHP_TAGS"); do
42-
echo "##### Build $PHP_VERSION (x.y.z) #####"
43-
docker build --build-arg PHP_VERSION_TAG=${PHP_VERSION}-apache -f ${DOCKERFILE_PATH} -t ${DOCKER_REPO}:${PHP_VERSION}-${DOCKER_TAG} .
35+
CUSTOM_IMAGE_NAME="${DOCKER_REPO}:php${PHP_VERSION}-v${CURRENT_RELEASE}"
36+
echo "##### Build $CUSTOM_IMAGE_NAME #####"
37+
docker build --build-arg PHP_VERSION_TAG=${PHP_VERSION}-apache -f ${DOCKERFILE_PATH} -t ${CUSTOM_IMAGE_NAME} .
4438
done
4539

4640
fi

hooks/post_push

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,35 @@
33

44
# grab latest tags
55
PHP_TAGS=$(curl 'https://registry.hub.docker.com/v2/repositories/library/php/tags?page_size=1024' | grep -Po "[0-9]+\.[0-9]+\.[0-9]+-apache" | sed 's/-apache//' | sort | uniq)
6+
IS_MASTER_BUILD=$([ "$SOURCE_BRANCH" == "master" ] && echo 1 || echo 0)
67

7-
if [ $DOCKER_TAG == "latest" ]; then
8-
9-
for PHP_MAJOR in $(echo "$PHP_TAGS" | grep -Po "^[0-9]+" | sort | uniq); do
10-
echo "##### Push ${PHP_MAJOR}-latest (x-latest) #####"
11-
docker push ${DOCKER_REPO}:${PHP_MAJOR}-latest
12-
done
8+
if [ $IS_MASTER_BUILD -eq 1 ]; then
139

1410
for PHP_MINOR in $(echo "$PHP_TAGS" | grep -Po "^[0-9]+\.[0-9]+" | sort | uniq); do
15-
echo "##### Push ${PHP_MINOR}-latest (x.y-latest) #####"
16-
docker push ${DOCKER_REPO}:${PHP_MINOR}-latest
11+
echo "##### Push ${PHP_MINOR} #####"
12+
docker push ${DOCKER_REPO}:${PHP_MINOR}
1713
done
1814

1915
for PHP_VERSION in $(echo "$PHP_TAGS"); do
2016
echo "##### Push $PHP_VERSION (x.y.z) #####"
21-
docker push ${DOCKER_REPO}:${PHP_VERSION}-latest
17+
docker push ${DOCKER_REPO}:${PHP_VERSION}
2218
done
2319

2420
else
2521

26-
for PHP_MAJOR in $(echo "$PHP_TAGS" | grep -Po "^[0-9]+" | sort | uniq); do
27-
echo "##### Push ${PHP_MAJOR}-${DOCKER_TAG} (phpVersion-basePhpApacheVersion) #####"
28-
docker push ${DOCKER_REPO}:${PHP_MAJOR}-${DOCKER_TAG}
29-
done
22+
CURRENT_RELEASE=$(echo $SOURCE_BRANCH | cut -c2-)
3023

3124
for PHP_MINOR in $(echo "$PHP_TAGS" | grep -Po "^[0-9]+\.[0-9]+" | sort | uniq); do
32-
echo "##### Push ${PHP_MINOR}-latest (x.y-latest) #####"
33-
docker push ${DOCKER_REPO}:${PHP_MINOR}-${DOCKER_TAG}
25+
SHORT_DOCKER_TAG=$(echo $CURRENT_RELEASE | cut -d'.' -f-2)
26+
CUSTOM_IMAGE_NAME="${DOCKER_REPO}:php${PHP_MINOR}-v${SHORT_DOCKER_TAG}"
27+
echo "##### Push $CUSTOM_IMAGE_NAME #####"
28+
docker push -t ${CUSTOM_IMAGE_NAME}
3429
done
3530

3631
for PHP_VERSION in $(echo "$PHP_TAGS"); do
37-
echo "##### Push $PHP_VERSION (x.y.z) #####"
38-
docker push ${DOCKER_REPO}:${PHP_VERSION}-${DOCKER_TAG}
32+
CUSTOM_IMAGE_NAME="${DOCKER_REPO}:php${PHP_VERSION}-v${CURRENT_RELEASE}"
33+
echo "##### Push $CUSTOM_IMAGE_NAME #####"
34+
docker push -t ${CUSTOM_IMAGE_NAME}
3935
done
4036

4137
fi

0 commit comments

Comments
 (0)