FROM gcr.io/numerologist-888/php56-nginx-mesl

ENV NGINX_DIR=/usr/local/nginx \
    PHP_DIR=/usr/local/php \
    PHP56_DIR=/usr/local/php56 \
    PHP7_DIR=/usr/local/php7 \
    LOG_DIR=/var/log/app_engine \
    APP_DIR=/app/public \
    NGINX_USER_CONF_DIR=/etc/nginx/conf.d \
    UPLOAD_DIR=/upload \
    SESSION_SAVE_PATH=/tmp/sessions \
    NGINX_VERSION=1.10.0 \
    PHP56_VERSION=5.6.21 \
    PATH=/usr/local/php/bin:$PATH

# A script for dynamic configuration.
RUN git clone -b php56-nginx-mesl https://gitlab.com/numerologist-apps/php-docker.git && cp php-docker/php-nginx/entrypoint.sh /entrypoint.sh && cp php-docker/php-nginx/composer.sh /composer.sh && cp php-docker/php-nginx/detect_php_version.php /tmp/detect_php_version.php
RUN chmod +x /entrypoint.sh    

# A script for installing dependencies.
RUN chmod +x /composer.sh

# A script for extracting PHP version from composer.json.
RUN cd /tmp && ${PHP_DIR}/bin/php \
        -d suhosin.executor.include.whitelist=phar \
        -d suhosin.executor.func.blacklist=none \
        -d memory_limit=-1 \
        -d max_input_time=-1 \
        /usr/local/bin/composer \
        require composer/semver

# SET custom NGINX config.         

ENV DOCUMENT_ROOT /app/public
COPY srv-nginx.conf $NGINX_DIR/conf/nginx.conf        

# FINISH BUILD
ARG WWW_DATA_UID=33
RUN usermod -u $WWW_DATA_UID www-data && groupmod -g $WWW_DATA_UID www-data

COPY . $APP_DIR
RUN chmod -R 775 $APP_DIR 
RUN chown -R root.www-data $APP_DIR

WORKDIR $APP_DIR

RUN /composer.sh
# Now suhosin.log might be owned by root.
RUN touch $LOG_DIR/suhosin.log
RUN chown www-data.www-data $LOG_DIR/suhosin.log
RUN chmod -R 775 $APP_DIR/aside && \
    chmod -R 775 $APP_DIR/audio && \
    chmod -R 775 $APP_DIR/bin && \
    chmod -R 775 $APP_DIR/css && \
    chmod -R 775 $APP_DIR/fonts && \
    chmod -R 775 $APP_DIR/slides && \ 
    chmod -R 775 $APP_DIR/vendor && \
    chmod -R 775 $APP_DIR/videos

ENTRYPOINT ["/entrypoint.sh"]
CMD ["/usr/bin/supervisord"]

