FROM ubuntu:18.04

RUN apt-get update \
    && apt-get install -y software-properties-common language-pack-en-base \
    && LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php \
    && apt-get update \
    && DEBIAN_FRONTEND=noninteractive apt-get install -y \
        php7.3 php7.3-fpm php7.3-mysql php7.3-curl php7.3-mbstring php7.3-xml php7.3-zip \
        php7.3-gd php7.3-redis \
        nginx=1.14.* \
        sudo

RUN mkdir /code /config
WORKDIR /code

# Copy libraries and update composer
COPY ow_libraries /code/ow_libraries
COPY composer.* /code/
RUN php composer.phar install

COPY ow_core /code/ow_core
COPY ow_updates /code/ow_updates
COPY ow_cron /code/ow_cron
COPY ow_includes /code/ow_includes
COPY ow_log /code/ow_log
COPY ow_smarty/plugin /code/ow_smarty/plugin
COPY ow_system_plugins /code/ow_system_plugins
COPY ow_utilities /code/ow_utilities
COPY ow_iis /code/ow_iis

COPY ow_plugins /code/ow_plugins
COPY ow_themes /code/ow_themes

# Copy admin and base static files into the image
COPY ow_static /code/ow_static
# For other plugins and themes, make a symbolic link instead of copying
RUN mkdir -p /code/ow_static/plugins /code/ow_static/themes
COPY docker/update-statics.sh /
RUN bash /update-statics.sh /code/ow_plugins /static /code/ow_static/plugins
RUN bash /update-statics.sh /code/ow_themes '' /code/ow_static/themes
 
COPY captcha.php /code/captcha.php
COPY e500.php /code/e500.php
COPY index.php /code/index.php
COPY robots.txt /code/robots.txt
COPY ow_version.xml /code/ow_version.xml

COPY docker/nginx.conf /etc/nginx/sites-available/default
RUN sed -i 's`types {`types {\n    font/ttf ttf;`g' /etc/nginx/mime.types
COPY docker/*-entrypoint.sh /
RUN chmod +x /*-entrypoint.sh
COPY docker/php-fpm.conf /etc/php/7.3/fpm/pool.d/zz-docker.conf

RUN ln -sf /config/config.php /code/ow_includes/config.php

ENTRYPOINT ["/app-entrypoint.sh"]
