FROM php:7.0-apache

ARG API_URL

ARG MYSQL_DATABASE
ARG MYSQL_USER
ARG MYSQL_PASSWORD

ARG WP_ENV
ARG WP_AUTH_KEY
ARG WP_SECURE_AUTH_KEY
ARG WP_LOGGED_IN_KEY
ARG WP_NONCE_KEY
ARG WP_AUTH_SALT
ARG WP_SECURE_AUTH_SALT
ARG WP_LOGGED_IN_SALT
ARG WP_NONCE_SALT
ARG WP_JWT_AUTH_SECRET_KEY

ENV WP_ENV ${WP_ENV}
ENV WP_HOME ${API_URL}
ENV WP_DB_HOST db

ENV MYSQL_DATABASE ${MYSQL_DATABASE}
ENV MYSQL_USER ${MYSQL_USER}
ENV MYSQL_PASSWORD ${MYSQL_PASSWORD}

ENV WP_AUTH_KEY ${WP_AUTH_KEY}
ENV WP_SECURE_AUTH_KEY ${WP_SECURE_AUTH_KEY}
ENV WP_LOGGED_IN_KEY ${WP_LOGGED_IN_KEY}
ENV WP_NONCE_KEY ${WP_NONCE_KEY}
ENV WP_AUTH_SALT ${WP_AUTH_SALT}
ENV WP_SECURE_AUTH_SALT ${WP_SECURE_AUTH_SALT}
ENV WP_LOGGED_IN_SALT ${WP_LOGGED_IN_SALT}
ENV WP_NONCE_SALT ${WP_NONCE_SALT}
ENV WP_JWT_AUTH_SECRET_KEY ${WP_JWT_AUTH_SECRET_KEY}

RUN apt-get update && apt-get install -y git unzip gnupg mysql-client sudo

COPY docker/php/composer.phar /usr/local/bin/composer
RUN chmod 755 /usr/local/bin/composer

COPY docker/php/wp-cli.phar /usr/local/bin/wp
RUN chmod +x /usr/local/bin/wp

COPY docker/php/setup.sh /init-scripts/
RUN chmod +x /init-scripts/setup.sh

RUN docker-php-ext-install pdo pdo_mysql mysqli
RUN a2enmod rewrite ssl

COPY backend /home/wiaas/backend

WORKDIR /home/wiaas/backend/
RUN composer install --no-dev

WORKDIR /home/wiaas
RUN cp -r backend/* /var/www/html/


WORKDIR /var/www/html
RUN ln -s ../html api

COPY docker/php/.htaccess /var/www/html/ 

RUN chown -R www-data:www-data /var/www/html

CMD /init-scripts/setup.sh
