-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild-images.sh
executable file
·104 lines (78 loc) · 3.97 KB
/
build-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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
set -e
IMAGE_NAME="${IMAGE_NAME:-hermsi/alpine-fpm-php}"
LATEST="8.0"
STABLE="7.4"
BUILD_DIR="${PWD}"
if [[ -n "${TRAVIS_BUILD_DIR}" ]] ; then
BUILD_DIR="${TRAVIS_BUILD_DIR}"
fi
DIRECTORIES=($(find "${BUILD_DIR}" -maxdepth 1 -mindepth 1 -type d -name "php*" -o -name "conf.d" | sed -e 's#.*\/\(\)#\1#' | sort))
CHANGED_DIRECTORIES=($(git -C "${TRAVIS_BUILD_DIR}" diff HEAD~ --name-only | grep -ioe "php-[0-9+].[0-9+]\|conf.d\|build-images.sh" | sort))
PHPREDIS_VERSION="$(w3m -dump "https://github.com/phpredis/phpredis/releases" | egrep "^[0-9]+.[0-9]+.[0-9]+(RC[0-9]+)?" | tr -d '\r' | awk '{print $1}' | head -n1)"
PHPREDIS_VERSION_TAG="phpredis${PHPREDIS_VERSION}"
BUILD_ALL_REGEX=".*conf.d.*\|.*build-images.sh.*"
docker_push() {
unset IMAGE
IMAGE="${1}"
echo "# Pushing tag: ${IMAGE##*:}"
docker push "${IMAGE}" 1>/dev/null
}
if [[ -n "${1}" ]]; then
TO_BUILD=("${1}")
elif [[ "${#CHANGED_DIRECTORIES[@]}" -eq 0 ]] || [[ $( echo "${CHANGED_DIRECTORIES[@]}" | grep -e "${BUILD_ALL_REGEX}" ) ]]; then
TO_BUILD=($(find "${BUILD_DIR}" -maxdepth 1 -mindepth 1 -type d -name "php*" | sed -e 's#.*\/\(\)#\1#' | sort))
else
TO_BUILD=(${CHANGED_DIRECTORIES})
fi
echo "# # # # # # # # # # # # # # # # # # # # # # # # #"
echo "# We're building the following realeases now:"
echo "# ${TO_BUILD[@]}"
for PHP_VERSION_DIR in ${TO_BUILD[@]}; do
echo "# # # # # # # # # # # # # # # # # #"
echo "# Building: ${PHP_VERSION_DIR}"
unset FULL_PHP_VERSION_PATH
FULL_PHP_VERSION_PATH="${BUILD_DIR}/${PHP_VERSION_DIR}"
unset PHP_VERSION
PHP_VERSION="${PHP_VERSION_DIR#*-}"
docker pull "php:${PHP_VERSION}-fpm-alpine"
unset PATCH_RELEASE_TAG
PATCH_RELEASE_TAG="$(docker run --rm --entrypoint /usr/bin/env -t "php:${PHP_VERSION}-fpm-alpine" /bin/sh -c 'echo $PHP_VERSION' | tr -d '\r')"
unset MINOR_RELEASE_TAG
MINOR_RELEASE_TAG="${PATCH_RELEASE_TAG%.*}"
unset MAJOR_RELEASE_TAG
MAJOR_RELEASE_TAG="${MINOR_RELEASE_TAG%.*}"
unset STABLE_RELEASE_TAG
STABLE_RELEASE_TAG="stable"
unset LATEST_RELEASE_TAG
LATEST_RELEASE_TAG="latest"
set -x
docker build \
--no-cache \
--pull \
--build-arg PHP_VERSION="${PATCH_RELEASE_TAG}" \
--build-arg PHPREDIS_VERSION="${PHPREDIS_VERSION}" \
--tag "${IMAGE_NAME}:${LATEST_RELEASE_TAG}" \
--tag "${IMAGE_NAME}:${LATEST_RELEASE_TAG}-${PHPREDIS_VERSION_TAG}" \
--tag "${IMAGE_NAME}:${STABLE_RELEASE_TAG}" \
--tag "${IMAGE_NAME}:${STABLE_RELEASE_TAG}-${PHPREDIS_VERSION_TAG}" \
--tag "${IMAGE_NAME}:${MAJOR_RELEASE_TAG}" \
--tag "${IMAGE_NAME}:${MAJOR_RELEASE_TAG}-${PHPREDIS_VERSION_TAG}" \
--tag "${IMAGE_NAME}:${MINOR_RELEASE_TAG}" \
--tag "${IMAGE_NAME}:${MINOR_RELEASE_TAG}-${PHPREDIS_VERSION_TAG}" \
--tag "${IMAGE_NAME}:${PATCH_RELEASE_TAG}" \
--tag "${IMAGE_NAME}:${PATCH_RELEASE_TAG}-${PHPREDIS_VERSION_TAG}" \
--file "${FULL_PHP_VERSION_PATH}/Dockerfile" \
"${BUILD_DIR}"
set +x
if [[ "${TRAVIS_BRANCH}" == "master" ]] && [[ "${TRAVIS_PULL_REQUEST}" == "false" ]]; then
[[ "${MINOR_RELEASE_TAG}" == "${STABLE}" ]] && docker_push "${IMAGE_NAME}:${STABLE_RELEASE_TAG}" && docker_push "${IMAGE_NAME}:${STABLE_RELEASE_TAG}-${PHPREDIS_VERSION_TAG}"
[[ "${MINOR_RELEASE_TAG}" == "${LATEST}" ]] && docker_push "${IMAGE_NAME}:${LATEST_RELEASE_TAG}" && docker_push "${IMAGE_NAME}:${LATEST_RELEASE_TAG}-${PHPREDIS_VERSION_TAG}"
[[ "${MINOR_RELEASE_TAG}" == "${STABLE}" ]] && docker_push "${IMAGE_NAME}:${MAJOR_RELEASE_TAG}" && docker_push "${IMAGE_NAME}:${MAJOR_RELEASE_TAG}-${PHPREDIS_VERSION_TAG}"
docker_push "${IMAGE_NAME}:${MINOR_RELEASE_TAG}"
docker_push "${IMAGE_NAME}:${MINOR_RELEASE_TAG}-${PHPREDIS_VERSION_TAG}"
docker_push "${IMAGE_NAME}:${PATCH_RELEASE_TAG}"
docker_push "${IMAGE_NAME}:${PATCH_RELEASE_TAG}-${PHPREDIS_VERSION_TAG}"
fi
done
echo "# # # # # # # # # # # # # # # # # # # # # # # # #"