Skip to content

Commit

Permalink
Merge pull request #171 from persephone-tools/deployment-nginx
Browse files Browse the repository at this point in the history
[WIP] Use nginx to serve the API
  • Loading branch information
shuttle1987 authored Mar 6, 2019
2 parents dc1220b + 40beafb commit a927d61
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 8 deletions.
25 changes: 18 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ RUN apt-get update -y && apt-get -y install \
python3-pip \
ffmpeg \
sox \
git
git \
nginx \
supervisor

# -- Install Application into container:
RUN mkdir /app
WORKDIR /app

# -- Install uWSGI and pipenv
RUN pip3 install uwsgi
RUN pip3 install pipenv

# -- Adding Pipfiles
Expand All @@ -24,10 +25,20 @@ COPY Pipfile.lock Pipfile.lock
# -- Install dependencies:
RUN pipenv install --deploy --system

# -- Install Application into container:
RUN mkdir /app
WORKDIR /app

# -- Set up configuration files
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
COPY nginx-app.conf /etc/nginx/sites-available/default
COPY supervisor-app.conf /etc/supervisor/conf.d/

COPY . /app

EXPOSE 8080
# -- Create supervisor log directory
RUN mkdir -p /var/log/supervisord/

ENTRYPOINT [ "python3" ]
EXPOSE 8080

CMD [ "transcription_API_server.py" ]
CMD [ "supervisord", "-c", "/etc/supervisor/conf.d/supervisor-app.conf", "-n" ]
31 changes: 31 additions & 0 deletions nginx-app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# nginx-app.conf

# the upstream component nginx needs to connect to
upstream api {
server 127.0.0.1:8080;
}

# configuration of the server
server {
# the port your site will be served on, default_server indicates that this server block
# is the block to use if no blocks match the server_name
listen 8080 default_server;

# the domain name it will serve for
server_name .example.com; # substitute your machine's IP address or FQDN
charset utf-8;

# max upload size
client_max_body_size 100M;

# uploads
location /uploads {
alias /home/docker/volatile/uploads;
}

# Finally, send all non-media requests to the API server.
location / {
uwsgi_pass unix:///tmp/uwsgi.sock;
include uwsgi_params;
}
}
17 changes: 17 additions & 0 deletions supervisor-app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[supervisord]
logfile=/var/log/supervisord/supervisord.log ; supervisord log file
logfile_maxbytes=50MB ; maximum size of logfile before rotation
logfile_backups=10 ; number of backed up logfiles
loglevel=info ; info, debug, warn, trace
user = root

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket

[program:app-uwsgi]
command = /usr/local/bin/uwsgi --ini /app/uwsgi.ini
priority=1

[program:nginx-app]
command = /usr/sbin/nginx
priority=2
5 changes: 4 additions & 1 deletion transcription_API_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

app = create_app(DevConfig)


base_file_path = os.getcwd()

@app.route('/')
def index():
return """Access to the API is via the API versioned path prefix
Expand All @@ -21,7 +24,7 @@ def index():

# persephone paths
# Persephone related files stored here
app.config['FILE_STORAGE_BASE'] = os.path.join(os.getcwd(), 'persephone_file_storage')
app.config['FILE_STORAGE_BASE'] = os.path.join(base_file_path, 'persephone_file_storage')
# Corpus directories stored here
app.config['CORPUS_PATH'] = os.path.join(app.config['FILE_STORAGE_BASE'], 'corpus')
if os.path.isdir(app.config['CORPUS_PATH']):
Expand Down
18 changes: 18 additions & 0 deletions uwsgi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[uwsgi]
# this config will be loaded if nothing specific is specified
# load base config from below
ini = :base

socket = /tmp/uwsgi.sock
chmod-socket = 777
master = true
processes = 4

[local]
http = :8080

[base]
# chdir to the folder this config file resides in
# %d is the dir this configuration file is in
chdir=%d
module=transcription_API_server:app

0 comments on commit a927d61

Please sign in to comment.