forked from thecodingmachine/docker-images-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.slim.cli
301 lines (236 loc) · 10.7 KB
/
Dockerfile.slim.cli
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
# DO NOT EDIT THIS FILE : Make yours changes in /utils/Dockerfile.*.blueprint)
FROM ubuntu:jammy
LABEL authors="Julien Neuhart <[email protected]>, David Négrier <[email protected]>"
SHELL ["/bin/bash", "-c"]
# Fixes some weird terminal issues such as broken clear / CTRL+L
#ENV TERM=linux
# Ensure apt doesn't ask questions when installing stuff
ENV DEBIAN_FRONTEND=noninteractive
ARG PHP_VERSION
ENV PHP_VERSION=$PHP_VERSION
ARG TARGETARCH
ENV TARGETARCH=$TARGETARCH
# |--------------------------------------------------------------------------
# | Main PHP extensions
# |--------------------------------------------------------------------------
# |
# | Installs the main PHP extensions
# |
# Install php an other packages
RUN apt update \
&& apt install -y --no-install-recommends gnupg software-properties-common \
&& apt-add-repository ppa:ondrej/php \
&& apt update \
&& apt upgrade -y \
&& apt install -y --no-install-recommends \
git \
nano \
sudo \
iproute2 \
openssh-client \
procps \
unzip \
ca-certificates \
curl \
php${PHP_VERSION}-cli \
php${PHP_VERSION}-curl \
php${PHP_VERSION}-mbstring \
php${PHP_VERSION}-opcache \
php${PHP_VERSION}-readline \
php${PHP_VERSION}-xml \
php${PHP_VERSION}-zip \
&& apt clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# |--------------------------------------------------------------------------
# | User
# |--------------------------------------------------------------------------
# |
# | Define a default user with sudo rights.
# |
RUN useradd -ms /bin/bash docker && adduser docker sudo
# Users in the sudoers group can sudo as root without password.
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# |--------------------------------------------------------------------------
# | Default php.ini file
# |--------------------------------------------------------------------------
# |
# | For some reasons, the official image has a php.ini-production.cli file
# | but no php.ini-development.cli file. Let's create this one.
# |
RUN cp /usr/lib/php/${PHP_VERSION}/php.ini-development /usr/lib/php/${PHP_VERSION}/php.ini-development.cli && \
sed -i 's/^disable_functions/;disable_functions/g' /usr/lib/php/${PHP_VERSION}/php.ini-development.cli && \
sed -i 's/^memory_limit = .*/memory_limit = -1/g' /usr/lib/php/${PHP_VERSION}/php.ini-development.cli
#ADD https://raw.githubusercontent.com/php/php-src/PHP-${PHP_VERSION}/php.ini-production /usr/local/etc/php/php.ini-production
#ADD https://raw.githubusercontent.com/php/php-src/PHP-${PHP_VERSION}/php.ini-development /usr/local/etc/php/php.ini-development
#RUN chmod 644 /usr/local/etc/php/php.ini-*
ENV TEMPLATE_PHP_INI=development
# Let's remove the default CLI php.ini file (it will be copied from TEMPLATE_PHP_INI)
RUN rm /etc/php/${PHP_VERSION}/cli/php.ini
# |--------------------------------------------------------------------------
# | Composer
# |--------------------------------------------------------------------------
# |
# | Installs Composer to easily manage your PHP dependencies.
# |
#ENV COMPOSER_ALLOW_SUPERUSER 1
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer &&\
chmod +x /usr/local/bin/composer
# TODO: utils.php in /usr/local/bin... bof!
COPY utils/utils.php /usr/local/bin/utils.php
RUN mv /usr/bin/php /usr/bin/real_php
COPY utils/php_proxy.sh /usr/bin/php
COPY utils/check_php_env_var_changes.php /usr/local/bin/check_php_env_var_changes.php
COPY utils/php_env_var_cache.php /opt/php_env_var_cache.php
COPY utils/generate_conf.php /usr/local/bin/generate_conf.php
COPY utils/setup_extensions.php /usr/local/bin/setup_extensions.php
# |--------------------------------------------------------------------------
# | Default PHP extensions to be enabled
# | By default, enable all the extensions that are enabled on a base Ubuntu install
# |--------------------------------------------------------------------------
ENV PHP_EXTENSION_CALENDAR=1 \
PHP_EXTENSION_CTYPE=1 \
PHP_EXTENSION_CURL=1 \
PHP_EXTENSION_DOM=1 \
PHP_EXTENSION_EXIF=1 \
PHP_EXTENSION_FILEINFO=1 \
PHP_EXTENSION_FTP=1 \
PHP_EXTENSION_GETTEXT=1 \
PHP_EXTENSION_ICONV=1 \
PHP_EXTENSION_JSON=1 \
PHP_EXTENSION_MBSTRING=1 \
PHP_EXTENSION_OPCACHE=1 \
PHP_EXTENSION_PDO=1 \
PHP_EXTENSION_PHAR=1 \
PHP_EXTENSION_POSIX=1 \
PHP_EXTENSION_READLINE=1 \
PHP_EXTENSION_SHMOP=1 \
PHP_EXTENSION_SIMPLEXML=1 \
PHP_EXTENSION_SOCKETS=1 \
PHP_EXTENSION_SYSVMSG=1 \
PHP_EXTENSION_SYSVSEM=1 \
PHP_EXTENSION_SYSVSHM=1 \
PHP_EXTENSION_TOKENIZER=1 \
PHP_EXTENSION_WDDX=1 \
PHP_EXTENSION_XML=1 \
PHP_EXTENSION_XMLREADER=1 \
PHP_EXTENSION_XMLWRITER=1 \
PHP_EXTENSION_XSL=1 \
PHP_EXTENSION_ZIP=1
USER docker
RUN composer global require bamarni/symfony-console-autocomplete && \
rm -rf ~/.composer/cache
USER root
RUN mkdir -p /usr/src/app && chown docker:docker /usr/src/app
WORKDIR /usr/src/app
# |--------------------------------------------------------------------------
# | PATH updating
# |--------------------------------------------------------------------------
# |
# | Let's add ./vendor/bin to the PATH (utility function to use Composer bin easily)
# |
ENV PATH="$PATH:./vendor/bin:~/.composer/vendor/bin"
RUN sed -i 's#/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin#/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:./vendor/bin:~/.composer/vendor/bin#g' /etc/sudoers
USER docker
# |--------------------------------------------------------------------------
# | SSH client
# |--------------------------------------------------------------------------
# |
# | Let's set-up the SSH client (for connections to private git repositories)
# | We create an empty known_host file and we launch the ssh-agent
# |
RUN mkdir ~/.ssh && touch ~/.ssh/known_hosts && chmod 644 ~/.ssh/known_hosts && eval $(ssh-agent -s)
# |--------------------------------------------------------------------------
# | .bashrc updating
# |--------------------------------------------------------------------------
# |
# | Let's update the .bashrc to add nice aliases
# |
RUN echo 'eval "$(symfony-autocomplete)"' > ~/.bash_profile
RUN { \
echo "alias ls='ls --color=auto'"; \
echo "alias ll='ls --color=auto -alF'"; \
echo "alias la='ls --color=auto -A'"; \
echo "alias l='ls --color=auto -CF'"; \
} >> ~/.bashrc
USER root
# |--------------------------------------------------------------------------
# | NodeJS
# |--------------------------------------------------------------------------
# |
# | NodeJS path registration (if we install NodeJS, this is useful).
# |
ENV PATH="$PATH:./node_modules/.bin"
RUN sed -i 's#/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin#/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:./node_modules/.bin#g' /etc/sudoers
# |--------------------------------------------------------------------------
# | Entrypoint
# |--------------------------------------------------------------------------
# |
# | Defines the entrypoint.
# |
ENV IMAGE_VARIANT=cli
COPY utils/generate_cron.php /usr/local/bin/generate_cron.php
COPY utils/startup_commands.php /usr/local/bin/startup_commands.php
COPY utils/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
COPY utils/docker-entrypoint-as-root.sh /usr/local/bin/docker-entrypoint-as-root.sh
COPY extensions/ /usr/local/lib/thecodingmachine-php/extensions
RUN ln -s ${PHP_VERSION} /usr/local/lib/thecodingmachine-php/extensions/current
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["php", "-v"]
RUN touch /etc/php/${PHP_VERSION}/mods-available/generated_conf.ini && ln -s /etc/php/${PHP_VERSION}/mods-available/generated_conf.ini /etc/php/${PHP_VERSION}/cli/conf.d/generated_conf.ini
USER docker
COPY utils/install_selected_extensions.php /usr/local/bin/install_selected_extensions.php
COPY utils/install_selected_extensions.sh /usr/local/bin/install_selected_extensions.sh
ONBUILD ARG PHP_EXTENSIONS
ONBUILD ENV PHP_EXTENSIONS="$PHP_EXTENSIONS"
ONBUILD RUN sudo -E PHP_EXTENSIONS="$PHP_EXTENSIONS" /usr/local/bin/install_selected_extensions.sh
# |--------------------------------------------------------------------------
# | Supercronic
# |--------------------------------------------------------------------------
# |
# | Supercronic is a drop-in replacement for cron (for containers).
# | https://github.com/aptible/supercronic
# |
ENV SUPERCRONIC_OPTIONS=
ENV SUPERCRONIC_VERSION=v0.2.27
ONBUILD ARG INSTALL_CRON
ONBUILD RUN if [ -n "$INSTALL_CRON" ]; then \
SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/${SUPERCRONIC_VERSION}/supercronic-linux-${TARGETARCH} \
&& SUPERCRONIC=supercronic-linux-${TARGETARCH} \
&& curl -fsSLO "$SUPERCRONIC_URL" \
&& chmod +x "$SUPERCRONIC" \
&& sudo mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
&& sudo ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic; \
fi;
# |--------------------------------------------------------------------------
# | NodeJS
# |--------------------------------------------------------------------------
# |
# | Installs NodeJS and npm. The later will allow you to easily manage
# | your frontend dependencies.
# | Also installs yarn. It provides some nice improvements over npm.
# |
ONBUILD ARG NODE_VERSION
ONBUILD RUN if [ -n "$NODE_VERSION" ]; then \
sudo mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list && \
curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/yarn.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/yarn.gpg] https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list && \
sudo apt update && \
sudo apt install -y --no-install-recommends nodejs yarn && \
sudo apt clean && \
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*; \
fi;
# |--------------------------------------------------------------------------
# | wkhtmltopdf and wkhtmltoimage
# |--------------------------------------------------------------------------
# |
# | Installs wkhtmltopdf and wkhtmltoimage to render HTML into PDF and
# | various image formats using the Qt WebKit rendering engine.
# |
ONBUILD ARG INSTALL_WKHTMLTOX
ONBUILD RUN if [ -n "$INSTALL_WKHTMLTOX" ]; then \
sudo apt update && \
sudo apt install -y --no-install-recommends wkhtmltopdf && \
sudo apt clean; \
fi;