Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nginx #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
FROM python:3.7
MAINTAINER Zach White <[email protected]>
EXPOSE 5001
EXPOSE 8080

WORKDIR /qmk_api
COPY . /qmk_api
RUN pip3 install -r requirements.txt git+git://github.com/qmk/qmk_compiler.git@master git+git://github.com/skullydazed/kle2xy.git@master
RUN apt-get update
RUN apt-get install -y nginx
COPY nginx.conf /etc/nginx/nginx.conf
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
CMD ./run
8 changes: 8 additions & 0 deletions html/4xx.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>QMK</title>
</head>
<body>
<p>Not Found / Request Error</p>
</body>
</html>
75 changes: 75 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
worker_processes 1;

#user nobody nogroup;
# 'user nobody nobody;' for systems with 'nobody' as a group instead
error_log stderr info;
pid /var/run/nginx.pid;

events {
worker_connections 1024; # increase if you have lots of clients
accept_mutex off; # set to 'on' if nginx worker_processes > 1
# 'use epoll;' to enable for Linux 2.6+
}

http {
include mime.types;
# fallback in case we can't determine a type
default_type application/octet-stream;
access_log /dev/stdout combined;
sendfile on;

upstream app_server {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response

# for a TCP configuration
server 127.0.0.1:5001 fail_timeout=0;
}

root /qmk_api/html;

#server {
# # if no Host match, close the connection to prevent host spoofing
# listen 80 default_server;
# return 444;
#}

server {
# use 'listen 80 deferred;' for Linux
# use 'listen 80 accept_filter=httpready;' for FreeBSD
listen 8080;
client_max_body_size 40M;

# set the correct host(s) for your site
server_name build-qmk.chonkerkeys.com;

keepalive_timeout 5;

location = / {
try_files /___sure_notfound___/$uri @app_proxy;
}

location = /v1 {
try_files /___sure_notfound___/$uri @app_proxy;
}

location ~ /v1/(healthcheck|compile|converters|keyboards|metrics|skeletons|telemetry|usb) {
try_files /___sure_notfound___/$uri @app_proxy;
}

location @app_proxy {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
# we don't want nginx trying to do something clever with
# redirects, we set the Host: header above already.
proxy_redirect off;
proxy_pass http://app_server;
}

error_page 400 401 402 403 404 405 406 /4xx.html;
location = /4xx.html {
internal;
}
}
}
2 changes: 2 additions & 0 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ if [ -e /qmk_compiler ]; then
pip3 install --editable /qmk_compiler || exit
fi

service nginx start

exec gunicorn --access-logfile $ACCESS_LOGFILE --log-level $LOG_LEVEL -w $NUM_WORKERS -b 0.0.0.0:$QMK_API_PORT --max-requests $MAX_REQUESTS --max-requests-jitter $MAX_REQUESTS_JITTER -t $TIMEOUT $RELOAD web:app
13 changes: 9 additions & 4 deletions web.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from os import stat, remove, makedirs, environ
from time import strftime, time, localtime

from botocore.exceptions import ClientError
import graphyte
import requests
from flask import jsonify, Flask, redirect, request, send_file
Expand Down Expand Up @@ -530,15 +531,19 @@ def GET_v1_compile_job_id(job_id):
'created_at': job.created_at,
'enqueued_at': job.enqueued_at,
'id': job.id,
'is_failed': job.is_failed or (job.result and job.result.get('returncode') != 0),
'is_failed': job.is_failed,
'status': status,
'result': job.result,
})

# Check for cached json if it's not in redis
job = get_job_metadata(job_id)
if job:
return jsonify(job)
try:
job = get_job_metadata(job_id)
if job:
return jsonify(job)
except ClientError as ex:
if ex.response['Error']['Code'] != 'NoSuchKey':
raise

# Couldn't find it
return error("Compile job not found", 404)
Expand Down