diff --git a/api-payroll/.dockerignore b/api-payroll/.dockerignore new file mode 100644 index 0000000..a78e94f --- /dev/null +++ b/api-payroll/.dockerignore @@ -0,0 +1,5 @@ +Dockerfile +README.md +buildspec.yml +CONTRIBUTING.md +docker-compose.yml diff --git a/api-payroll/.htaccess b/api-payroll/.htaccess new file mode 100644 index 0000000..5a928f6 --- /dev/null +++ b/api-payroll/.htaccess @@ -0,0 +1 @@ +Options -Indexes diff --git a/api-payroll/Dockerfile b/api-payroll/Dockerfile new file mode 100644 index 0000000..d4fdc8f --- /dev/null +++ b/api-payroll/Dockerfile @@ -0,0 +1,43 @@ +FROM ubuntu:16.04 + +# Updating +RUN apt-get -y update && apt-get -y upgrade + +# Installing php, apache and supplementary software +RUN apt-get -y install apache2 php7.0 libapache2-mod-php7.0 php7.0-cli php7.0-common php7.0-mbstring php7.0-gd php7.0-intl php7.0-xml php7.0-mysql php7.0-mcrypt php7.0-zip curl git unzip composer + +# Enable apache mods +RUN a2enmod php7.0 +RUN a2enmod rewrite + +# Update the PHP.ini file, enable tags and quieten logging +RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.0/apache2/php.ini +RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/7.0/apache2/php.ini + +# Manually set up the apache environment variables +ENV APACHE_RUN_USER www-data +ENV APACHE_RUN_GROUP www-data +ENV APACHE_LOG_DIR /var/log/apache2 +ENV APACHE_LOCK_DIR /var/lock/apache2 + +# Expose apache +EXPOSE 80 + +# Copy this repo into place. +ADD . /var/www/site +WORKDIR /var/www/site + +# Testing permisions +RUN chmod 777 -R . + +# Installing dependencies +RUN composer install + +# Unit tests +RUN composer test + +# Update the default apache site with the config we created. +ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf + +# By default start up apache in the foreground, override with /bin/bash for interative +CMD /usr/sbin/apache2ctl -D FOREGROUND diff --git a/api-payroll/apache-config.conf b/api-payroll/apache-config.conf new file mode 100644 index 0000000..f89e608 --- /dev/null +++ b/api-payroll/apache-config.conf @@ -0,0 +1,15 @@ + + ServerAdmin me@mydomain.com + DocumentRoot /var/www/site + + + Options Indexes FollowSymLinks MultiViews + AllowOverride All + Order deny,allow + Allow from all + + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + diff --git a/api-payroll/buildspec.yml b/api-payroll/buildspec.yml index 55bbfa4..8723797 100644 --- a/api-payroll/buildspec.yml +++ b/api-payroll/buildspec.yml @@ -14,8 +14,9 @@ phases: - echo Entered the build phase... - echo Build started on `date` - composer test + - sudo docker-compose up --build -d post_build: commands: - echo Entered the post_build phase... + - sudo docker-compose down --rmi all -v - echo Build completed on `date` - diff --git a/api-payroll/src/settings.php b/api-payroll/src/settings.php index 435f286..af5995f 100644 --- a/api-payroll/src/settings.php +++ b/api-payroll/src/settings.php @@ -26,7 +26,7 @@ return [ // Datanase settings 'mysql' => [ - 'host' => 'localhost', + 'host' => 'mysql', 'database' => 'payroll', 'user' => 'root', 'password' => '12345678', diff --git a/database/.dockerignore b/database/.dockerignore new file mode 100644 index 0000000..9414382 --- /dev/null +++ b/database/.dockerignore @@ -0,0 +1 @@ +Dockerfile diff --git a/database/Dockerfile b/database/Dockerfile new file mode 100644 index 0000000..c96c19f --- /dev/null +++ b/database/Dockerfile @@ -0,0 +1,3 @@ +FROM mysql:5.7 + +ADD . /docker-entrypoint-initdb.d diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5d802d7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: '3' +services: + api: + container_name: payroll_api + build: api-payroll/ + ports: + - "8085:80" + volumes: + - api-payroll:/var/www/site + depends_on: + - mysql + mysql: + container_name: payroll_mysql + restart: always + build: database + ports: + - "3306:3306" + volumes: + - my-datavolume:/var/lib/mysql + environment: + MYSQL_ROOT_PASSWORD: '12345678' + MYSQL_USER: 'sloth' + MYSQL_PASS: '12345678' +volumes: + api-payroll: + my-datavolume: