-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
244 lines (207 loc) · 7.37 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
# PHP 8.2 FPM w/ Nginx
FROM debian:buster-slim
#############
# VARIABLES #
#############
ARG MACHINE_USER=devops
###############
# ENVIRONMENT #
###############
ENV APP_ENV prod
ENV PHP_VERSION 8.3
ENV NODE_MAJOR 20
ENV PROJECT_ROOT /var/www/html
ENV SERVER_NAME localhost
ENV SERVER_ADMIN [email protected]
ENV APACHE_DOCUMENT_ROOT ${PROJECT_ROOT}/public
ENV PROJECT_VAR ${PROJECT_ROOT}/var
ENV PROJECT_LOG ${PROJECT_VAR}/log
ARG BUILD_FILES=build_files
ARG PROJECT_SRC=${BUILD_FILES}/public
# -------------------------------------------------------------------------------------------------------------------- #
USER root
RUN echo "Europe/Paris" > /etc/timezone
# dependencies required for running "phpize"
# (see persistent deps below)
ENV PHPIZE_DEPS \
autoconf \
dpkg-dev \
file \
g++ \
gcc \
libc-dev \
make \
pkg-config \
re2c
RUN apt-get update && apt-get install -y \
$PHPIZE_DEPS \
ca-certificates \
curl \
gnupg \
wget \
xz-utils \
sudo \
unzip \
apt-transport-https \
lsb-release \
cron \
multitail \
nano \
supervisor \
mariadb-server \
mariadb-client \
php-dev \
php-pear \
htop \
rename
RUN wget -O- https://packages.sury.org/php/apt.gpg | apt-key add - && \
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
RUN wget -q -O - https://packages.blackfire.io/gpg.key | sudo dd of=/usr/share/keyrings/blackfire-archive-keyring.asc && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/blackfire-archive-keyring.asc] http://packages.blackfire.io/debian any main" | sudo tee /etc/apt/sources.list.d/blackfire.list
RUN apt-get update && apt-get install -y \
nginx \
redis \
blackfire \
openssl \
php${PHP_VERSION}-fpm \
php-fpm \
php${PHP_VERSION}-cli \
php${PHP_VERSION}-common \
php${PHP_VERSION}-curl \
php${PHP_VERSION}-mbstring \
php${PHP_VERSION}-amqp \
php${PHP_VERSION}-mongodb \
php${PHP_VERSION}-mysql \
php${PHP_VERSION}-sqlite \
php${PHP_VERSION}-gd \
php${PHP_VERSION}-intl \
php${PHP_VERSION}-opcache \
php${PHP_VERSION}-zip \
php${PHP_VERSION}-redis \
php${PHP_VERSION}-soap \
php${PHP_VERSION}-xml \
php${PHP_VERSION}-xdebug \
php-excimer
RUN apt purge php7.4\* -y
RUN apt install -y imagemagick && \
apt-get clean && \
rm -rf /tmp/* /var/tmp/*
#RUN pecl install xdebug
RUN wget -P /etc/ssl/certs/ http://curl.haxx.se/ca/cacert.pem && \
chmod 744 /etc/ssl/certs/cacert.pem
#RUN pecl channel-update pecl.php.net
#RUN pecl install mongodb-1.15.0
#RUN pecl install redis
#RUN pecl upgrade
COPY ${BUILD_FILES}/php.ini /etc/php/${PHP_VERSION}/cli/php.ini
COPY ${BUILD_FILES}/php.ini /etc/php/${PHP_VERSION}/fpm/php.ini
COPY ${BUILD_FILES}/conf.d /etc/php/${PHP_VERSION}/cli/conf.d
COPY ${BUILD_FILES}/conf.d /etc/php/${PHP_VERSION}/fpm/conf.d
RUN mkdir -p /usr/local/etc/[email protected]
#COPY ${BUILD_FILES}/cert.pem /usr/local/etc/[email protected]/cert.pem
#########################
# AWS CLI Install & Setup #
#########################
RUN cd && \
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
./aws/install
# Install CloudWatch Agent
#COPY ${BUILD_FILES}/amazon-cloudwatch-agent.deb /root/amazon-cloudwatch-agent.deb
#RUN dpkg -i -E /root/amazon-cloudwatch-agent.deb
RUN mkdir -p /var/run/blackfire
#RUN blackfire php:install && \
# blackfire agent:config \
# --server-id=<server_id> \
# --server-token=<server_token> \
# --socket=tcp://127.0.0.1:8307 \
# --log-file=/var/log/blackfire-agent.log
RUN rm -r /var/lib/apt/lists/*
# COMPOSER INSTALLATION
RUN curl -sS https://getcomposer.org/installer | php && \
mv composer.phar /usr/local/bin/composer && \
chmod +x /usr/local/bin/composer
RUN composer -V
RUN composer self-update
# YARN
RUN 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
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update && apt-get install -y \
nodejs
RUN npm install --global yarn
RUN yarn set version stable
RUN yarn set version latest
# CACHETOOL - to clear opcache
# https://github.com/gordalina/cachetool
RUN curl -sLO https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar && \
mv cachetool.phar /usr/local/bin/cachetool && \
chmod +x /usr/local/bin/cachetool
# -------------------------------------------------------------------------------------------------------------------- #
RUN sudo update-alternatives --set php /usr/bin/php${PHP_VERSION}
RUN sudo update-alternatives --set phar /usr/bin/phar${PHP_VERSION}
RUN sudo update-alternatives --set phar.phar /usr/bin/phar.phar${PHP_VERSION}
#####################
# CUSTOM USER SETUP #
#####################
# Creating the user and group
RUN groupadd user && useradd -g user -m -d /home/user user -s /bin/bash
RUN addgroup --gid 1337 ${MACHINE_USER} && \
adduser --disabled-password --gecos "" --force-badname --ingroup ${MACHINE_USER} ${MACHINE_USER} && \
usermod -aG www-data ${MACHINE_USER}
######################
# DEFAULT LOGS FILES #
######################
USER root
RUN mkdir ${PROJECT_VAR} -p
RUN mkdir ${PROJECT_ROOT}/public -p
RUN mkdir ${PROJECT_LOG}/nginx -p
# -------------------------------------------------------------------------------------------------------------------- #
#####################################
# PROJECT ROOT DIRECTORY OWNSERSHIP #
#####################################
USER root
RUN chown ${MACHINE_USER}:www-data ${PROJECT_ROOT} -R
# PROJECT DIRECTORIES PERMISSIONS
USER root
RUN chmod 775 ${PROJECT_ROOT} -R && \
chmod 2775 ${PROJECT_VAR} -R && \
chmod 2777 ${PROJECT_LOG} -R
# -------------------------------------------------------------------------------------------------------------------- #
############################
# NGINX CONFIGURATION #
############################
COPY ${BUILD_FILES}/default.conf /etc/nginx/sites-available/default
COPY ${BUILD_FILES}/public ${PROJECT_ROOT}/public
COPY ${BUILD_FILES}/fpm/website_pool.conf /etc/php/${PHP_VERSION}/fpm/pool.d
# Will create the sock, so supervisor can start the program php-fpm
RUN /etc/init.d/php${PHP_VERSION}-fpm start && \
cachetool opcache:reset && \
cachetool opcache:status && \
/etc/init.d/php${PHP_VERSION}-fpm stop
############################
# SUPERVISOR CONFIGURATION #
############################
USER root
COPY ${BUILD_FILES}/supermd.conf /etc/supervisor/conf.d/supermd.conf
COPY ${BUILD_FILES}/supervisord.conf /etc/supervisor/supervisord.conf
# -------------------------------------------------------------------------------------------------------------------- #
#######################
# CRON CONFIGURATION #
#######################
USER root
# Add crontab file in the cron directory
COPY ${BUILD_FILES}/mdcron /etc/cron.d/mdcron
# Give execution rights on the cron job
# Apply cron job
RUN chmod 0644 /etc/cron.d/mdcron && \
crontab /etc/cron.d/mdcron
# -------------------------------------------------------------------------------------------------------------------- #
RUN php -m
RUN php -v
#########################
# RUN SUPERVISOR DAEMON #
#########################
USER root
CMD ["/usr/bin/supervisord"]
WORKDIR ${PROJECT_ROOT}