Skip to content

Commit 5fbf849

Browse files
committed
Octane Swoole support/re-write
1 parent 6b3701d commit 5fbf849

File tree

4 files changed

+77
-90
lines changed

4 files changed

+77
-90
lines changed

.github/workflows/docker-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
schedule:
1010
- cron: '15 16 * * *'
1111
push:
12-
branches: [ "master" ]
12+
branches: [ "master", "octane" ]
1313
# Publish semver tags as releases.
1414
tags: [ 'v*.*.*' ]
1515
pull_request:

Dockerfile

Lines changed: 37 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,56 @@
1-
ARG ALPINE_VERSION=3.16
2-
FROM alpine:${ALPINE_VERSION}
3-
LABEL Maintainer="Tim de Pater <[email protected]>"
4-
LABEL Description="Lightweight container with Nginx 1.22 & PHP 8.1 based on Alpine Linux. With Laravel support by @hidde.me"
5-
# Setup document root
1+
ARG BASE_TAG=php8.1-alpine
2+
3+
# https://hub.docker.com/r/phpswoole/swoole
4+
FROM phpswoole/swoole:$BASE_TAG
65
WORKDIR /var/www/html
76

8-
# Install packages and remove default server definition
9-
RUN apk add --no-cache \
10-
curl \
11-
nginx \
12-
redis \
13-
php81 \
14-
php81-ctype \
15-
php81-curl \
16-
php81-dom \
17-
php81-fpm \
18-
php81-gd \
19-
php81-intl \
20-
php81-mbstring \
21-
php81-pdo \
22-
php81-pgsql \
23-
php81-pdo_pgsql \
24-
php81-opcache \
25-
php81-openssl \
26-
php81-phar \
27-
php81-session \
28-
php81-xml \
29-
php81-xmlreader \
30-
php81-xmlwriter \
31-
php81-fileinfo \
32-
php81-simplexml \
33-
php81-tokenizer \
34-
php81-exif \
35-
php81-pcntl \
36-
php81-posix \
37-
php81-redis \
38-
supervisor
39-
# Create symlink so programs depending on `php` still function
40-
RUN ln -s /usr/bin/php81 /usr/bin/php
7+
RUN set -ex \
8+
&& apk update \
9+
&& apk --no-cache add \
10+
supervisor \
11+
nginx \
12+
curl \
13+
libmcrypt-dev \
14+
libxml2-dev \
15+
pcre-dev \
16+
zlib-dev \
17+
autoconf \
18+
oniguruma-dev \
19+
curl-dev \
20+
openssl \
21+
openssl-dev \
22+
freetype-dev \
23+
libjpeg-turbo-dev \
24+
jpeg-dev \
25+
libpng-dev \
26+
imagemagick-dev \
27+
imagemagick \
28+
postgresql \
29+
postgresql-dev \
30+
libzip-dev \
31+
gettext-dev \
32+
libxslt-dev \
33+
libgcrypt-dev \
34+
libxml2 && \
35+
docker-php-ext-enable redis && \
36+
docker-php-ext-install ctype pdo pdo_pgsql pcntl exif && \
37+
rm /var/cache/apk/* && rm -rf /tmp/pear
38+
4139

4240
# Configure nginx
4341
COPY config/nginx.conf /etc/nginx/nginx.conf
4442

45-
# Configure PHP-FPM
46-
COPY config/fpm-pool.conf /etc/php81/php-fpm.d/www.conf
47-
COPY config/php.ini /etc/php81/conf.d/custom.ini
48-
4943
# Configure supervisord
5044
COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
5145

5246
# Make sure files/folders needed by the processes are accessable when they run under the nobody user
5347
RUN chown -R nobody.nobody /var/www/html /run /var/lib/nginx /var/log/nginx
5448

55-
COPY --from=hipages/php-fpm_exporter /php-fpm_exporter /usr/bin/php-fpm_exporter
56-
RUN chmod +x /usr/bin/php-fpm_exporter
57-
5849
# Switch to use a non-root user from here on
5950
USER nobody
6051

6152
# Expose the port nginx is reachable on
6253
EXPOSE 8080
6354

64-
# Expose php-fpm_exporter port
65-
EXPOSE 9253
66-
6755
# Let supervisord start nginx & php-fpm
68-
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
69-
70-
# Configure a healthcheck to validate that everything is up&running
71-
HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:8080/fpm-ping
72-
73-
# Install composer from the official image
74-
COPY --from=composer /usr/bin/composer /usr/bin/composer
56+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

config/nginx.conf

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ events {
66
worker_connections 1024;
77
}
88

9+
910
http {
1011
include mime.types;
1112
default_type application/octet-stream;
@@ -28,6 +29,11 @@ http {
2829
uwsgi_temp_path /tmp/uwsgi_temp;
2930
scgi_temp_path /tmp/scgi_temp;
3031

32+
map $http_upgrade $connection_upgrade {
33+
default upgrade;
34+
'' close;
35+
}
36+
3137
# Default server definition
3238
server {
3339
listen [::]:8080 default_server;
@@ -41,10 +47,12 @@ http {
4147
root /var/www/html/public;
4248
index index.php index.html;
4349

50+
location /index.php {
51+
try_files /not_exists @octane;
52+
}
53+
4454
location / {
45-
# First attempt to serve request as file, then
46-
# as directory, then fall back to index.php
47-
try_files $uri $uri/ /index.php?q=$uri&$args;
55+
try_files $uri $uri/ @octane;
4856
}
4957

5058
# Redirect server error pages to the static page /50x.html
@@ -53,17 +61,32 @@ http {
5361
root /var/lib/nginx/html;
5462
}
5563

64+
location = /favicon.ico { access_log off; log_not_found off; }
65+
location = /robots.txt { access_log off; log_not_found off; }
66+
67+
68+
error_page 404 /index.php;
69+
5670
client_max_body_size 100M;
5771

5872
# Pass the PHP scripts to PHP-FPM listening on php-fpm.sock
59-
location ~ \.php$ {
60-
try_files $uri =404;
61-
fastcgi_split_path_info ^(.+\.php)(/.+)$;
62-
fastcgi_pass unix:/run/php-fpm.sock;
63-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
64-
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
65-
fastcgi_index index.php;
66-
include fastcgi_params;
73+
location @octane {
74+
set $suffix "";
75+
76+
if ($uri = /index.php) {
77+
set $suffix ?$query_string;
78+
}
79+
80+
proxy_http_version 1.1;
81+
proxy_set_header Host $http_host;
82+
proxy_set_header Scheme $scheme;
83+
proxy_set_header SERVER_PORT $server_port;
84+
proxy_set_header REMOTE_ADDR $remote_addr;
85+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
86+
proxy_set_header Upgrade $http_upgrade;
87+
proxy_set_header Connection $connection_upgrade;
88+
89+
proxy_pass http://127.0.0.1:8000$suffix;
6790
}
6891

6992
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
@@ -77,28 +100,19 @@ http {
77100
deny all;
78101
}
79102

80-
# Allow fpm ping and status from localhost
81-
location ~ ^/(fpm-status|fpm-ping)$ {
82-
access_log off;
83-
allow 127.0.0.1;
84-
deny all;
85-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
86-
include fastcgi_params;
87-
fastcgi_pass unix:/run/php-fpm.sock;
88-
}
89103
}
90-
104+
91105
# Hardening
92106
proxy_hide_header X-Powered-By;
93107
fastcgi_hide_header X-Powered-By;
94108
server_tokens off;
95-
109+
96110
gzip on;
97111
gzip_proxied any;
98112
gzip_types text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss;
99113
gzip_vary on;
100114
gzip_disable "msie6";
101-
115+
102116
# Include other server configs
103117
include /etc/nginx/conf.d/*.conf;
104118
}

config/supervisord.conf

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ logfile=/dev/null
44
logfile_maxbytes=0
55
pidfile=/run/supervisord.pid
66

7-
[program:php-fpm]
8-
command=php-fpm81 -F
7+
[program:octane]
8+
command=php -d variables_order=EGPCS artisan octane:start --server=swoole --host=0.0.0.0 --port=8000
99
stdout_logfile=/dev/stdout
1010
stdout_logfile_maxbytes=0
1111
stderr_logfile=/dev/stderr
@@ -21,12 +21,3 @@ stderr_logfile=/dev/stderr
2121
stderr_logfile_maxbytes=0
2222
autorestart=false
2323
startretries=0
24-
25-
[program:php-fpm_exporter]
26-
command=php-fpm_exporter server --phpfpm.fix-process-count true --phpfpm.scrape-uri unix:///run/php-fpm.sock;/fpm-status
27-
stdout_logfile=/dev/stdout
28-
stdout_logfile_maxbytes=0
29-
stderr_logfile=/dev/stderr
30-
stderr_logfile_maxbytes=0
31-
autorestart=false
32-
startretries=0

0 commit comments

Comments
 (0)