-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprepare.sh
executable file
·99 lines (80 loc) · 2.56 KB
/
prepare.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
#!/usr/bin/env bash
set -eu -o pipefail
VERSION=""
while getopts ":s:" opt ; do
case ${opt} in
s)
VERSION="${OPTARG}";
;;
\?)
echo "Invalid option: -${OPTARG}"
;;
esac;
done;
shift $((OPTIND-1))
if [ -z "${VERSION}" ]; then
>&2 echo "-s is required";
exit 1
fi;
VERSIONS="5.6/fpm 7.0/fpm 7.1/fpm 7.2/fpm 7.3/fpm 7.4/fpm 8.0/fpm 8.1/fpm 8.2/fpm 8.3/fpm"
if echo "$VERSIONS" | grep -v "\( \|^\)$VERSION\( \|$\)" &> /dev/null; then
>&2 echo "version $VERSION is not supported"
exit 1
fi
for V in ${VERSIONS}; do
if [ "${V}" == "${VERSION}" ]; then
if [ -d "build/${V}" ]; then
rm -rf "build/${V}"
fi;
mkdir -p "build/${V}"
fi;
done;
if [ "${VERSION}" != "" ] && [ -d build/${VERSION} ]; then
cp -R common/. build/${VERSION}/.
cp -R ${VERSION}/. build/${VERSION}/.
cd build/${VERSION}/
cp "Dockerfile.tpl" "Dockerfile"
PHP_EXT_GROUP_ALL_PATH="args/PHP_EXT_GROUP_ALL"
PECL_EXT_GROUP_ALL_PATH="args/PECL_EXT_GROUP_ALL"
TAG_PATH="TAG"
if [ ! -f "${PHP_EXT_GROUP_ALL_PATH}" ]; then
>&2 echo "Missing required file: ${PWD}/${PHP_EXT_GROUP_ALL_PATH}";
exit 1;
fi;
if [ ! -f "${PECL_EXT_GROUP_ALL_PATH}" ]; then
>&2 echo "Missing required file: ${PWD}/${PECL_EXT_GROUP_ALL_PATH}";
exit 1;
fi;
TAG=$(cat "${TAG_PATH}")
dockerfile_content="$(cat Dockerfile)"
dockerfile_content="$(
echo "$dockerfile_content" \
| awk -v "tag=$TAG" '{ gsub("{{TAG}}", tag, $0); print $0 }'
)"
declare -A BUILD_ARGS;
BUILD_ARGS=(
[PHP_EXT_GROUP_ALL]="args/PHP_EXT_GROUP_ALL"
[PECL_EXT_GROUP_ALL]="args/PECL_EXT_GROUP_ALL"
);
BUILD_ARGS_STR="";
for ARG_NAME in ${!BUILD_ARGS[@]}; do
ARG_VAL="\\\\\\n";
for i in $(cat "${BUILD_ARGS[${ARG_NAME}]}"); do
ARG_VAL="${ARG_VAL}${i} \\\\\\n";
done;
BUILD_ARGS_STR="${BUILD_ARGS_STR}\nARG ${ARG_NAME}=\"${ARG_VAL}\""
done;
dockerfile_content="$(
echo "$dockerfile_content" \
| awk -v "args=$BUILD_ARGS_STR" '{ gsub("{{ARGS}}", args, $0); print $0 }'
)"
FIX_APT_STR=""
if [[ "$TAG" == "5.6-fpm" || "$TAG" == "7.0-fpm" ]]; then
FIX_APT_STR='RUN echo "deb http://archive.debian.org/debian stretch main" > /etc/apt/sources.list'
fi
dockerfile_content="$(
echo "$dockerfile_content" \
| awk -v "fix_apt=$FIX_APT_STR" '{ gsub("{{FIX_APT}}", fix_apt, $0); print $0 }'
)"
echo "$dockerfile_content" > Dockerfile
fi;