Skip to content

Commit

Permalink
Add supervisor + nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
willemarcel committed Oct 31, 2023
1 parent e000fb3 commit 90b8fc9
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 9 deletions.
34 changes: 26 additions & 8 deletions images/osmcha-web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update -y -qq && \
apt-get install -y curl python3 \
python3-dev python3-pip git libgeos-dev \
RUN apt-get update -y -qq
RUN apt-get install -y curl python3 python3-dev \
python3-pip git libgeos-dev libyaml-dev \
libcurl4-gnutls-dev librtmp-dev python3-gdal \
libyaml-dev locales yarnpkg nodejs npm && \
locale-gen en_US.UTF-8 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
locales nginx supervisor yarnpkg nodejs npm
RUN locale-gen en_US.UTF-8
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/*

# Install yarn.
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -y
RUN apt-get remove -y yarnpkg cmdtest && apt-get install -y yarn && apt-get clean && rm -rf /var/lib/apt/lists/*

# Setup nginx
RUN rm /etc/nginx/sites-enabled/default
COPY django.conf /etc/nginx/sites-available/
RUN ln -s /etc/nginx/sites-available/django.conf /etc/nginx/sites-enabled/django.conf
RUN echo "daemon off;" >> /etc/nginx/nginx.conf


# Setting locale is required by unicode-slugify (osmcha-django python requirement)
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en

WORKDIR /app
ENV BACKEND_VERSION feature/osm-server-config
ENV BACKEND_VERSION v4.19.0
RUN git clone https://github.com/willemarcel/osmcha-django .
RUN git checkout $BACKEND_VERSION
RUN git pull origin $BACKEND_VERSION
RUN pip3 install -r requirements/production.txt
RUN pip3 install -r requirements/local.txt

ADD . /app
ENV DJANGO_ROOT /app
ENV DJANGO_SETTINGS_MODULE config.settings.aws_production

# Replace social-auth-core by a modified version that provides OHM authentication
RUN pip3 install git+https://github.com/OpenHistoricalMap/social-core.git@master

Expand All @@ -44,5 +55,12 @@ RUN cd /osmcha-frontend && yarn install
RUN echo "alias python=python3" >> ~/.bashrc
RUN echo "alias pip=pip3" >> ~/.bashrc

EXPOSE 80

# Supervisor config
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY gunicorn.conf /etc/supervisor/conf.d/gunicorn.conf

COPY ./start.sh .
CMD ./start.sh
31 changes: 31 additions & 0 deletions images/osmcha-web/django.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
server {
listen 80;
charset utf-8;
client_max_body_size 20M;

location /static/ {
gzip_static on;
alias /app/staticfiles/;
}

location /index.html {
gzip_static on;
alias /app/osmchadjango/frontend/templates/frontend/index.html;
}

location / {
# checks for static file, if not found proxy to app
try_files $uri @proxy_to_app;
}

# cookiecutter-django app
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:5000;
fastcgi_connect_timeout 130;
fastcgi_send_timeout 130;
fastcgi_read_timeout 130;
}
}
6 changes: 6 additions & 0 deletions images/osmcha-web/gunicorn.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[program:gunicorn]
command=/usr/local/bin/gunicorn config.wsgi -b localhost:5000 -w 4 --log-file /var/log/gunicorn.error --access-logfile /var/log/gunicorn.access --capture-output --timeout 120
directory=/app
autostart=true
autorestart=true
redirect_stderr=true
2 changes: 1 addition & 1 deletion images/osmcha-web/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ cp -R build/static/* /app/osmchadjango/static/
cd /app
python3 manage.py collectstatic --noinput
python3 manage.py migrate
python3 manage.py runserver 0.0.0.0:8000
supervisord -c /etc/supervisor/supervisord.conf
5 changes: 5 additions & 0 deletions images/osmcha-web/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[supervisord]
nodaemon=true

[program:nginx]
command=/usr/sbin/nginx

0 comments on commit 90b8fc9

Please sign in to comment.