FROM ubuntu:18.04
MAINTAINER Stefano Alberto Russo <stefano.russo@gmail.com>

#----------------------
# Basics
#----------------------

# Set non-interactive
ENV DEBIAN_FRONTEND noninteractive

# Update
RUN apt-get update

# Utilities
RUN apt-get install -y nano telnet unzip wget openssh-server sudo curl

# Devel
RUN apt-get install -y build-essential python-dev git-core

# Download get-pip script
RUN curl -O https://bootstrap.pypa.io/get-pip.py

# Install Python3 and Pip3 (python3-distutils required for pip3)
RUN apt-get install python3 python3-distutils -y 

# Install Python3 and Pip3 (python3-distutils required for pip3)
# Fix pip version to avoid future issues.
RUN apt-get install python3 python3-distutils -y 
RUN python3 get-pip.py 'pip==21.0.1'

# Python 3 dev (for pycrypto)
RUN apt-get install python3-dev -y

# Install postgres driver required for psycopg2
RUN apt-get install libpq-dev -y


#------------------------
# Esap user
#------------------------

# Add group. We chose GID 65527 to try avoiding conflicts.
RUN groupadd -g 65527 esap

# Add user. We chose UID 65527 to try avoiding conflicts.
RUN useradd esap -d /esap -u 65527 -g 65527 -m -s /bin/bash

# Add esap user to sudoers
RUN adduser esap sudo

# No pass sudo (for everyone, actually)
COPY sudoers /etc/sudoers


#------------------------
# Code
#------------------------

COPY esap-api-gateway /opt/esap-api-gateway
RUN chown -R esap:esap /opt/esap-api-gateway


#------------------------
# Dependencies
#------------------------

RUN pip3 install -r /opt/esap-api-gateway/esap/requirements/prod.txt
RUN pip3 install uwsgi==2.0.19.1


#----------------------
# Entrypoint
#----------------------

COPY run_api-gateway.sh /run_api-gateway.sh
COPY entrypoint.sh /entrypoint.sh
RUN chmod 755 /entrypoint.sh /run_api-gateway.sh

USER esap
ENTRYPOINT ["/entrypoint.sh"]
