# Debian: PHP-QA
#
# VERSION 0.0.1

#
# Pull the base image.
#
FROM re6exp/debian-jessie-oracle-jdk-8

#
# Set author.
#
MAINTAINER <NAME> <<EMAIL>>

# Set environment variables.
ENV FILES docker/files/
ENV NGINX_VERSION 1.9.9-1~jessie

# Install Wget Git Nano.
#
# 	- wget
# 	- git
# 	- nano
RUN apt-get update && \
    apt-get install -y wget git nano

# Install NGINX.
# 
# 	- openssl
# 	- ca-certificates
# 	- nginx
RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys <KEY>
RUN echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list

RUN apt-get update && \
    apt-get install -y openssl ca-certificates nginx=${NGINX_VERSION}

# Remove default configuration files.
RUN rm -rf /etc/nginx/nginx.conf
RUN rm -rf /etc/nginx/conf.d/*

# Add managed nginx configuration files.
ADD ${FILES}/etc/nginx/nginx.conf /etc/nginx/
ADD ${FILES}/etc/nginx/conf.d/php-qa-app.conf /etc/nginx/conf.d/
ADD ${FILES}/etc/nginx/fastcgi_params /etc/nginx/
ADD ${FILES}/etc/nginx/conf.d/php-upstream.conf /etc/nginx/conf.d/upstream.conf

# Remove default directories.
RUN rm -rf /var/www/*
RUN rm -rf /srv/www/*

# Forward request and error logs to docker log collector.
RUN ln -sf /dev/stdout /var/log/nginx/access.log
RUN ln -sf /dev/stderr /var/log/nginx/error.log

# Install X virtual framebuffer.
#
# 	- Xvfb
#
RUN apt-get update && \
	apt-get install -y xvfb

# Install Firefox.
#
RUN echo "deb http://packages.linuxmint.com debian import" >> /etc/apt/sources.list

RUN apt-key update && \
	apt-get update && \
	apt-get install -y --force-yes firefox

# Adjust Firefox installation directory.
RUN chmod -R +x /opt/firefox/

# Install Firefox dependencies.
#
# 	- libdbus-glib
#	- libxrender-dev
#	- libxcomposite-dev
#	- libasound-dev
#	- libgtk-3-0
#	- libgtk2.0-0-dbg
RUN apt-get update && \
	apt-get install -y libdbus-glib-1-2 && \
	apt-get install -y libxrender-dev && \
	apt-get install -y libxcomposite-dev && \
	apt-get install -y libasound-dev && \
	apt-get install -y libgtk-3-0 && \
	apt-get install -y libgtk2.0-0-dbg

# Download Selenium standalone server (2.49.1).
RUN wget -O selenium-server-standalone-2.49.1.jar http://goo.gl/rQhaxb -P /opt/

# Install PHP 5.
#
# 	- php5-dev
#	- php5-common
#	- php5-pear
# 	- php5-cli
# 	- php5-fpm
# 	- php5-mcrypt
# 	- php5-mysql
# 	- php5-apcu
# 	- php5-gd
# 	- php5-imagick
# 	- php5-curl
# 	- php5-intl
RUN apt-get update && \
    apt-get install -y php5-dev php5-common php5-cli php5-fpm php5-mcrypt php5-mysql php5-apcu php5-gd php5-imagick php5-curl php5-intl

# Add managed php ini files.
ADD ${FILES}/etc/php5/fpm/conf.d/php-qa-app.ini /etc/php5/fpm/conf.d/
ADD ${FILES}/etc/php5/fpm/conf.d/php-qa-app.ini /etc/php5/cli/conf.d/
ADD ${FILES}/etc/php5/fpm/pool.d/php-qa-app.pool.conf /etc/php5/fpm/pool.d/

# Install Curl
RUN apt-get update && \
	apt-get install curl

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

# Install PHP Composer dependecies.
#
# - phpunit
# - phpunit-selenium
RUN composer global require phpunit/phpunit && \
	composer global require phpunit/phpunit-selenium

# Install PHP Composer dependecies
#
# - phpdocumentor
# - phpcpd
# - phploc
# - phpmd
# - php_codesniffer
RUN composer global require phpdocumentor/phpdocumentor && \
	composer global require sebastian/phpcpd && \
	composer global require phploc/phploc && \
	composer global require phpmd/phpmd && \
	composer global require squizlabs/php_codesniffer && \
	composer global require facebook/webdriver

# composer global require phpunit/dbunit
# composer global require phing/phing

# Install PHPUnit
RUN wget https://phar.phpunit.de/phpunit.phar && \
	chmod +x phpunit.phar && \
	mv phpunit.phar /usr/local/bin/phpunit && \
	phpunit --version

# Install Supervisor.
# 
RUN apt-get update && \
	apt-get install -y supervisor

# Add managed supervisor configuration files.
ADD ${FILES}/etc/supervisor/conf.d/supervisord.conf /etc/supervisor/conf.d/supervisord.conf 

# Define mountable directories.
VOLUME ["/srv/www", "/etc/nginx", "/var/log/nginx/", "/var/cache/nginx"]

# Listen on http https ports.
EXPOSE 80 443

# Add scripts.
ADD ./bin/ /bin

# Configure executable.
ENTRYPOINT ["/usr/bin/supervisord"]

# Define default command.
CMD []