forked from jtreminio/php-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·208 lines (172 loc) · 5.06 KB
/
build
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# 7.4.0
PHP_VERSION="${1}"
# 7.4
PHP_MAJOR=$(echo ${PHP_VERSION} | cut -d . -f -2)
if [[ -z "${PHP_VERSION// }" ]]; then
cat << EOF
Usage: build PHP_VERSION
Builds CLI, FPM, Apache and Nginx images for PHP PHP_VERSION
Example: build 7.4.0
Builds these images - jtreminio:php-cli
- jtreminio:php
- jtreminio:php-apache
- jtreminio:php-nginx
EOF
fi
if [[ ${PHP_VERSION} != "env" ]] && [[ "${PHP_VERSION// }" == "${PHP_MAJOR// }" ]]; then
printf "PHP_VERSION must be in 7.4.0 format"
exit 1
fi
REGEXP="([0-9]{1}\.)+([0-9]{1}\.)+([0-9]{1,2})"
if [[ ${PHP_VERSION} != "env" ]] && ! [[ ${PHP_VERSION} =~ ${REGEXP} ]]; then
printf "PHP_VERSION must be in 7.4.0 format"
exit 1
fi
IS_LATEST=0
if [[ ${PHP_MAJOR} == 7.4 ]]; then
IS_LATEST=1
fi
function main() {
if [[ PHP_VERSION == "env" ]]; then
build_env_image
docker image push jtreminio/phpenv:latest
exit 0
fi
build_php_cli_image ${PHP_MAJOR} ${PHP_VERSION}
build_php_fpm_image ${PHP_MAJOR} ${PHP_VERSION}
build_apache_image ${PHP_MAJOR} ${PHP_VERSION}
build_nginx_image ${PHP_MAJOR} ${PHP_VERSION}
bash "${DIR}/test" ${PHP_VERSION}
if [[ $? -ne 0 ]]; then
exit 1
fi
docker image push jtreminio/php-cli:${PHP_MAJOR}
docker image push jtreminio/php-cli:${PHP_VERSION}
docker image push jtreminio/php:${PHP_MAJOR}
docker image push jtreminio/php:${PHP_VERSION}
docker image push jtreminio/php-apache:${PHP_MAJOR}
docker image push jtreminio/php-apache:${PHP_VERSION}
docker image push jtreminio/php-nginx:${PHP_MAJOR}
docker image push jtreminio/php-nginx:${PHP_VERSION}
if [[ ${IS_LATEST} -eq 1 ]]; then
docker image push jtreminio/php-cli:latest
docker image push jtreminio/php:latest
docker image push jtreminio/php-apache:latest
docker image push jtreminio/php-nginx:latest
fi
cat << EOF
The following images were built and pushed:
jtreminio/php-cli:${PHP_MAJOR}
jtreminio/php-cli:${PHP_VERSION}
jtreminio/php:${PHP_MAJOR}
jtreminio/php:${PHP_VERSION}
jtreminio/php-apache:${PHP_MAJOR}
jtreminio/php-apache:${PHP_VERSION}
jtreminio/php-nginx:${PHP_MAJOR}
jtreminio/php-nginx:${PHP_VERSION}
EOF
if [[ ${IS_LATEST} -eq 1 ]]; then
cat << EOF
docker image push jtreminio/php-cli:latest
docker image push jtreminio/php:latest
docker image push jtreminio/php-apache:latest
docker image push jtreminio/php-nginx:latest
EOF
fi
}
function build_env_image() {
echo "Building ENV"
docker image build \
-t jtreminio/env:latest \
-f Dockerfile-env \
.
if [[ $? -ne 0 ]]; then
echo "Error encountered"
exit 1
fi
}
function build_php_cli_image() {
PHP_MAJOR="${1}"
PHP_MINOR="${2}"
LATEST_TAG=""
if [[ ${IS_LATEST} -eq 1 ]]; then
LATEST_TAG="-t jtreminio/php-cli:latest"
fi
echo "Building PHP-CLI ${PHP_MINOR}"
docker image build \
--build-arg PHP_VER=${PHP_MAJOR} \
--build-arg PHP_VER_DOT=${PHP_MINOR} \
-t jtreminio/php-cli:${PHP_MAJOR} \
-t jtreminio/php-cli:${PHP_MINOR} \
${LATEST_TAG} \
-f Dockerfile-php-cli \
.
if [[ $? -ne 0 ]]; then
echo "Error encountered"
exit 1
fi
}
function build_php_fpm_image() {
PHP_MAJOR="${1}"
PHP_MINOR="${2}"
LATEST_TAG=""
if [[ ${IS_LATEST} -eq 1 ]]; then
LATEST_TAG="-t jtreminio/php:latest"
fi
echo "Building PHP-CLI + PHP-FPM ${PHP_MINOR}"
docker image build \
--build-arg PHP_VER=${PHP_MAJOR} \
--build-arg PHP_VER_DOT=${PHP_MINOR} \
-t jtreminio/php:${PHP_MAJOR} \
-t jtreminio/php:${PHP_MINOR} \
${LATEST_TAG} \
-f Dockerfile-php-fpm \
.
if [[ $? -ne 0 ]]; then
echo "Error encountered"
exit 1
fi
}
function build_apache_image() {
PHP_MAJOR="${1}"
PHP_MINOR="${2}"
LATEST_TAG=""
if [[ ${IS_LATEST} -eq 1 ]]; then
LATEST_TAG="-t jtreminio/php-apache:latest"
fi
echo "Building PHP ${PHP_MAJOR} + Apache"
docker image build \
--build-arg PHP_VER_DOT=${PHP_MINOR} \
-t jtreminio/php-apache:${PHP_MAJOR} \
-t jtreminio/php-apache:${PHP_MINOR} \
${LATEST_TAG} \
-f Dockerfile-apache \
.
if [[ $? -ne 0 ]]; then
echo "Error encountered"
exit 1
fi
}
function build_nginx_image() {
PHP_MAJOR="${1}"
PHP_MINOR="${2}"
LATEST_TAG=""
if [[ ${IS_LATEST} -eq 1 ]]; then
LATEST_TAG="-t jtreminio/php-nginx:latest"
fi
echo "Building PHP ${PHP_MAJOR} + Nginx"
docker image build \
--build-arg PHP_VER_DOT=${PHP_MINOR} \
-t jtreminio/php-nginx:${PHP_MAJOR} \
-t jtreminio/php-nginx:${PHP_MINOR} \
${LATEST_TAG} \
-f Dockerfile-nginx \
.
if [[ $? -ne 0 ]]; then
echo "Error encountered"
exit 1
fi
}
main