Skip to content

Commit 9dbf9ab

Browse files
author
a21ns1g4ts
committed
Add nixpacks
1 parent 7a51fca commit 9dbf9ab

File tree

1 file changed

+293
-0
lines changed

1 file changed

+293
-0
lines changed

nixpacks.toml

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
[packages]
2+
php = "8.3"
3+
composer = "*"
4+
nodejs = "22"
5+
6+
[phases.setup]
7+
nixPkgs = ["php83", "php83Packages.composer", "nodejs-18_x", "python311Packages.supervisor", "nginx", "php83Extensions.redis", "php83Extensions.pdo_pgsql", "php83Extensions.bcmath", "php83Extensions.gd", "php83Extensions.zip", "php83Extensions.intl", "php83Extensions.opcache", "php83Extensions.pcntl", "php83Extensions.exif", "php83Extensions.ftp"]
8+
9+
[phases.install]
10+
cmds = ["npm ci"]
11+
12+
[phases.build]
13+
cmds = [
14+
"composer install --no-dev --optimize-autoloader --no-scripts",
15+
"npm run build",
16+
"composer dump-autoload --optimize",
17+
"mkdir -p /etc/supervisor/conf.d/",
18+
"cp /assets/worker-*.conf /etc/supervisor/conf.d/",
19+
"cp /assets/supervisord.conf /etc/supervisord.conf",
20+
"chmod +x /assets/start.sh"
21+
]
22+
23+
[start]
24+
cmd = '/assets/start.sh'
25+
26+
[staticAssets]
27+
"start.sh" = '''
28+
#!/bin/bash
29+
mkdir -p /var/log/nginx
30+
mkdir -p /var/lib/nginx/body
31+
touch /var/log/nginx-access.log
32+
touch /var/log/nginx-error.log
33+
34+
# Copy config and replace PORT
35+
cp /assets/nginx.template.conf /etc/nginx.conf
36+
sed -i "s/PORT_PLACEHOLDER/${PORT:-80}/g" /etc/nginx.conf
37+
38+
# Start supervisor
39+
supervisord -c /etc/supervisord.conf -n
40+
'''
41+
42+
"supervisord.conf" = '''
43+
[unix_http_server]
44+
file=/assets/supervisor.sock
45+
46+
[supervisord]
47+
logfile=/var/log/supervisord.log
48+
logfile_maxbytes=50MB
49+
logfile_backups=10
50+
loglevel=info
51+
pidfile=/assets/supervisord.pid
52+
nodaemon=false
53+
silent=false
54+
minfds=1024
55+
minprocs=200
56+
57+
[rpcinterface:supervisor]
58+
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
59+
60+
[supervisorctl]
61+
serverurl=unix:///assets/supervisor.sock
62+
63+
[include]
64+
files = /etc/supervisor/conf.d/*.conf
65+
'''
66+
67+
"worker-nginx.conf" = '''
68+
[program:worker-nginx]
69+
process_name=%(program_name)s_%(process_num)02d
70+
command=nginx -c /etc/nginx.conf
71+
autostart=true
72+
autorestart=true
73+
stdout_logfile=/var/log/worker-nginx.log
74+
stderr_logfile=/var/log/worker-nginx.log
75+
'''
76+
77+
"worker-phpfpm.conf" = '''
78+
[program:worker-phpfpm]
79+
process_name=%(program_name)s_%(process_num)02d
80+
command=php-fpm -y /assets/php-fpm.conf -F -R
81+
autostart=true
82+
autorestart=true
83+
stdout_logfile=/var/log/worker-phpfpm.log
84+
stderr_logfile=/var/log/worker-phpfpm.log
85+
'''
86+
87+
"worker-laravel.conf" = '''
88+
[program:worker-laravel]
89+
process_name=%(program_name)s_%(process_num)02d
90+
command=bash -c 'exec php /app/artisan queue:work --sleep=3 --tries=3 --max-time=3600'
91+
autostart=true
92+
autorestart=true
93+
stopasgroup=true
94+
killasgroup=true
95+
numprocs=2
96+
startsecs=1
97+
stopwaitsecs=3600
98+
stdout_logfile=/var/log/worker-laravel.log
99+
stderr_logfile=/var/log/worker-laravel.log
100+
'''
101+
102+
"php-fpm.conf" = '''
103+
[global]
104+
error_log = /proc/self/fd/2
105+
106+
[www]
107+
listen = 127.0.0.1:9000
108+
pm = dynamic
109+
pm.max_children = 40 ; Aumentado para 40 (Utiliza ~3GB de RAM, seguro para 12GB)
110+
pm.min_spare_servers = 10 ; Aumentado para evitar cold starts
111+
pm.max_spare_servers = 30 ; Aumentado
112+
pm.start_servers = 20 ; Aumentado para start mais rápido
113+
clear_env = no
114+
php_admin_value[post_max_size] = 35M
115+
php_admin_value[upload_max_filesize] = 30M
116+
117+
; ----------------------------------------------------
118+
; ** OTIMIZAÇÃO CRÍTICA: PHP OPCACHE (RESOLVE O TTFB) **
119+
; ----------------------------------------------------
120+
php_admin_flag[opcache.enable] = on
121+
php_admin_value[opcache.memory_consumption] = 256 ; Uso generoso de 256MB de RAM para cache
122+
php_admin_value[opcache.max_accelerated_files] = 20000
123+
php_admin_value[opcache.validate_timestamps] = 0 ; Desempenho máximo: Não verifica se o arquivo mudou.
124+
php_admin_value[opcache.revalidate_freq] = 0 ; Só deve ser alterado após o deploy.
125+
'''
126+
127+
"nginx.template.conf" = '''
128+
worker_processes 5;
129+
daemon off;
130+
worker_rlimit_nofile 8192;
131+
pid /var/lib/nginx/nginx.pid;
132+
133+
events {
134+
worker_connections 4096;
135+
}
136+
137+
http {
138+
include /assets/mime.types;
139+
index index.html index.htm index.php;
140+
141+
default_type application/octet-stream;
142+
log_format main '$remote_addr - $remote_user [$time_local] $status '
143+
'"$request" $body_bytes_sent "$http_referer" '
144+
'"$http_user_agent" "$http_x_forwarded_for"';
145+
access_log /var/log/nginx-access.log;
146+
error_log /var/log/nginx-error.log;
147+
sendfile on;
148+
tcp_nopush on;
149+
server_names_hash_bucket_size 128;
150+
151+
client_body_temp_path /var/lib/nginx/body;
152+
proxy_temp_path /var/lib/nginx/proxy;
153+
fastcgi_temp_path /var/lib/nginx/fastcgi;
154+
uwsgi_temp_path /var/lib/nginx/uwsgi;
155+
scgi_temp_path /var/lib/nginx/scgi;
156+
157+
server {
158+
listen PORT_PLACEHOLDER;
159+
listen [::]:PORT_PLACEHOLDER;
160+
server_name localhost;
161+
root /app/public;
162+
163+
add_header X-Content-Type-Options "nosniff";
164+
client_max_body_size 35M;
165+
index index.php;
166+
charset utf-8;
167+
168+
location / {
169+
try_files $uri $uri/ /index.php?$query_string;
170+
}
171+
172+
location = /favicon.ico { access_log off; log_not_found off; }
173+
location = /robots.txt { access_log off; log_not_found off; }
174+
175+
error_page 404 /index.php;
176+
177+
location ~ \.php$ {
178+
fastcgi_pass 127.0.0.1:9000;
179+
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
180+
include /assets/fastcgi_params;
181+
}
182+
183+
location ~ /\.(?!well-known).* {
184+
deny all;
185+
}
186+
}
187+
}
188+
'''
189+
190+
"mime.types" = '''
191+
types {
192+
text/html html htm shtml;
193+
text/css css;
194+
text/xml xml;
195+
image/gif gif;
196+
image/jpeg jpeg jpg;
197+
application/javascript js;
198+
application/atom+xml atom;
199+
application/rss+xml rss;
200+
text/mathml mml;
201+
text/plain txt;
202+
text/vnd.sun.j2me.app-descriptor jad;
203+
text/vnd.wap.wml wml;
204+
text/x-component htc;
205+
image/png png;
206+
image/svg+xml svg svgz;
207+
image/tiff tif tiff;
208+
image/vnd.wap.wbmp wbmp;
209+
image/webp webp;
210+
image/x-icon ico;
211+
image/x-jng jng;
212+
image/x-ms-bmp bmp;
213+
application/font-woff woff;
214+
application/java-archive jar war ear;
215+
application/json json;
216+
application/mac-binhex40 hqx;
217+
application/msword doc;
218+
application/pdf pdf;
219+
application/postscript ps eps ai;
220+
application/rtf rtf;
221+
application/vnd.apple.mpegurl m3u8;
222+
application/vnd.google-earth.kml+xml kml;
223+
application/vnd.google-earth.kmz kmz;
224+
application/vnd.ms-excel xls;
225+
application/vnd.ms-fontobject eot;
226+
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx;
227+
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx;
228+
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx;
229+
application/vnd.wap.wmlc wmlc;
230+
application/x-7z-compressed 7z;
231+
application/x-cocoa cco;
232+
application/x-java-archive-diff jardiff;
233+
application/x-java-jnlp-file jnlp;
234+
application/x-makeself run;
235+
application/x-perl pl pm;
236+
application/x-pilot prc pdb;
237+
application/x-rar-compressed rar;
238+
application/x-redhat-package-manager rpm;
239+
application/x-sea sea;
240+
application/x-shockwave-flash swf;
241+
application/x-stuffit sit;
242+
application/x-tcl tcl tk;
243+
application/x-x509-ca-cert der pem crt;
244+
application/x-xpinstall xpi;
245+
application/xhtml+xml xhtml;
246+
application/xspf+xml xspf;
247+
application/zip zip;
248+
application/octet-stream bin exe dll;
249+
application/octet-stream deb;
250+
application/octet-stream dmg;
251+
application/octet-stream iso img;
252+
application/octet-stream msi msp msm;
253+
audio/midi mid midi kar;
254+
audio/mpeg mp3;
255+
audio/ogg ogg;
256+
audio/x-m4a m4a;
257+
audio/x-realaudio ra;
258+
video/3gpp 3gpp 3gp;
259+
video/mp2t ts;
260+
video/mp4 mp4;
261+
video/mpeg mpeg mpg;
262+
video/quicktime mov;
263+
video/webm webm;
264+
video/x-flv flv;
265+
video/x-m4v m4v;
266+
video/x-mng mng;
267+
video/x-ms-asf asx asf;
268+
video/x-ms-wmv wmv;
269+
video/x-msvideo avi;
270+
}
271+
'''
272+
273+
"fastcgi_params" = '''
274+
fastcgi_param QUERY_STRING $query_string;
275+
fastcgi_param REQUEST_METHOD $request_method;
276+
fastcgi_param CONTENT_TYPE $content_type;
277+
fastcgi_param CONTENT_LENGTH $content_length;
278+
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
279+
fastcgi_param REQUEST_URI $request_uri;
280+
fastcgi_param DOCUMENT_URI $document_uri;
281+
fastcgi_param DOCUMENT_ROOT $document_root;
282+
fastcgi_param SERVER_PROTOCOL $server_protocol;
283+
fastcgi_param REQUEST_SCHEME $scheme;
284+
fastcgi_param HTTPS $https if_not_empty;
285+
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
286+
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
287+
fastcgi_param REMOTE_ADDR $remote_addr;
288+
fastcgi_param REMOTE_PORT $remote_port;
289+
fastcgi_param SERVER_ADDR $server_addr;
290+
fastcgi_param SERVER_PORT $server_port;
291+
fastcgi_param SERVER_NAME $server_name;
292+
fastcgi_param REDIRECT_STATUS 200;
293+
'''

0 commit comments

Comments
 (0)