diff --git a/images/osmcha-web/Dockerfile b/images/osmcha-web/Dockerfile index 1f861267..ae3c6898 100644 --- a/images/osmcha-web/Dockerfile +++ b/images/osmcha-web/Dockerfile @@ -1,14 +1,14 @@ 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 - @@ -16,19 +16,30 @@ RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources 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 @@ -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 diff --git a/images/osmcha-web/django.conf b/images/osmcha-web/django.conf new file mode 100644 index 00000000..ff788d99 --- /dev/null +++ b/images/osmcha-web/django.conf @@ -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; + } +} diff --git a/images/osmcha-web/gunicorn.conf b/images/osmcha-web/gunicorn.conf new file mode 100644 index 00000000..21d99bb7 --- /dev/null +++ b/images/osmcha-web/gunicorn.conf @@ -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 diff --git a/images/osmcha-web/start.sh b/images/osmcha-web/start.sh index 0e396977..b37767e0 100755 --- a/images/osmcha-web/start.sh +++ b/images/osmcha-web/start.sh @@ -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 diff --git a/images/osmcha-web/supervisord.conf b/images/osmcha-web/supervisord.conf new file mode 100644 index 00000000..8d520a8c --- /dev/null +++ b/images/osmcha-web/supervisord.conf @@ -0,0 +1,5 @@ +[supervisord] +nodaemon=true + +[program:nginx] +command=/usr/sbin/nginx