Skip to content

Commit 18139fb

Browse files
committed
Merge branch 'config' into develop
Merge a functional docker image of nginx and php. This is still WIP and needs to be cleaned up. * config: Set workdir and exposing ports Change `composer selfupdate` in entrypoint Add docker-entrypoint Install and configure Honcho Install PHP composer and git Install supervisord Apply advanced PHP configuration and use PHP-FPM socket Use www-data user and supply default config for Nginx Add GPG verification for PHP archive Add readline support for PHP and remove more punctuation Add default nginx.conf and overwrite existing one
2 parents 79f17b0 + 4bc9ce2 commit 18139fb

File tree

4 files changed

+218
-7
lines changed

4 files changed

+218
-7
lines changed

Dockerfile

Lines changed: 106 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@ RUN \
1111
# In general...
1212
build-essential \
1313
curl \
14+
supervisor \
1415

1516
# For Nginx
16-
libssl-dev \
1717
libpcre3-dev \
18+
libssl-dev \
1819

1920
# For PHP
2021
bison \
2122
libbz2-dev \
2223
libcurl4-openssl-dev \
2324
libpng12-dev \
2425
libpq-dev \
26+
libreadline-dev \
2527
libxml2-dev \
2628
libxslt1-dev \
2729
pkg-config \
28-
re2c && \
30+
re2c \
31+
32+
# For PHP composer
33+
git && \
2934

3035
# Prepare for building
3136
mkdir -p /tmp/build
@@ -39,8 +44,9 @@ RUN \
3944

4045
RUN \
4146
cd /tmp/build/nginx && \
42-
# Verify signature
43-
curl -SLO https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz.asc && \
47+
48+
# GPG keys from the main maintainers of Nginx
49+
# Source https://nginx.org/en/pgp_keys.html
4450
curl -SLO https://nginx.org/keys/nginx_signing.key && \
4551
gpg --import nginx_signing.key && \
4652
curl -SLO https://nginx.org/keys/aalexeev.key && \
@@ -53,6 +59,9 @@ RUN \
5359
gpg --import maxim.key && \
5460
curl -SLO https://nginx.org/keys/sb.key && \
5561
gpg --import sb.key && \
62+
63+
# Verify signature
64+
curl -SLO https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz.asc && \
5665
gpg nginx-${NGINX_VERSION}.tar.gz.asc
5766

5867
RUN \
@@ -64,6 +73,8 @@ RUN \
6473
cd /tmp/build/nginx/nginx-${NGINX_VERSION} && \
6574
# Run configuration
6675
./configure \
76+
--group=www-data \
77+
--user=www-data \
6778
--with-file-aio \
6879
--with-http_gunzip_module \
6980
--with-http_gzip_static_module \
@@ -87,8 +98,17 @@ RUN \
8798
# Download PHP
8899
curl -SLo php-${PHP_VERSION}.tar.gz http://ch1.php.net/get/php-${PHP_VERSION}.tar.gz/from/this/mirror
89100

90-
# RUN \
91-
# TODO SIG VERIFICATION!!!
101+
RUN \
102+
cd /tmp/build/php/ && \
103+
104+
# GPG keys from the release managers of PHP 7.0
105+
# Source https://secure.php.net/gpg-keys.php#gpg-7.0
106+
gpg --keyserver pgp.mit.edu/ --recv "1A4E 8B72 77C4 2E53 DBA9 C7B9 BCAA 30EA 9C0D 5763" && \
107+
gpg --keyserver pgp.mit.edu/ --recv "6E4F 6AB3 21FD C07F 2C33 2E3A C2BF 0BC4 33CF C8B3" && \
108+
109+
# Verify signature
110+
curl -SLo php-${PHP_VERSION}.tar.gz.asc http://ch1.php.net/get/php-${PHP_VERSION}.tar.gz.asc/from/this/mirror && \
111+
gpg php-${PHP_VERSION}.tar.gz.asc
92112

