Skip to content

Commit bdbfe21

Browse files
Fix: PHP 8.1.22 -> 8.1.28 alpine 3.16 -> 3.18 + repo 3.13 -> 3.18
Fix: nginx default config not loaded Fix: nginx permissions Test : docker Test: docker Test: docker Fix: docker Test: docker Test: docker Test: docker Test: docker Test: docker Test: docker Test: docker Test: docker Test: docker Test: docker Test: docker Test: docker Test: docker Test: docker Test: docker Test: docker Test: docker Chore: refactor Test: docker
1 parent a86dc65 commit bdbfe21

10 files changed

+1210
-592
lines changed

Dockerfile

Lines changed: 68 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
#FROM node:20.0.0-alpine as node
2-
FROM node:19.9.0-alpine as node
1+
FROM node:19.9.0-alpine AS node
32

4-
FROM php:8.1.22-fpm-alpine3.16 as base
5-
6-
# Setup Working Dir
7-
WORKDIR /var/www
3+
# Base image with PHP-FPM
4+
#FROM php:8.1.22-fpm-alpine3.16 AS base
5+
FROM php:8.1.28-fpm-alpine3.18 AS base
86

97
# Musl for adding locales
10-
ENV MUSL_LOCALE_DEPS cmake make musl-dev gcc gettext-dev libintl
11-
ENV MUSL_LOCPATH /usr/share/i18n/locales/musl
8+
ENV MUSL_LOCALE_DEPS="cmake make musl-dev gcc gettext-dev libintl"
9+
ENV MUSL_LOCPATH="/usr/share/i18n/locales/musl"
1210

1311
RUN apk add --no-cache \
1412
$MUSL_LOCALE_DEPS \
@@ -20,8 +18,8 @@ RUN apk add --no-cache \
2018

2119
# Add Repositories
2220
RUN rm -f /etc/apk/repositories &&\
23-
echo "http://dl-cdn.alpinelinux.org/alpine/v3.13/main" >> /etc/apk/repositories && \
24-
echo "http://dl-cdn.alpinelinux.org/alpine/v3.13/community" >> /etc/apk/repositories
21+
echo "http://dl-cdn.alpinelinux.org/alpine/v3.18/main" >> /etc/apk/repositories && \
22+
echo "http://dl-cdn.alpinelinux.org/alpine/v3.18/community" >> /etc/apk/repositories
2523

2624
# Add Build Dependencies
2725
RUN apk update && apk add --no-cache --virtual .build-deps \
@@ -90,36 +88,59 @@ RUN docker-php-ext-configure \
9088
xsl \
9189
&& docker-php-ext-enable \
9290
imagick \
93-
redis && \
94-
chown www-data:www-data /usr/sbin/crond && \
95-
setcap cap_setgid=ep /usr/sbin/crond
96-
97-
COPY ./config/php.ini $PHP_INI_DIR/conf.d/
98-
99-
# Setup config for supervisor nginx php-fpm crontabs
100-
RUN mkdir /etc/supervisor.d
101-
COPY ./config/supervisord-master.ini /etc/supervisor.d/master.ini
102-
COPY ./config/supervisord.conf /etc/
103-
104-
RUN mkdir /var/log/supervisor/
105-
RUN touch /var/log/supervisor/supervisord.log
106-
RUN chown -R www-data:www-data /var/log/supervisor/
107-
108-
COPY ./config/nginx-default.conf /etc/nginx/conf.d/default.conf
91+
redis
92+
93+
# Create necessary directories and set permissions
94+
RUN mkdir -p /var/run/nginx \
95+
&& mkdir -p /var/run/php-fpm \
96+
&& mkdir -p /var/run/supervisor \
97+
&& mkdir -p /var/log/nginx \
98+
&& mkdir -p /var/log/supervisor \
99+
&& mkdir -p /var/log/php-fpm \
100+
&& chown -R www-data:www-data /var/run/nginx \
101+
&& chown -R www-data:www-data /var/run/php-fpm \
102+
&& chown -R www-data:www-data /var/run/supervisor \
103+
&& chown -R www-data:www-data /var/log/nginx \
104+
&& chown -R www-data:www-data /var/log/supervisor \
105+
&& chown -R www-data:www-data /var/log/php-fpm \
106+
&& chown -R www-data:www-data /etc/nginx \
107+
&& chown -R www-data:www-data /usr/sbin/nginx \
108+
&& chown -R www-data:www-data /usr/local/sbin/php-fpm \
109+
&& chown -R www-data:www-data /usr/local/etc/php-fpm.conf \
110+
&& touch /var/log/php-fpm/php-fpm.log \
111+
&& chown www-data:www-data /var/log/php-fpm/php-fpm.log \
112+
&& mkdir -p /run \
113+
&& chown www-data:www-data /run
114+
115+
# Ensure cron directories exist and have correct permissions
116+
RUN mkdir -p /etc/cron.d \
117+
&& mkdir -p /etc/periodic \
118+
&& touch /etc/crontabs/www-data \
119+
&& chmod 755 /etc/cron.d \
120+
&& chmod 755 /etc/periodic \
121+
&& chown www-data:www-data /etc/cron.d \
122+
&& chown www-data:www-data /etc/periodic \
123+
&& chown www-data:www-data /etc/crontabs \
124+
&& chmod 755 /usr/sbin/crond \
125+
&& chown www-data:www-data /usr/sbin/crond \
126+
&& setcap cap_setgid=ep /usr/sbin/crond
127+
128+
# Copy Nginx and Supervisor configuration files
109129
COPY ./config/nginx.conf /etc/nginx/nginx.conf
130+
COPY ./config/nginx-default.conf /etc/nginx/conf.d/default.conf
110131

