FROM alpine:3.3
MAINTAINER Tom Maiaroto <tom@outdoorsy.co>

# Install packages
RUN apk --update --repository http://dl-3.alpinelinux.org/alpine/edge/main add \
    freetype-dev \
    libjpeg-turbo-dev \
    libpng-dev \
    libwebp-dev \
	php7 \
	php7-xml \
    php7-xmlreader \
    php7-xsl \
    php7-pdo_mysql \
    php7-mcrypt \
    php7-curl \
    php7-json \
    php7-fpm \
    php7-phar \
    php7-openssl \
    php7-mysqli \
    php7-ctype \
    php7-opcache \
    php7-mbstring \
    php7-zlib \
    php7-gd \
	nginx \
	supervisor --repository http://nl.alpinelinux.org/alpine/edge/testing/

# Small fixes and cleanup
RUN ln -s /etc/php7 /etc/php && \
    ln -s /usr/bin/php7 /usr/bin/php && \
    ln -s /usr/sbin/php-fpm7 /usr/bin/php-fpm && \
    ln -s /usr/lib/php7 /usr/lib/php && \
    rm -fr /var/cache/apk/*

# PHP Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer

# Configure nginx
COPY config/nginx.conf /etc/nginx/nginx.conf

# Configure PHP-FPM
COPY config/fpm-pool.conf /etc/php7/php-fpm.d/zzz_custom.conf
COPY config/php.ini /etc/php7/conf.d/zzz_custom.ini

# Configure supervisord
COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# This runs supervisord as well as configures some things like nginx's webroot.
COPY config/config-and-run.sh /usr/local/bin/config-and-run.sh
RUN chmod +x /usr/local/bin/config-and-run.sh


# Note: The NGINX_WEBROOT environment variable should be set to change 
# the webroot so that this file is never served.
COPY config/index.php /var/www/html/

# Permissions
RUN chown nginx:www-data -R /var/lib/nginx
RUN chmod -R g+w /var/lib/nginx
# /run/nginx/nginx.pid needs /run/nginx to exist
# https://github.com/gliderlabs/docker-alpine/issues/185
RUN mkdir -p /run/nginx

# The following should be set or overwritten when the Docker container runs (ECS Task definition).
# These are used by WordPress.
# ENV DB_HOST
# ENV DB_NAME
# ENV DB_USER
# ENV DB_PASSWORD
ENV WP_ENV='development'
ENV WP_HOME='http://localhost'
ENV WP_SITEURL='http://localhost/wp'
# Not used by WordPress, but used by the config-and-run.sh script to replace
# the webroot in nginx.conf. It should point to where you have WordPress.
ENV WP_WEBROOT='/var/www/html'

EXPOSE 80 1443
CMD ["/usr/local/bin/config-and-run.sh"]