93113
RUN \
94114
cd /tmp/build/php && \
@@ -102,23 +122,102 @@ RUN \
102122
--enable-fpm \
103123
--enable-mbregex \
104124
--enable-mbstring \
125+
--enable-mbstring=all \
105126
--enable-opcache \
106127
--enable-sockets \
107128
--enable-zip \
129+
--enable-zip \
108130
--with-bz2 \
109131
--with-curl \
132+
--with-fpm-group=www-data \
133+
--with-fpm-user=www-data \
110134
--with-gd \
111135
--with-gettext \
112136
--with-openssl \
113137
--with-pcre-regex \
114138
--with-pdo-mysql \
115139
--with-pdo-pgsql \
140+
--with-readline \
116141
--with-xsl \
117142
--with-zlib
118143

119144
RUN \
120145
cd /tmp/build/php/php-${PHP_VERSION} && \
121-
# Compile, test and install.
146+
# Compile, test and install
122147
make -j$(nproc) build && \
123148
make test && \
124149
make install
150+
151+
# Nginx configuration
152+
COPY nginx.conf /usr/local/nginx/conf/nginx.conf
153+
154+
RUN \
155+
# Fix permissions
156+
chown -R www-data:www-data /usr/local/nginx/html && \
157+
158+
# Symlink Nginx binary
159+
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ && \
160+
161+
# Copy PHP-FPM configuration files
162+
cp /tmp/build/php/php-${PHP_VERSION}/sapi/fpm/php-fpm.conf /usr/local/etc/php-fpm.conf && \
163+
cp /tmp/build/php/php-${PHP_VERSION}/sapi/fpm/www.conf /usr/local/etc/www.conf && \
164+
cp /tmp/build/php/php-${PHP_VERSION}/php.ini-development /usr/local/php/php.ini && \
165+
166+
# Patch PHP-FPM for proper loading www.conf
167+
sed -Ei \
168+
-e 's/^;?\s*daemonize\s*=\s*yes/daemonize = no/' \
169+
-e 's/^;?\s*include=NONE\/etc\/php-fpm.d\/\*.conf/include=\/usr\/local\/etc\/www.conf/' \
170+
/usr/local/etc/php-fpm.conf && \
171+
172+
# Patch www.conf config connection establishment
173+
sed -Ei \
174+
-e 's/^;?\s*listen\s*=.*/listen = \/var\/run\/php-fpm.sock/' \
175+
-e 's/^;?\s*?\s*listen.owner\s*=.*/listen.owner = www-data/' \
176+
-e 's/^;?\s*?\s*listen.group\s*=.*/listen.group = www-data/' \
177+
-e 's/^;?\s*?\s*listen.mode\s*=.*/listen.mode = 0660/' \
178+
/usr/local/etc/www.conf && \
179+
180+
# Patch PHP config files on the fly
181+
sed -Ei \
182+
-e 's/^;?\s*expose_php\s*=.*/expose_php = Off/' \
183+
-e 's/^;?\s*cgi.fix_pathinfo\s*=.*/cgi.fix_pathinfo=0/' \
184+
-e 's/^;?\s*error_log\s*=.*/error_log = \/usr\/local\/nginx\/logs\/error-php.log/' \
185+
-e 's/^;?\s*date.timezone\s*=.*/date.timezone = \"UTC\"/' \
186+
-e 's/^;?\s*opcache.enable\s*=.*/opcache.enable = 1/' \
187+
-e 's/^;?\s*opcache.enable_cli\s*=.*/opcache.enable_cli=1/' \
188+
-e 's/^;?\s*opcache.memory_consumption\s*=.*/opcache.memory_consumption = 256/' \
189+
-e 's/^;?\s*opcache.max_accelerated_files\s=.*/opcache.max_accelerated_files = 10000/' \
190+
/usr/local/php/php.ini
191+
192+
RUN \
193+
# Install PHP composer
194+
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
195+
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'aa96f26c2b67226a324c27919f1eb05f21c248b987e6195cad9690d5c1ff713d53020a02ac8c217dbf90a7eacc9d141d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
196+
php composer-setup.php --install-dir=/usr/local/bin --filename=composer && \
197+
php -r "unlink('composer-setup.php');"
198+
199+
# Install Honcho
200+
RUN \
201+
apt-get install -y \
202+
python-pip && \
203+
pip install honcho
204+
205+
# Configure Honcho
206+
COPY Procfile /
207+
208+
# Add entrypoint for docker
209+
COPY docker-entrypoint /
210+
RUN \
211+
chmod +x /docker-entrypoint
212+
213+
# Declare entrypoint
214+
ENTRYPOINT ["/docker-entrypoint"]
215+
216+
# Define default command
217+
CMD ["server"]
218+
219+
# Define Workdir
220+
WORKDIR "/usr/local/nginx/html"
221+
222+
# Exposing ports
223+
EXPOSE 80/tcp 443/tcp

Procfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nginx: /usr/local/sbin/nginx
2+
phpfpm: /usr/local/sbin/php-fpm

docker-entrypoint

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Fix permission ownership
4+
chown -R www-data:www-data /usr/local/nginx/html/
5+
6+
# Create PHP error log if not present
7+
# touch /usr/local/nginx/logs/error-php.log
8+
# chown www-data:www-data /usr/local/nginx/logs/error-php.log
9+
10+
# Update PHP composer
11+
# Update PHP composer to most most recent version (as of now the current version is v1.2.2).
12+
# By default, we will try to update to the most recent version of PHP composer.
13+
# However, this blocks starting the initial process IF you have a bad or no Internet connection at
14+
# all. To avoid this, you can start the container with SKIP_COMPOSER_UPDATE env set to 1.
15+
if [[ $SKIP_COMPOSER_UPDATE != "1" ]]; then
16+
composer selfupdate -vvvn
17+
fi
18+
19+
if [[ $1 == "server" ]]; then
20+
exec honcho -d / start
21+
fi
22+
23+
exec "$@"

nginx.conf

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
master_process on;
2+
daemon off;
3+
4+
user www-data www-data;
5+
worker_processes auto;
6+
7+
error_log logs/error-nginx.log;
8+
error_log logs/error-nginx.log notice;
9+
error_log logs/error-nginx.log info;
10+
11+
pid /var/run/nginx.pid;
12+
13+
events {
14+
worker_connections 1024;
15+
}
16+
17+
http {
18+
include mime.types;
19+
default_type application/octet-stream;
20+
21+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
22+
'$status $body_bytes_sent "$http_referer" '
23+
'"$http_user_agent" "$http_x_forwarded_for"';
24+
25+
sendfile on;
26+
27+
keepalive_timeout 15;
28+
29+
gzip on;
30+
gzip_comp_level 2;
31+
gzip_min_length 1000;
32+
gzip_proxied expired no-cache no-store private auth;
33+
gzip_types text/plain application/x-javascript text/xml text/css application/xml;
34+
35+
server {
36+
listen 80 default_server;
37+
server_name localhost;
38+
39+
root /usr/local/nginx/html;
40+
index index.php index.html index.htm;
41+
42+
access_log logs/http-access.log main;
43+
44+
location ~ \.php {
45+
include fastcgi_params;
46+
fastcgi_keep_conn on;
47+
fastcgi_index index.php;
48+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
49+
fastcgi_param PATH_INFO $fastcgi_path_info;
50+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
51+
fastcgi_intercept_errors on;
52+
fastcgi_pass unix:/var/run/php-fpm.sock;
53+
}
54+
55+
}
56+
57+
# server {
58+
# listen 443 ssl;
59+
# server_name localhost;
60+
61+
# ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
62+
# ssl_prefer_server_ciphers on;
63+
# ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4 !MEDIUM";
64+
65+
# ssl_certificate /etc/ssl/private/cert.pem;
66+
# ssl_certificate_key /etc/ssl/private/cert.key;
67+
68+
# ssl_session_cache shared:SSL:10m;
69+
# ssl_session_timeout 5m;
70+
71+
# root /usr/local/nginx/html;
72+
# index index.php index.html index.htm;
73+
74+
# access_log logs/https-access.log main;
75+
76+
# location ~ \.php {
77+
# include fastcgi_params;
78+
# fastcgi_keep_conn on;
79+
# fastcgi_index index.php;
80+
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
81+
# fastcgi_param PATH_INFO $fastcgi_path_info;
82+
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
83+
# fastcgi_intercept_errors on;
84+
# fastcgi_pass unix:/var/run/php-fpm.sock;
85+
# }
86+
# }
87+
}

0 commit comments

Comments
 (0)