111-
COPY ./config/php-fpm.conf /usr/local/etc/php-fpm.conf.d/www.conf
112-
COPY ./config/php-fpm.conf /usr/local/etc/php-fpm.d/www.conf
113-
COPY ./config/php-fpm-docker.conf /usr/local/etc/php-fpm.d/docker.conf
132+
# Copy Supervisor config files
133+
COPY ./config/supervisord.conf /etc/supervisord.conf
134+
COPY ./config/supervisord-master.ini /etc/supervisor.d/master.ini
114135

115-
RUN chmod 755 -R /etc/supervisor.d/ /etc/supervisord.conf /etc/nginx/ /etc/crontabs/
136+
# Copy custom PHP-FPM configuration
137+
COPY ./config/php-fpm.conf /usr/local/etc/php-fpm.conf
116138

117-
# Remove Build Dependencies
118-
RUN apk del -f .build-deps
139+
# Copy PHP configuration
140+
COPY ./config/php.ini /usr/local/etc/php/php.ini
119141

120-
RUN mkdir -p /var/lib/nginx/tmp /var/log/nginx \
121-
&& chown -R www-data:www-data /var/lib/nginx /var/log/nginx \
122-
&& chmod -R 755 /var/lib/nginx /var/log/nginx
142+
# Set permissions
143+
RUN chown -R www-data:www-data /var/lib/nginx /var/log/nginx /run/nginx /var/log/supervisor /var/run
123144

124145
# Add non root user to the tty group, so we can write to stdout and stderr
125146
RUN addgroup www-data tty
@@ -140,6 +161,17 @@ COPY --from=node /usr/local/bin /usr/local/bin
140161
# More info here : https://stackoverflow.com/questions/69417926/docker-error-eacces-permission-denied-mkdir
141162
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
142163

164+
# Remove Build Dependencies
165+
RUN apk del -f .build-deps
166+
167+
# Setup Working Dir
168+
WORKDIR /var/www
169+
170+
# Switch to www-data user to run services
143171
USER www-data
144172

145-
CMD ["/usr/bin/supervisord"]
173+
# Expose ports
174+
EXPOSE 8080
175+
176+
# Command to run supervisord
177+
CMD ["supervisord", "-c", "/etc/supervisord.conf"]

