Skip to content

Commit c1be5cb

Browse files
committed
try to nginxify
1 parent 81c7ee6 commit c1be5cb

File tree

6 files changed

+173
-5
lines changed

6 files changed

+173
-5
lines changed

Dockerfile.cabotage

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM python:3.9-bullseye
2+
COPY --from=ewdurbin/nginx-static:1.25.x /usr/bin/nginx /usr/bin/nginx
23
ENV PYTHONUNBUFFERED=1
34
ENV PYTHONDONTWRITEBYTECODE=1
45
RUN mkdir /code

Procfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
release: python manage.py migrate --noinput
2-
web: gunicorn -c gunicorn.conf pydotorg.wsgi
2+
web: bin/start-nginx gunicorn -c gunicorn.conf pydotorg.wsgi

bin/start-nginx

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
3+
psmgr=/tmp/nginx-buildpack-wait
4+
rm -f $psmgr
5+
mkfifo $psmgr
6+
7+
n=1
8+
while getopts :f option ${@:1:2}
9+
do
10+
case "${option}"
11+
in
12+
f) FORCE=$OPTIND; n=$((n+1));;
13+
esac
14+
done
15+
16+
# Initialize log directory.
17+
mkdir -p /tmp/logs/nginx
18+
touch /tmp/logs/nginx/access.log /tmp/logs/nginx/error.log
19+
echo 'buildpack=nginx at=logs-initialized'
20+
21+
# Start log redirection.
22+
(
23+
# Redirect nginx logs to stdout.
24+
tail -qF -n 0 /tmp/logs/nginx/*.log
25+
echo 'logs' >$psmgr
26+
) &
27+
28+
# Start App Server
29+
(
30+
# Take the command passed to this bin and start it.
31+
# E.g. bin/start-nginx bundle exec unicorn -c config/unicorn.rb
32+
COMMAND=${@:$n}
33+
echo "buildpack=nginx at=start-app cmd=$COMMAND"
34+
$COMMAND
35+
echo 'app' >$psmgr
36+
) &
37+
38+
if [[ -z "$FORCE" ]]
39+
then
40+
FILE="/tmp/app-initialized"
41+
42+
# We block on app-initialized so that when nginx binds to $PORT
43+
# are app is ready for traffic.
44+
while [[ ! -f "$FILE" ]]
45+
do
46+
echo 'buildpack=nginx at=app-initialization'
47+
sleep 1
48+
done
49+
echo 'buildpack=nginx at=app-initialized'
50+
fi
51+
52+
# Start nginx
53+
(
54+
# We expect nginx to run in foreground.
55+
# We also expect a socket to be at /tmp/nginx.socket.
56+
echo 'buildpack=nginx at=nginx-start'
57+
cd /tmp
58+
/usr/bin/nginx -p . -c /code/config/nginx.conf
59+
echo 'nginx' >$psmgr
60+
) &
61+
62+
# This read will block the process waiting on a msg to be put into the fifo.
63+
# If any of the processes defined above should exit,
64+
# a msg will be put into the fifo causing the read operation
65+
# to un-block. The process putting the msg into the fifo
66+
# will use it's process name as a msg so that we can print the offending
67+
# process to stdout.
68+
read exit_process <$psmgr
69+
echo "buildpack=nginx at=exit process=$exit_process"
70+
exit 1

config/mime.types

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
types {
2+
text/html html htm shtml;
3+
text/css css;
4+
text/xml xml;
5+
image/gif gif;
6+
image/jpeg jpeg jpg;
7+
application/javascript js;
8+
application/atom+xml atom;
9+
application/rss+xml rss;
10+
11+
text/mathml mml;
12+
text/plain txt;
13+
text/vnd.sun.j2me.app-descriptor jad;
14+
text/vnd.wap.wml wml;
15+
text/x-component htc;
16+
17+
image/avif avif;
18+
image/png png;
19+
image/svg+xml svg svgz;
20+
image/tiff tif tiff;
21+
image/vnd.wap.wbmp wbmp;
22+
image/webp webp;
23+
image/x-icon ico;
24+
image/x-jng jng;
25+
image/x-ms-bmp bmp;
26+
27+
font/woff woff;
28+
font/woff2 woff2;
29+
30+
application/java-archive jar war ear;
31+
application/json json;
32+
application/mac-binhex40 hqx;
33+
application/msword doc;
34+
application/pdf pdf;
35+
application/postscript ps eps ai;
36+
application/rtf rtf;
37+
application/vnd.apple.mpegurl m3u8;
38+
application/vnd.google-earth.kml+xml kml;
39+
application/vnd.google-earth.kmz kmz;
40+
application/vnd.ms-excel xls;
41+
application/vnd.ms-fontobject eot;
42+
application/vnd.ms-powerpoint ppt;
43+
application/vnd.oasis.opendocument.graphics odg;
44+
application/vnd.oasis.opendocument.presentation odp;
45+
application/vnd.oasis.opendocument.spreadsheet ods;
46+
application/vnd.oasis.opendocument.text odt;
47+
application/vnd.openxmlformats-officedocument.presentationml.presentation
48+
pptx;
49+
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
50+
xlsx;
51+
application/vnd.openxmlformats-officedocument.wordprocessingml.document
52+
docx;
53+
application/vnd.wap.wmlc wmlc;
54+
application/wasm wasm;
55+
application/x-7z-compressed 7z;
56+
application/x-cocoa cco;
57+
application/x-java-archive-diff jardiff;
58+
application/x-java-jnlp-file jnlp;
59+
application/x-makeself run;
60+
application/x-perl pl pm;
61+
application/x-pilot prc pdb;
62+
application/x-rar-compressed rar;
63+
application/x-redhat-package-manager rpm;
64+
application/x-sea sea;
65+
application/x-shockwave-flash swf;
66+
application/x-stuffit sit;
67+
application/x-tcl tcl tk;
68+
application/x-x509-ca-cert der pem crt;
69+
application/x-xpinstall xpi;
70+
application/xhtml+xml xhtml;
71+
application/xspf+xml xspf;
72+
application/zip zip;
73+
74+
application/octet-stream bin exe dll;
75+
application/octet-stream deb;
76+
application/octet-stream dmg;
77+
application/octet-stream iso img;
78+
application/octet-stream msi msp msm;
79+
80+
audio/midi mid midi kar;
81+
audio/mpeg mp3;
82+
audio/ogg ogg;
83+
audio/x-m4a m4a;
84+
audio/x-realaudio ra;
85+
86+
video/3gpp 3gpp 3gp;
87+
video/mp2t ts;
88+
video/mp4 mp4;
89+
video/mpeg mpeg mpg;
90+
video/quicktime mov;
91+
video/webm webm;
92+
video/x-flv flv;
93+
video/x-m4v m4v;
94+
video/x-mng mng;
95+
video/x-ms-asf asx asf;
96+
video/x-ms-wmv wmv;
97+
video/x-msvideo avi;
98+
}

config/nginx.conf.erb config/nginx.conf

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
daemon off;
2-
#Heroku dynos have at least 4 cores.
3-
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;
2+
worker_processes 2;
43

54
events {
65
use epoll;
@@ -33,7 +32,7 @@ http {
3332
}
3433

3534
server {
36-
listen <%= ENV["PORT"] %>;
35+
listen unix:/var/run/cabotage/cabotage.sock;
3736
server_name _;
3837
keepalive_timeout 5;
3938

gunicorn.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
bind = 'unix:/var/run/cabotage/cabotage.sock'
1+
bind = 'unix:/tmp/nginx.sock'
22
backlog = 1024
33
preload_app = True
44
max_requests = 2048

0 commit comments

Comments
 (0)