-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-build.sh
More file actions
executable file
·71 lines (65 loc) · 2.1 KB
/
docker-build.sh
File metadata and controls
executable file
·71 lines (65 loc) · 2.1 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
70
71
#!/bin/bash
if [ -z ${BASE_VERSION} ]; then
echo >&2 Base version not specified
exit 1
fi
declare -A TARGET_TAG_VARIANT_MAP
TARGET_TAG_VARIANT_MAP=(
['cron']='cli'
['cli']='cli'
['fpm']='fpm'
['fpm-alpine']='fpm-alpine'
)
BASE_REGISTRY_REPO='wordpress'
TARGET_REGISTRY_REPO='yehuda/wordpress'
BUILD_NGINX=yes
if [ -z ${IMAGE_TAG} ]; then
IMAGE_TAG=`date +%Y%m%d`
BUILD_NGINX=no
fi
# Build wordpress images
version=${BASE_VERSION}
for target_variant in "${!TARGET_TAG_VARIANT_MAP[@]}"; do
base_variant=${TARGET_TAG_VARIANT_MAP[$target_variant]}
base_tag="php${version}-${base_variant}"
target_tag="php${version}-${target_variant}"
if [[ "${base_variant}" == "cli" ]]; then
base_tag="${base_variant}-php${version}"
fi
echo "Creating Dockerfile for ${target_tag}"
base_dockerfile="Dockerfile-${target_variant}"
dockerfile_content=$(sed -e "s/PHP_VERSION/${version}/" "${base_dockerfile}")
docker pull "${BASE_REGISTRY_REPO}:${base_tag}"
new_image_tag="${TARGET_REGISTRY_REPO}:${target_tag}"
set -x
echo -e "FROM ${BASE_REGISTRY_REPO}:${base_tag}\n${dockerfile_content}" | docker build -t "${new_image_tag}" -f - . 2>&1 > "docker_build_${base_tag}.log"
set +x
result=$?
if [[ "x${result}" != "x0" ]]; then
echo 1>&2 "Failed building image for ${target_tag}"
echo 1>&2 "Image kept on local disk for inspection"
else
echo "Building image for ${target_tag} succeeded"
docker tag "${new_image_tag}" "${new_image_tag}-${IMAGE_TAG}"
docker push "${new_image_tag}-${IMAGE_TAG}"
docker push "${new_image_tag}"
fi
done
if [ "${BUILD_NGINX}" == "no" ]; then
exit
fi
# Build nginx image
echo "Creating Dockerfile for nginx:alpine"
docker build \
-t "yehuda/wp-nginx:${IMAGE_TAG}" \
-t "yehuda/wp-nginx:latest" \
nginx 2>&1 > "docker_build_nginx.log"
result=$?
if [[ "x${result}" != "x0" ]]; then
echo 1>&2 "Failed building image for nginx:alpine"
echo 1>&2 "Image kept on local disk for inspection"
else
echo "Building image for nginx:alpine succeeded"
docker push "yehuda/wp-nginx:${IMAGE_TAG}"
docker push 'yehuda/wp-nginx:latest'
fi