forked from 25th-floor/docker-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.sh
executable file
·148 lines (119 loc) · 4.04 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
#!/bin/bash
set -e
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
ppas=(
[54]='php5-oldstable'
[55]='php5'
[56]='php5-5.6'
[70]='php'
)
# 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=${ppas[$versionShort]}
package="php${majorVersion}-fpm"
binary="php${majorVersion}-fpm"
config="/etc/php${majorVersion}/fpm/php-fpm.conf"
extensions="php5-sqlite php5-pgsql php5-mysqlnd php5-mcrypt php5-intl php5-gd php5-curl php5-xsl"
cliBinary="php${majorVersion}"
if [[ ${version} == "5.4" ]]; then
package+=" php5-cli"
fi
if [[ ${majorVersion} == "7" ]]; then
package="php7.0-fpm"
binary="php-fpm7.0"
config='/etc/php/7.0/fpm/php-fpm.conf'
extensions="php7.0-sqlite php7.0-pgsql php7.0-mysql php7.0-mcrypt php7.0-intl php7.0-gd php7.0-curl php7.0-xml php7.0-mbstring"
cliBinary="php"
fi
cat <<- DOCKERFILE > ${file}
# Beware: This file is generated by the generate.sh script!
FROM ubuntu:14.04
MAINTAINER Martin Prebio <[email protected]>
EXPOSE 9000
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update \\
&& apt-get dist-upgrade -y \\
&& apt-get install -y software-properties-common language-pack-en-base git \\
&& LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/${ppa} \\
&& apt-get update \\
&& apt-get install -y ${package} ${extensions} \\
&& apt-get clean \\
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \\
&& ${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
# 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 "twentyfifth/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"
echo "Generating ${file}"
binary="php${majorVersion}-fpm"
if [[ ${majorVersion} == "7" ]]; then
binary="php-fpm7.0"
fi
cat <<- DOCKERFILE > ${file}
# Beware: This file is generated by the generate.sh script!
FROM twentyfifth/php-fpm:${version}
MAINTAINER Martin Prebio <[email protected]>
EXPOSE 80
RUN add-apt-repository ppa:nginx/development \\
&& 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/self/fd/2
logfile_maxbytes=0
[program:php-fpm]
command=${binary}
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/proc/self/fd/2
stdout_logfile_maxbytes=0
stderr_logfile=/proc/self/fd/2
stderr_logfile_maxbytes=0
[program:nginx]
command=nginx -g "daemon off;"
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/proc/self/fd/2
stdout_logfile_maxbytes=0
stderr_logfile=/proc/self/fd/2
stderr_logfile_maxbytes=0
SUPERVISOR
cp nginx-site.conf ${directory}
docker build -f ${file} --tag "twentyfifth/php-nginx:${version}" ${directory}/
done