Skip to content

Commit 4811aa0

Browse files
committed
feat: simplify stack
Added supervisor, healthcheck, fpm-ping. Removed nginx image.
1 parent caded49 commit 4811aa0

File tree

15 files changed

+243
-75
lines changed

15 files changed

+243
-75
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ uploads/*
44
!uploads/.gitkeep
55
.env*
66
!*.example
7+
volumes/mysql-data/*
8+
!volumes/mysql-data/.gitkeep
9+

wordpress/Dockerfile renamed to Dockerfile

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ARG COMPOSER_VERSION=2.0
33
FROM composer:${COMPOSER_VERSION} as composer
44
FROM php:8.0-fpm
55

6+
67
RUN apt-get update -y && apt-get install -y \
78
pkg-config libssl-dev \
89
curl \
@@ -13,7 +14,9 @@ RUN apt-get update -y && apt-get install -y \
1314
libjpeg-dev \
1415
libzip-dev \
1516
libmagickwand-dev \
16-
nasm
17+
nasm \
18+
nginx \
19+
supervisor
1720

1821
# Clear cache
1922
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
@@ -28,10 +31,28 @@ RUN docker-php-ext-configure gd --enable-gd --with-jpeg --with-webp && docker-ph
2831
# Installing composer
2932
COPY --from=composer /usr/bin/composer /usr/local/bin/composer
3033

34+
# Configure nginx
35+
COPY /config/nginx/nginx.conf /etc/nginx/nginx.conf
36+
COPY /config/nginx/50x.html /var/www/localhost/htdocs/50x.html
37+
COPY /config/nginx/index.html /var/www/localhost/htdocs/index.html
38+
39+
# Configure php-fpm
40+
COPY /config/fpm-pool.conf /usr/local/etc/php-fpm.d/fpm-pool.conf
41+
42+
# Configure supervisor
43+
COPY /config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
44+
3145
WORKDIR /var/www/html
32-
COPY . /var/www/html
46+
COPY wordpress/ /var/www/html
3347

3448
# RUN composer install
3549
# Replaced by "docker exec"
3650

37-
VOLUME /var/www/html
51+
VOLUME /var/www/html
52+
53+
EXPOSE 80
54+
55+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
56+
57+
# Configure a healthcheck to validate that everything is up&running
58+
HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:80/fpm-ping

config/fpm-pool.conf

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[global]
2+
; Log to stderr
3+
error_log = /dev/stderr
4+
5+
[www]
6+
; The address on which to accept FastCGI requests.
7+
; Valid syntaxes are:
8+
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
9+
; a specific port;
10+
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
11+
; a specific port;
12+
; 'port' - to listen on a TCP socket to all addresses
13+
; (IPv6 and IPv4-mapped) on a specific port;
14+
; '/path/to/unix/socket' - to listen on a unix socket.
15+
; Note: This value is mandatory.
16+
listen = 127.0.0.1:9000
17+
18+
; Enable status page
19+
pm.status_path = /fpm-status
20+
21+
; Ondemand process manager
22+
pm = ondemand
23+
24+
; The number of child processes to be created when pm is set to 'static' and the
25+
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
26+
; This value sets the limit on the number of simultaneous requests that will be
27+
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
28+
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
29+
; CGI. The below defaults are based on a server without much resources. Don't
30+
; forget to tweak pm.* to fit your needs.
31+
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
32+
; Note: This value is mandatory.
33+
pm.max_children = 100
34+
35+
; The number of seconds after which an idle process will be killed.
36+
; Note: Used only when pm is set to 'ondemand'
37+
; Default Value: 10s
38+
pm.process_idle_timeout = 10s;
39+
40+
; The number of requests each child process should execute before respawning.
41+
; This can be useful to work around memory leaks in 3rd party libraries. For
42+
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
43+
; Default Value: 0
44+
pm.max_requests = 1000
45+
46+
; Make sure the FPM workers can reach the environment variables for configuration
47+
clear_env = no
48+
49+
; Catch output from PHP
50+
catch_workers_output = yes
51+
52+
; Enable ping page to use in healthcheck
53+
ping.path = /fpm-ping
File renamed without changes.

config/nginx/50x.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Error</title>
5+
<style>
6+
body {
7+
width: 35em;
8+
margin: 0 auto;
9+
font-family: Tahoma, Verdana, Arial, sans-serif;
10+
}
11+
</style>
12+
</head>
13+
<body>
14+
<h1>An error occurred.</h1>
15+
</body>
16+
</html>

config/nginx/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
</body>
5+
</html>

config/nginx/nginx.conf

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
worker_processes 1;
2+
error_log stderr warn;
3+
pid /run/nginx.pid;
4+
5+
events {
6+
use epoll;
7+
worker_connections 1024;
8+
multi_accept on;
9+
}
10+
11+
http {
12+
include mime.types;
13+
default_type application/octet-stream;
14+
15+
# Request entity too large fix
16+
client_max_body_size 100M;
17+
18+
log_format main_timed '$remote_addr - $remote_user [$time_local] "$request" '
19+
'$status $body_bytes_sent "$http_referer" '
20+
'"$http_user_agent" "$http_x_forwarded_for" '
21+
'$request_time $upstream_response_time $pipe $upstream_cache_status';
22+
23+
access_log /dev/stdout main_timed;
24+
error_log /dev/stderr notice;
25+
26+
keepalive_timeout 65;
27+
28+
# Remove nginx version
29+
server_tokens off;
30+
31+
# BREACH vulnerability fix
32+
gzip off;
33+
34+
# BEAST vulearbility fix
35+
ssl_protocols TLSv1.2;
36+
37+
# Enable optional HSTS
38+
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
39+
40+
# X-Frame-Options Protection
41+
add_header X-Frame-Options "SAMEORIGIN";
42+
43+
# X-XSS-Protection
44+
add_header X-XSS-Protection "1; mode=block";
45+
46+
# X-Content-Type-Options
47+
add_header X-Content-Type-Options nosniff;
48+
49+
# Secure cookie flag
50+
add_header Set-Cookie "Path=/; HttpOnly; Secure";
51+
52+
server {
53+
listen [::]:80 default_server;
54+
listen 80 default_server;
55+
server_name _;
56+
57+
sendfile off;
58+
59+
root /var/www/html/web;
60+
index index.php;
61+
62+
location / {
63+
try_files $uri $uri/ /index.php?$args;
64+
}
65+
66+
# redirect server error pages to the static page /50x.html
67+
#
68+
error_page 500 502 503 504 /50x.html;
69+
location = /50x.html {
70+
#root /var/lib/nginx/html;
71+
root /var/www/localhost/htdocs;
72+
}
73+
74+
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
75+
#
76+
location ~ \.php$ {
77+
try_files $uri =404;
78+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
79+
fastcgi_pass 127.0.0.1:9000;
80+
fastcgi_index index.php;
81+
fastcgi_read_timeout 300s;
82+
include fastcgi_params;
83+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
84+
fastcgi_param PATH_INFO $fastcgi_path_info;
85+
}
86+
87+
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
88+
expires 5d;
89+
}
90+
91+
# deny access to . files, for security
92+
location ~ /\.(?!well-known).* {
93+
deny all;
94+
access_log off;
95+
log_not_found off;
96+
}
97+
98+
# allow fpm ping and status from localhost
99+
#
100+
location ~ ^/(fpm-status|fpm-ping)$ {
101+
access_log off;
102+
allow 127.0.0.1;
103+
deny all;
104+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
105+
include fastcgi_params;
106+
fastcgi_pass 127.0.0.1:9000;
107+
}
108+
}
109+
}

config/supervisord.conf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[supervisord]
2+
nodaemon=true
3+
logfile=/dev/null
4+
logfile_maxbytes=0
5+
pidfile=/run/supervisord.pid
6+
7+
[program:php-fpm]
8+
command=php-fpm -F
9+
stdout_logfile=/dev/stdout
10+
stdout_logfile_maxbytes=0
11+
stderr_logfile=/dev/stderr
12+
stderr_logfile_maxbytes=0
13+
autorestart=false
14+
startretries=0
15+
16+
[program:nginx]
17+
command=nginx -g 'daemon off;'
18+
stdout_logfile=/dev/stdout
19+
stdout_logfile_maxbytes=0
20+
stderr_logfile=/dev/stderr
21+
stderr_logfile_maxbytes=0
22+
autorestart=false
23+
startretries=0

docker-compose.yaml

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ services:
1414
mysql:
1515
container_name: ${PROJECT_NAME}__mysql
1616
image: mysql:8.0
17-
restart: always
17+
restart: unless-stopped
1818
env_file: .env.mysql
1919
ports:
2020
- ${PORT_MYSQL}:3306
2121
volumes:
22-
- ./mysql/data:/var/lib/mysql
23-
- ./mysql/low-memory-mysql-8.cnf:/etc/mysql/conf.d/low-memory-my.cnf
22+
- ./volumes/mysql-data:/var/lib/mysql
23+
- ./config/low-memory-mysql-8.cnf:/etc/mysql/conf.d/low-memory-my.cnf
2424
networks:
2525
- internal
2626

@@ -42,47 +42,31 @@ services:
4242
wordpress:
4343
container_name: ${PROJECT_NAME}__wordpress
4444
build:
45-
context: ./wordpress/
45+
context: .
4646
env_file: .env.wordpress
47-
restart: always
47+
environment:
48+
- PROJECT_NAME=${PROJECT_NAME}
49+
restart: unless-stopped
4850
volumes:
4951
- "${VOLUME}:/var/www/html"
50-
- ./uploads:/var/www/html/web/app/uploads
52+
- ./volumes/uploads:/var/www/html/web/app/uploads
5153
depends_on:
5254
- mysql
5355
networks:
5456
- internal
5557
- web
56-
57-
nginx:
58-
container_name: ${PROJECT_NAME}__nginx
59-
build:
60-
context: ./nginx/
6158
ports:
6259
- ${PORT_NGINX}:80
63-
volumes:
64-
- "${VOLUME}:/var/www/html"
65-
- ./uploads:/var/www/html/web/app/uploads
66-
- ./nginx/templates:/etc/nginx/templates
67-
restart: always
68-
environment:
69-
- PROJECT_NAME=${PROJECT_NAME}
70-
depends_on:
71-
- wordpress
72-
- mysql
7360
labels:
7461
- traefik.http.routers.${PROJECT_NAME}__nginx.rule=Host(`${HOST_WORDPRESS}`)
7562
- traefik.http.routers.${PROJECT_NAME}__nginx.tls=true
7663
- traefik.http.routers.${PROJECT_NAME}__nginx.tls.certresolver=lets-encrypt
7764
- traefik.port=${PORT_NGINX}
78-
networks:
79-
- internal
80-
- web
8165

8266
adminer:
8367
container_name: ${PROJECT_NAME}__adminer
8468
image: adminer:latest
85-
restart: always
69+
restart: unless-stopped
8670
environment:
8771
ADMINER_DEFAULT_SERVER: ${PROJECT_NAME}__mysql
8872
ports:
@@ -104,7 +88,7 @@ services:
10488
backup:
10589
container_name: ${PROJECT_NAME}__backup
10690
image: futurice/docker-volume-backup
107-
restart: always
91+
restart: unless-stopped
10892
env_file:
10993
- .env.backup
11094
volumes:

nginx/Dockerfile

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)