forked from allysonsilva/laravel-docker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
398 lines (347 loc) · 12.9 KB
/
Dockerfile
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
FROM php:7.4-fpm
# Add label for documentation
LABEL maintainer="Allyson Silva <[email protected]>" \
description="Base image for PHP applications" \
version="base"
####
## DEFAULT CONFIGURATIONS
####
# If an ARG instruction has a default value and if there is no value passed at build-time, the builder uses the default
ARG DEFAULT_USER=app
# Unlike an ARG instruction, ENV values are always persisted in the built image
ENV DEFAULT_USER ${DEFAULT_USER}
ARG DEFAULT_USER_UID=1000
ENV DEFAULT_USER_UID ${DEFAULT_USER_UID}
ARG DEFAULT_USER_GID=1000
ENV DEFAULT_USER_GID ${DEFAULT_USER_GID}
# Default directory for application deployment
# Location of the folder in the container, path of the folder inside the container
ARG REMOTE_SRC=/var/www/app/
ENV REMOTE_SRC $REMOTE_SRC
# = /usr/local/etc/php || (./configure --with-config-file-path="$PHP_INI_DIR")
ENV PHP_INI_DIR ${PHP_INI_DIR:-/usr/local/etc/php}
# = /usr/local/etc/php/conf.d || (./configure --with-config-file-scan-dir="$PHP_INI_DIR/conf.d")
ENV PHP_INI_SCAN_DIR ${PHP_INI_DIR}/conf.d
# = /usr/local/etc/php-fpm.d || Pool Definitions (docker.conf | www.conf | zz-docker.conf)
ENV PHP_FPM_POOL_DIR ${PHP_INI_DIR}-fpm.d
# Path logs PHP/PHP-FPM
ENV PHP_LOG_PREFIX=/usr/local/var/log/php
####
## PHP
####
## AMQP EXT
# https://github.com/pdezwart/php-amqp
ARG INSTALL_PHP_AMQP=false
ENV PHP_AMQP_VERSION 1.9.4
## SWOOLE
# Event-driven asynchronous and concurrent networking engine with high performance for PHP.
# https://github.com/swoole/swoole-src
ARG INSTALL_PHP_SWOOLE=false
ENV PHP_SWOOLE_VERSION 4.4.16
# Install the PHP EXTENSIONS
RUN set -eux; \
\
echo "---> Preparing and Installing PHP"; \
\
# Print the list of manually installed packages
savedAptMark="$(apt-mark showmanual)"; \
\
apt-get update; \
# Dependencies required for PHP EXTENSIONS
apt-get install --no-install-recommends -y \
# for GD extension
libjpeg-dev \
libpng-dev \
libwebp-dev \
# for intl extension
icu-devtools \
libicu-dev \
# for soap extension
libxml2-dev \
# for amqp extension
librabbitmq-dev \
# for gmp extension
libgmp-dev \
# for swoole extension
libssl-dev \
libnghttp2-dev \
libhiredis-dev \
# for zip extension
libzip-dev \
zlib1g-dev \
; \
\
docker-php-ext-configure gd \
--enable-gd \
--with-jpeg \
--with-webp \
; \
\
docker-php-ext-configure mysqli --with-mysqli=mysqlnd; \
docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd; \
docker-php-ext-install -j $(nproc) \
gd \
bcmath \
gmp \
intl \
pcntl \
mysqli \
pdo_mysql \
soap \
sockets \
opcache \
zip \
; \
\
# Communicate with any AMQP compliant server
if [ $INSTALL_PHP_AMQP = true ]; then \
pecl install amqp-${PHP_AMQP_VERSION}; \
docker-php-ext-enable amqp; \
fi; \
\
if [ $INSTALL_PHP_SWOOLE = true ]; then \
# enable sockets supports? [no] : yes
# enable openssl support? [no] : yes
# enable http2 support? [no] : yes
# enable mysqlnd support? [no] : yes
# enable postgresql coroutine client support? [no] : no
printf "yes \n yes \n yes \n yes \n no \n" | pecl install swoole-${PHP_SWOOLE_VERSION}; \
docker-php-ext-enable swoole; \
fi; \
\
echo "---> Cleaning up"; \
\
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark; \
ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
| awk '/=>/ { print $3 }' \
| sort -u \
| xargs -r dpkg-query -S \
| cut -d: -f1 \
| sort -u \
| xargs -rt apt-mark manual; \
\
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
rm -rf /var/lib/apt/lists/*; \
rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin; \
\
php --version; \
\
# https://github.com/docker-library/php/issues/443
pecl update-channels; \
rm -rf /tmp/pear ~/.pearrc
####
## SUPPORT PACKAGES
####
RUN set -ex \
&& apt-get update \
&& apt-get install --no-install-recommends -y \
sudo \
git \
apt-transport-https \
gnupg \
openssh-client \
autoconf \
pkg-config \
libssl-dev \
wget \
unzip \
&& apt-get purge -y --auto-remove && rm -rf /var/lib/apt/lists/* \
&& rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin
####
## NEW USER
####
RUN set -ex \
&& echo "---> Adding user to IMAGE" \
&& addgroup --system --gid ${DEFAULT_USER_GID} ${DEFAULT_USER} \
&& adduser --system --disabled-password -uid ${DEFAULT_USER_UID} -gid ${DEFAULT_USER_GID} --force-badname ${DEFAULT_USER} \
&& echo "${DEFAULT_USER} ALL = (ALL) NOPASSWD: ALL" >> /etc/sudoers
########
## MONGODB
# https://docs.mongodb.com/php-library/current
# https://github.com/mongodb/mongo-php-library && composer require mongodb/mongodb
########
ARG INSTALL_PHP_MONGO=false
ENV PHP_MONGO_VERSION 1.7.3
RUN if [ $INSTALL_PHP_MONGO = true ]; then \
pecl install mongodb-${PHP_MONGO_VERSION} \
&& docker-php-ext-enable mongodb \
;fi
########
## IGBINARY
# Igbinary is a drop in replacement for the standard php serializer.
# https://github.com/igbinary/igbinary
########
ARG INSTALL_PHP_IGBINARY=true
ENV PHP_IGBINARY_VERSION 3.1.2
RUN if [ $INSTALL_PHP_IGBINARY = true ]; then \
pecl install igbinary-${PHP_IGBINARY_VERSION} \
&& docker-php-ext-enable igbinary \
;fi
########
## LZF
# This package handles LZF de/compression.
# http://php.net/lzf
########
ARG INSTALL_PHP_LZF=true
ENV PHP_LZF_VERSION 1.6.7
RUN if [ $INSTALL_PHP_LZF = true ]; then \
pecl install lzf-${PHP_LZF_VERSION} \
&& docker-php-ext-enable lzf \
;fi
########
## MESSAGEPACK
# MessagePack is an efficient binary serialization format
# https://msgpack.org/
########
ARG INSTALL_PHP_MESSAGEPACK=true
ENV PHP_MESSAGEPACK_VERSION 2.1.0
RUN if [ $INSTALL_PHP_MESSAGEPACK = true ]; then \
pecl install msgpack-${PHP_MESSAGEPACK_VERSION} \
&& docker-php-ext-enable msgpack \
;fi
########
## REDIS
# https://github.com/phpredis/phpredis
########
ARG INSTALL_PHP_REDIS=true
ENV PHP_REDIS_VERSION 5.1.1
RUN if [ $INSTALL_PHP_REDIS = true ]; then \
# /configure --with-php-config=/usr/local/bin/php-config \
# --enable-redis-igbinary=yes \
# --enable-redis-lzf=yes
printf "yes \n yes \n" | pecl install -o -f redis-${PHP_REDIS_VERSION} \
&& docker-php-ext-enable redis \
;fi
########
## DATA STRUCTURES (DS)
# Data Structures (https://medium.com/p/9dda7af674cd)
# https://github.com/php-ds/extension
########
ARG INSTALL_PHP_DS=true
ENV PHP_DS_VERSION 1.2.9
RUN if [ $INSTALL_PHP_DS = true ]; then \
pecl install ds-${PHP_DS_VERSION} && \
docker-php-ext-enable ds \
;fi
########
## SQLSRV + PDO_SQLSRV
# Microsoft Drivers for PHP for SQL Server (SQLSRV + PDO_SQLSRV)
# @see https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server#debian-8-and-9
########
ARG INSTALL_PHP_SQLSRV=false
ENV PHP_SQLSRV_VERSION 5.8.0
RUN set -eux; \
\
if [ $INSTALL_PHP_SQLSRV = true ]; then \
\
# Installing the Microsoft ODBC Driver for SQL Server on Linux (DEBIAN)
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -; \
curl https://packages.microsoft.com/config/debian/9/prod.list | tee /etc/apt/sources.list.d/mssql-release.list; \
apt-get update; \
\
ACCEPT_EULA=Y apt-get install msodbcsql17 --no-install-recommends -y; \
\
# @see https://stackoverflow.com/questions/15447386/sql-h-header-file-missing-though-unixodbc-is-installed
apt-get install unixodbc-dev --no-install-recommends -y; \
\
## SQLSRV + PDO_SQLSRV
pecl install sqlsrv-${PHP_SQLSRV_VERSION} pdo_sqlsrv-${PHP_SQLSRV_VERSION}; \
\
docker-php-ext-enable sqlsrv pdo_sqlsrv; \
\
apt-get purge -y --auto-remove && rm -rf /var/lib/apt/lists/*; \
rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin; \
fi;
#####
## XDEBUG
#####
ARG INSTALL_PHP_XDEBUG=true
ENV PHP_XDEBUG_VERSION 2.9.2
RUN if [ $INSTALL_PHP_XDEBUG = true ]; then \
yes | pecl install xdebug-$PHP_XDEBUG_VERSION && \
docker-php-ext-enable xdebug \
;fi
###
## [FD]
## A simple, fast and user-friendly alternative to 'find'
###
ENV DEFAULT_PARAMETERS_FD -j $(nproc) --hidden --no-ignore --ignore-case
RUN set -ex \
&& echo "---> Adding [FD]" \
&& wget -O /tmp/fd.deb $(curl -s https://api.github.com/repos/sharkdp/fd/releases/latest | grep -Po '"browser_download_url":\s*"\K[^"]+/fd_.*_amd64.deb(?=")') \
&& dpkg -i /tmp/fd.deb \
&& rm /tmp/fd.deb \
&& which fd; fd --version
###
## [EXA]
## Replacement for 'ls' written in Rust. https://the.exa.website/
###
RUN set -ex \
&& echo "---> Adding [EXA]" \
&& wget -O /tmp/exa.zip $(curl -s https://api.github.com/repos/ogham/exa/releases/latest | grep -Po '"browser_download_url":\s*"\K[^"]+/exa-linux-x86_64-.*.zip(?=")') \
&& unzip /tmp/exa.zip -d /usr/local/bin/ \
&& mv /usr/local/bin/exa-linux-x86_64 /usr/local/bin/exa \
&& rm /tmp/exa.zip \
&& which exa; exa --version
###
## php.ini PRODUCTION
###
RUN set -ex \
&& echo "---> Move PHP.INI(PRODUCTION)" \
&& rm ${PHP_INI_DIR}/php.ini-development \
&& mv ${PHP_INI_DIR}/php.ini-production ${PHP_INI_DIR}/php.ini
###
## Verify PHP
###
RUN set -ex \
&& /usr/local/sbin/php-fpm --test \
&& PHP_ERROR="$( php -v 2>&1 1>/dev/null )" \
&& if [ -n "$PHP_ERROR" ]; then echo "$PHP_ERROR"; false; fi \
&& php -m; php -v; php --ini
###
## PERMISSION
###
RUN set -ex \
&& echo "---> Changing permissions" \
&& mkdir -p $REMOTE_SRC \
&& chown -R $DEFAULT_USER:$DEFAULT_USER /usr/local/lib/php \
/usr/local/var/log \
/usr/local/var/run \
/usr/local/etc \
/var/www \
/home/${DEFAULT_USER}
# && fd . /var/www $DEFAULT_PARAMETERS_FD --exec chown $DEFAULT_USER:$DEFAULT_USER {} \; \
# && fd . /usr/local/lib/php $DEFAULT_PARAMETERS_FD --exec chown $DEFAULT_USER:$DEFAULT_USER {} \; \
# && fd . /home/$DEFAULT_USER $DEFAULT_PARAMETERS_FD --exec chown -R $DEFAULT_USER:$DEFAULT_USER /home/$DEFAULT_USER {} \;
###
## Define the running USER
###
USER $DEFAULT_USER
###
## COMPOSER
###
RUN set -ex \
&& echo "---> COMPOSER" \
&& COMPOSER_HOME="/home/${DEFAULT_USER}/.composer/" \
&& curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer \
&& composer global require hirak/prestissimo:"^0.3" --ansi \
&& composer global install --prefer-dist --no-dev --no-suggest --optimize-autoloader --ansi \
&& composer clear-cache
###
## PHPUnit
###
RUN set -ex \
&& echo "---> PHPUNIT" \
&& wget https://phar.phpunit.de/phpunit.phar \
&& chmod +x phpunit.phar \
&& sudo mv phpunit.phar /usr/local/bin/phpunit \
&& command -v phpunit
# Application directory
# Sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile.
WORKDIR $REMOTE_SRC
# Environment variables
# Default: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV PATH="$PATH:/home/${DEFAULT_USER}/.composer/vendor/bin"
# vim:set ft=dockerfile: