FROM base AS web

WORKDIR /code

RUN apk update && apk add nginx && apk add supervisor

COPY requirements/base.txt .
COPY requirements/production.txt .
COPY requirements/web.txt .

RUN pip install -r production.txt
RUN pip install -r web.txt

RUN rm -f /etc/nginx/sites-enabled/default
RUN rm -f /etc/nginx/conf.d/default.conf
COPY ./services/web/nginx.conf /etc/nginx/nginx.conf
COPY ./services/web/geeksbot.conf /etc/nginx/sites-enabled/geeksbot
COPY ./services/web/gunicorn.conf /etc/gunicorn.conf
COPY ./services/web/supervisord.conf /etc/supervisor/supervisord.conf
COPY ./services/web/supervisor_geeksbot.conf /etc/supervisor/conf.d/geeksbot.conf
COPY ./ssl_certs/geeksbot_app/geeksbot_app_cert_chain.crt /etc/ssl/geeksbot_app_cert_chain.crt
COPY ./ssl_certs/geeksbot_app/geeksbot.app.key /etc/ssl/geeksbot.app.key

RUN rm -rf /tmp/*

RUN mkdir -p /tmp/logs/nginx
RUN mkdir -p /tmp/logs/geeksbot

COPY manage.py .
copy entrypoint .
RUN sed -i 's/\r$//g' /code/entrypoint
RUN chmod +x /code/entrypoint

EXPOSE 80 8000 443

ENTRYPOINT [ "/code/entrypoint" ]