bak.Dockerfile

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#FROM node:20.0.0-alpine as node
2+
FROM node:19.9.0-alpine AS node
3+
4+
#FROM php:8.1.22-fpm-alpine3.16 AS base
5+
FROM php:8.1.28-fpm-alpine3.18 AS base
6+
7+
# Setup Working Dir
8+
WORKDIR /var/www
9+
10+
# Musl for adding locales
11+
ENV MUSL_LOCALE_DEPS="cmake make musl-dev gcc gettext-dev libintl"
12+
ENV MUSL_LOCPATH="/usr/share/i18n/locales/musl"
13+
14+
RUN apk add --no-cache \
15+
$MUSL_LOCALE_DEPS \
16+
&& wget https://gitlab.com/rilian-la-te/musl-locales/-/archive/master/musl-locales-master.zip \
17+
&& unzip musl-locales-master.zip \
18+
&& cd musl-locales-master \
19+
&& cmake -DLOCALE_PROFILE=OFF -D CMAKE_INSTALL_PREFIX:PATH=/usr . && make && make install \
20+
&& cd .. && rm -r musl-locales-master
21+
22+
# Add Repositories
23+
RUN rm -f /etc/apk/repositories &&\
24+
echo "http://dl-cdn.alpinelinux.org/alpine/v3.18/main" >> /etc/apk/repositories && \
25+
echo "http://dl-cdn.alpinelinux.org/alpine/v3.18/community" >> /etc/apk/repositories
26+
27+
# Add Build Dependencies
28+
RUN apk update && apk add --no-cache --virtual .build-deps \
29+
zlib-dev \
30+
libjpeg-turbo-dev \
31+
libpng-dev \
32+
python3 \
33+
gcc \
34+
clang \
35+
llvm \
36+
libxml2-dev \
37+
bzip2-dev
38+
39+
# Add Production Dependencies
40+
RUN apk add --update --no-cache \
41+
bash \
42+
jq \
43+
nano \
44+
git \
45+
openssh \
46+
pcre-dev ${PHPIZE_DEPS} \
47+
jpegoptim \
48+
pngquant \
49+
optipng \
50+
supervisor \
51+
nginx \
52+
dcron \
53+
libcap \
54+
icu-dev \
55+
freetype-dev \
56+
postgresql-dev \
57+
postgresql-client \
58+
zip \
59+
libzip-dev \
60+
less \
61+
imagemagick \
62+
libxslt-dev \
63+
exiftool \
64+
imagemagick-dev \
65+
chromium \
66+
&& pecl install redis \
67+
&& pecl install -o -f imagick
68+
69+
# Configure & Install Extension
70+
RUN docker-php-ext-configure \
71+
opcache --enable-opcache &&\
72+
docker-php-ext-configure gd --with-jpeg=/usr/include/ --with-freetype=/usr/include/ && \
73+
docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql &&\
74+
docker-php-ext-configure zip && \
75+
docker-php-ext-install \
76+
opcache \
77+
mysqli \
78+
pgsql \
79+
pdo \
80+
pdo_mysql \
81+
pdo_pgsql \
82+
sockets \
83+
intl \
84+
gd \
85+
xml \
86+
bz2 \
87+
pcntl \
88+
bcmath \
89+
exif \
90+
zip \
91+
xsl \
92+
&& docker-php-ext-enable \
93+
imagick \
94+
redis && \
95+
chown www-data:www-data /usr/sbin/crond && \
96+
setcap cap_setgid=ep /usr/sbin/crond
97+
98+
COPY ./config/php.ini $PHP_INI_DIR/conf.d/
99+
100+
# Setup config for supervisor nginx php-fpm crontabs
101+
RUN mkdir /etc/supervisor.d
102+
COPY ./config/supervisord-master.ini /etc/supervisor.d/master.ini
103+
COPY ./config/supervisord.conf /etc/
104+
105+
RUN mkdir /var/log/supervisor/
106+
RUN touch /var/log/supervisor/supervisord.log
107+
RUN chown -R www-data:www-data /var/log/supervisor/
108+
109+
COPY ./config/nginx-default.conf /etc/nginx/conf.d/default.conf
110+
COPY ./config/nginx.conf /etc/nginx/nginx.conf
111+
112+
# Tests
113+
#RUN chmod -R 777 /etc/nginx/
114+
#RUN chown www-data:www-data /etc/nginx/conf.d/default.conf
115+
#RUN chown www-data:www-data /etc/nginx/nginx.conf
116+
117+
COPY ./config/php-fpm.conf /usr/local/etc/php-fpm.conf.d/www.conf
118+
COPY ./config/php-fpm.conf /usr/local/etc/php-fpm.d/www.conf
119+
COPY ./config/php-fpm-docker.conf /usr/local/etc/php-fpm.d/docker.conf
120+
121+
RUN chmod 755 -R /etc/supervisor.d/ /etc/supervisord.conf /etc/nginx/ /etc/crontabs/
122+
123+
# Remove Build Dependencies
124+
RUN apk del -f .build-deps
125+
126+
RUN mkdir -p /var/lib/nginx/tmp /var/log/nginx \
127+
&& chown -R www-data:www-data /var/lib/nginx /var/log/nginx /etc/nginx \
128+
&& chmod -R 755 /var/lib/nginx /var/log/nginx /etc/nginx
129+
130+
# Add non root user to the tty group, so we can write to stdout and stderr
131+
RUN addgroup www-data tty
132+
133+
# Install Composer
134+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
135+
136+
# Install Node
137+
COPY --from=node /usr/lib /usr/lib
138+
COPY --from=node /usr/local/share /usr/local/share
139+
COPY --from=node /usr/local/lib /usr/local/lib
140+
COPY --from=node /usr/local/include /usr/local/include
141+
COPY --from=node /usr/local/bin /usr/local/bin
142+
143+
# Puppeteer npm configuration.
144+
# It uses apk installed Chromium "/usr/bin/chromium-browser", tell Puppeteer to not install local Chromium which takes time.
145+
# Compatible version = Puppeteer 10.0.0. Install in project with "npm install [email protected]".
146+
# More info here : https://stackoverflow.com/questions/69417926/docker-error-eacces-permission-denied-mkdir
147+
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
148+
149+
USER www-data
150+
151+
#CMD ["/usr/bin/supervisord"]
152+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]

config/nginx-default.conf.bak

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
fastcgi_cache_path /dev/shm levels=1:2 keys_zone=laravel:100m;
2+
fastcgi_cache_key "$scheme$request_method$host$request_uri$query_string";
3+
4+
map $http_x_forwarded_proto $fastcgi_param_https_variable {
5+
default '';
6+
https 'on';
7+
}
8+
9+
error_log stderr;
10+
11+
server {
12+
access_log /dev/stdout;
13+
14+
listen 8080 default_server;
15+
server_name _;
16+
17+
index index.php index.html;
18+
root /var/www/public;
19+
20+
#client_max_body_size 20M;
21+
client_max_body_size 4G;
22+
23+
# Compression
24+
25+
# Enable Gzip compressed.
26+
gzip on;
27+
28+
# Enable compression both for HTTP/1.0 and HTTP/1.1.
29+
gzip_http_version 1.1;
30+
31+
# Compression level (1-9).
32+
# 5 is a perfect compromise between size and cpu usage, offering about
33+
# 75% reduction for most ascii files (almost identical to level 9).
34+
gzip_comp_level 5;
35+
36+
# Don't compress anything that's already small and unlikely to shrink much
37+
# if at all (the default is 20 bytes, which is bad as that usually leads to
38+
# larger files after gzipping).
39+
gzip_min_length 256;
40+
41+
# Compress data even for clients that are connecting to us via proxies,
42+
# identified by the "Via" header (required for CloudFront).
43+
gzip_proxied any;
44+
45+
# Tell proxies to cache both the gzipped and regular version of a resource
46+
# whenever the client's Accept-Encoding capabilities header varies;
47+
# Avoids the issue where a non-gzip capable client (which is extremely rare
48+
# today) would display gibberish if their proxy gave them the gzipped version.
49+
gzip_vary on;
50+
51+
# Compress all output labeled with one of the following MIME-types.
52+
gzip_types
53+
application/atom+xml
54+
application/javascript
55+
application/json
56+
application/rss+xml
57+
application/vnd.ms-fontobject
58+
application/x-font-ttf
59+
application/x-web-app-manifest+json
60+
application/xhtml+xml
61+
application/xml
62+
font/opentype
63+
image/svg+xml
64+
image/x-icon
65+
image/jpeg
66+
image/png
67+
text/css
68+
text/plain
69+
text/x-component;
70+
# text/html is always compressed by HttpGzipModule
71+
72+
location / {
73+
try_files $uri $uri/ /index.php?$query_string;
74+
}
75+
76+
location ~ \.php$ {
77+
root /var/www/public;
78+
fastcgi_cache off;
79+
fastcgi_cache_valid 200 204 1m;
80+
fastcgi_ignore_headers Cache-Control;
81+
fastcgi_no_cache $http_authorization $cookie_laravel_session;
82+
fastcgi_cache_lock on;
83+
fastcgi_cache_lock_timeout 10s;
84+
85+
# Bigger buffer size to handle cache invalidation headers expansion
86+
fastcgi_buffer_size 32k;
87+
fastcgi_buffers 8 16k;
88+
89+
90+
add_header X-Proxy-Cache $upstream_cache_status;
91+
92+
fastcgi_pass localhost:9000;
93+
fastcgi_index index.php;
94+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
95+
fastcgi_param HTTPS $fastcgi_param_https_variable;
96+
fastcgi_read_timeout 900s;
97+
include fastcgi_params;
98+
}
99+
100+
location ~* \.(jpg|jpeg|png|gif|ico|css|js|eot|ttf|woff|woff2)$ {
101+
expires max;
102+
add_header Cache-Control public;
103+
add_header Access-Control-Allow-Origin *;
104+
try_files $uri $uri/ /index.php?$query_string;
105+
}
106+
107+
location ~ /\.ht {
108+
deny all;
109+
}
110+
}

0 commit comments

Comments
 (0)