FROM ubuntu:18.10

# To fix "configuring tzdata" interactive input during apt install
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install -yq --no-install-recommends \
    apache2 \
    libapache2-mod-php7.2 \
    php7.2-xml \
    php7.2-mbstring \
    php-mysql \
    php-curl \
    libapache2-mod-shib2 \
    make \
    wget \
    ca-certificates \
    ssl-cert \
    vim

# Copying Shibboleth SP configuration
COPY docker/shibboleth/shibboleth2.xml /etc/shibboleth/
COPY docker/shibboleth/sp-key.pem /etc/shibboleth/
COPY docker/shibboleth/sp-cert.pem /etc/shibboleth/
    
# Installing Embedded Discovery Service
WORKDIR /usr/local/src

RUN wget https://shibboleth.net/downloads/embedded-discovery-service/1.2.1/shibboleth-embedded-ds-1.2.1.tar.gz -O shibboleth-eds.tar.gz
RUN tar xzf shibboleth-eds.tar.gz

WORKDIR shibboleth-embedded-ds-1.2.1
RUN make install

RUN mv /etc/shibboleth-ds/shibboleth-ds.conf /etc/apache2/conf-available/shibboleth-ds.conf
RUN sed -i 's/Allow from All/Require all granted/g' /etc/apache2/conf-available/shibboleth-ds.conf
RUN a2enconf shibboleth-ds.conf

# Adding RAP Apache configuration
COPY docker/rap.conf /etc/apache2/conf-available/
RUN a2enconf rap.conf

# Enable mod_rewrite (for Flight framework)
RUN a2enmod rewrite
RUN a2enmod ssl
RUN a2ensite default-ssl

# Copying RAP php files
WORKDIR /var/www/html
COPY . rap-ia2

WORKDIR /var/www/html/rap-ia2
RUN mkdir -p logs
RUN chown -R www-data logs

# Starting shibd & Apache
CMD service shibd start && apachectl -D FOREGROUND
