/
generate.sh
executable file
·166 lines (133 loc) · 4.85 KB
/
generate.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
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
#!/bin/bash
set -e
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
# Set default timezone
TZ='Europe/Vienna'
# Building php-fpm images
for version in "${versions[@]}"; do
versionShort=`echo $version | tr -d '.'`
majorVersion=`echo $version | sed 's/^\([[:digit:]]*\).*$/\1/'`
directory="${version}/fpm"
file="${directory}/Dockerfile"
echo "Generating ${file}"
ppa="php"
ppaPinName="LP-PPA-ondrej-php5"
package="php${version}-fpm"
binary="php-fpm${version}"
config="/etc/php/${version}/fpm/php-fpm.conf"
extensions="sqlite3 pgsql mysql mcrypt mbstring intl gd curl xml xsl xdebug zip"
extensionsDisable="xdebug"
extensionsPackages=""
cliBinary="php${version}"
phpenmod="phpenmod -v ${version} -s ALL"
phpdismod="phpdismod -v ${version} -s ALL"
if [[ ${majorVersion} == "7" ]]; then
extensions+=""
fi
for short in $extensions; do
extensionsPackages+="php${version}-${short} "
done
cat <<- DOCKERFILE > ${file}
# Beware: This file is generated by the generate.sh script!
FROM ubuntu:16.04
MAINTAINER 25th-floor GmbH <devops@25th-floor.com>
EXPOSE 9000
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=${TZ}
RUN apt-get update \\
&& apt-get -y dist-upgrade \\
&& apt-get install -y software-properties-common language-pack-en-base language-pack-de git tzdata netcat \\
&& LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/${ppa} \\
&& apt-get update \\
&& echo "Package: *\nPin: release o=${ppaPinName}\nPin-Priority: 1001" > /etc/apt/preferences.d/ondrej \\
&& apt-get install -y ${package} ${extensionsPackages} \\
&& apt-get install -y php-pear \\
&& apt-get clean \\
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \\
&& ln -snf /usr/share/zoneinfo/\$TZ /etc/localtime \\
&& echo \$TZ > /etc/timezone \\
&& dpkg-reconfigure -f noninteractive tzdata
RUN ${phpenmod} ${extensions}
# supply but disable xdebug; can be enabled by custom volume-mount ini file
RUN ${phpdismod} ${extensionsDisable}
# install composer
RUN ${cliBinary} -r 'readfile("https://getcomposer.org/installer");' > composer-setup.php \\
&& ${cliBinary} composer-setup.php --install-dir=/usr/local/bin --filename=composer \\
&& rm composer-setup.php
# install phing
RUN export PHP_PEAR_PHP_BIN=${cliBinary} \\
&& pear channel-discover pear.phing.info \\
&& pear install phing/phing
# Prepare run directory\nRUN mkdir /run/php\n\nWORKDIR /var/www\n\n" >> ${file}
COPY php-fpm.conf ${config}
CMD ["${binary}"]
DOCKERFILE
# do some code-styling for Dockerfile readability
sed -i '' -e "s|^&&|$(printf '\t')\&\&|g" ${file}
cp php-fpm.conf ${directory}
docker build -f ${file} --tag "25thfloor/php-fpm:${version}" ${directory}/
done
# Building php-nginx images
for version in "${versions[@]}"; do
majorVersion=`echo $version | sed 's/^\([[:digit:]]*\).*$/\1/'`
directory="${version}/nginx"
file="${directory}/Dockerfile"
supervisor="${directory}/supervisord.conf"
binary="php-fpm${version}"
echo "Generating ${file}"
cat <<- DOCKERFILE > ${file}
# Beware: This file is generated by the generate.sh script!
FROM 25thfloor/php-fpm:${version}
MAINTAINER 25th-floor GmbH <devops@25th-floor.com>
EXPOSE 80
ENV TZ=${TZ}
RUN ln -snf /usr/share/zoneinfo/\$TZ /etc/localtime \\
&& echo \$TZ > /etc/timezone \\
&& dpkg-reconfigure -f noninteractive tzdata \\
&& apt-key adv --fetch-keys http://nginx.org/keys/nginx_signing.key \\
&& echo "deb http://nginx.org/packages/mainline/ubuntu/ \`grep -oP 'DISTRIB_CODENAME=\\K.*' /etc/lsb-release\` nginx" >> /etc/apt/sources.list.d/nginx.list \\
&& cat /etc/apt/sources.list.d/nginx.list \\
&& apt-get update \\
&& apt-get install -y supervisor nginx \\
&& apt-get clean \\
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \\
&& ln -sf /dev/stdout /var/log/nginx/access.log \\
&& ln -sf /dev/stderr /var/log/nginx/error.log
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY nginx-site.conf /etc/nginx/sites-enabled/default
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
DOCKERFILE
# do some code-styling for Dockerfile readability
sed -i '' -e "s|^&&|$(printf '\t')\&\&|g" ${file}
cat <<- SUPERVISOR > ${supervisor}
[supervisord]
nodaemon=true
loglevel=debug
logfile=/proc/1/fd/1
logfile_maxbytes=0
[program:php-fpm]
command=${binary}
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/proc/1/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/proc/1/fd/2
stderr_logfile_maxbytes=0
[program:nginx]
command=nginx -g "daemon off;"
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/proc/1/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/proc/1/fd/2
stderr_logfile_maxbytes=0
SUPERVISOR
cp nginx-site.conf ${directory}
docker build -f ${file} --tag "25thfloor/php-nginx:${version}" ${directory}/
done