Skip to content

Commit

Permalink
Updated tests and Dockerfiles to pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrayner committed Mar 14, 2020
1 parent a5ea0f7 commit be56abc
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 81 deletions.
19 changes: 3 additions & 16 deletions 1604/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ENV DOCKER_USER_GID 20
ENV BOOT2DOCKER_ID 1000
ENV BOOT2DOCKER_GID 50

ENV PHPMYADMIN_VERSION=4.9.0.1
ENV PHPMYADMIN_VERSION=5.0.1

# Tweaks to give Apache/PHP write permissions to the app
RUN usermod -u ${BOOT2DOCKER_ID} www-data && \
Expand All @@ -27,15 +27,11 @@ ENV DEBIAN_FRONTEND noninteractive
RUN add-apt-repository -y ppa:ondrej/php && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C && \
apt-get update && \
apt-get -y upgrade && \
apt-get -y install supervisor wget git apache2 php-xdebug libapache2-mod-php mysql-server php-mysql pwgen php-apcu php7.1-mcrypt php-gd php-xml php-mbstring php-gettext zip unzip php-zip curl php-curl && \
apt-get -o Dpkg::Options::="--force-confnew" --force-yes -fuy upgrade && \
apt-get -y install supervisor wget git apache2 php-xdebug libapache2-mod-php mysql-server php-mysql pwgen php-apcu php-gd php-xml php-mbstring php-gettext zip unzip php-zip curl php-curl && \
apt-get -y autoremove && \
echo "ServerName localhost" >> /etc/apache2/apache2.conf

# needed for phpMyAdmin
RUN ln -s /etc/php/7.1/mods-available/mcrypt.ini /etc/php/7.3/mods-available/ && \
phpenmod mcrypt

# Add image configuration and scripts
ADD supporting_files/start-apache2.sh /start-apache2.sh
ADD supporting_files/start-mysqld.sh /start-mysqld.sh
Expand All @@ -45,20 +41,11 @@ ADD supporting_files/supervisord-apache2.conf /etc/supervisor/conf.d/supervisord
ADD supporting_files/supervisord-mysqld.conf /etc/supervisor/conf.d/supervisord-mysqld.conf
ADD supporting_files/mysqld_innodb.cnf /etc/mysql/conf.d/mysqld_innodb.cnf

# Allow mysql to bind on 0.0.0.0
RUN sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf && \
sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/mysqld.cnf

# Set PHP timezones to Europe/London
RUN sed -i "s/;date.timezone =/date.timezone = Europe\/London/g" /etc/php/7.3/apache2/php.ini
RUN sed -i "s/;date.timezone =/date.timezone = Europe\/London/g" /etc/php/7.3/cli/php.ini

# Remove pre-installed database
RUN rm -rf /var/lib/mysql

# Add MySQL utils
ADD supporting_files/create_mysql_users.sh /create_mysql_users.sh
RUN chmod 755 /*.sh

# Add phpmyadmin
RUN wget -O /tmp/phpmyadmin.tar.gz https://files.phpmyadmin.net/phpMyAdmin/${PHPMYADMIN_VERSION}/phpMyAdmin-${PHPMYADMIN_VERSION}-all-languages.tar.gz
Expand Down
24 changes: 5 additions & 19 deletions 1804/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,26 @@ ENV DOCKER_USER_GID 20
ENV BOOT2DOCKER_ID 1000
ENV BOOT2DOCKER_GID 50

ENV PHPMYADMIN_VERSION=4.9.0.1
ENV PHPMYADMIN_VERSION=5.0.1

# Tweaks to give Apache/PHP write permissions to the app
RUN usermod -u ${BOOT2DOCKER_ID} www-data && \
usermod -G staff www-data && \
useradd -r mysql && \
usermod -G staff mysql

RUN groupmod -g $(($BOOT2DOCKER_GID + 10000)) $(getent group $BOOT2DOCKER_GID | cut -d: -f1)
RUN groupmod -g ${BOOT2DOCKER_GID} staff
usermod -G staff mysql && \
groupmod -g $(($BOOT2DOCKER_GID + 10000)) $(getent group $BOOT2DOCKER_GID | cut -d: -f1) && \
groupmod -g ${BOOT2DOCKER_GID} staff

# Install packages
ENV DEBIAN_FRONTEND noninteractive
RUN add-apt-repository -y ppa:ondrej/php && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C && \
apt-get update && \
apt-get -y upgrade && \
apt-get -y install supervisor wget git apache2 php-xdebug libapache2-mod-php mysql-server php-mysql pwgen php-apcu php7.1-mcrypt php-gd php-xml php-mbstring php-gettext zip unzip php-zip curl php-curl && \
apt-get -y install supervisor wget git apache2 php-xdebug libapache2-mod-php mysql-server php-mysql pwgen php-apcu php-gd php-xml php-mbstring php-gettext zip unzip php-zip curl php-curl && \
apt-get -y autoremove && \
echo "ServerName localhost" >> /etc/apache2/apache2.conf

# needed for phpMyAdmin
RUN ln -s /etc/php/7.1/mods-available/mcrypt.ini /etc/php/7.3/mods-available/ && \
phpenmod mcrypt

# Add image configuration and scripts
ADD supporting_files/start-apache2.sh /start-apache2.sh
ADD supporting_files/start-mysqld.sh /start-mysqld.sh
Expand All @@ -45,20 +40,11 @@ ADD supporting_files/supervisord-apache2.conf /etc/supervisor/conf.d/supervisord
ADD supporting_files/supervisord-mysqld.conf /etc/supervisor/conf.d/supervisord-mysqld.conf
ADD supporting_files/mysqld_innodb.cnf /etc/mysql/conf.d/mysqld_innodb.cnf

# Allow mysql to bind on 0.0.0.0
RUN sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf && \
sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/mysqld.cnf

# Set PHP timezones to Europe/London
RUN sed -i "s/;date.timezone =/date.timezone = Europe\/London/g" /etc/php/7.4/apache2/php.ini
RUN sed -i "s/;date.timezone =/date.timezone = Europe\/London/g" /etc/php/7.4/cli/php.ini

# Remove pre-installed database
RUN rm -rf /var/lib/mysql

# Add MySQL utils
ADD supporting_files/create_mysql_users.sh /create_mysql_users.sh
RUN chmod 755 /*.sh

# Add phpmyadmin
RUN wget -O /tmp/phpmyadmin.tar.gz https://files.phpmyadmin.net/phpMyAdmin/${PHPMYADMIN_VERSION}/phpMyAdmin-${PHPMYADMIN_VERSION}-all-languages.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test:
docker-compose -f docker-compose.test.yml -p ci build
docker-compose -f docker-compose.test.yml -p ci up -d
docker logs -f ci_sut_1
cd test && ./test.sh
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ With Ubuntu **18.04** amd **16.04** images on the `latest-1804` and `latest-1604
- [One-line testing command](#one-line-testing-command)
- [`docker-compose -f docker-compose.test.yml -p ci build;`](#docker-compose--f-docker-composetestyml--p-ci-build)
- [`docker-compose -f docker-compose.test.yml -p ci up -d;`](#docker-compose--f-docker-composetestyml--p-ci-up--d)
- [`docker logs -f ci_sut_1;`](#docker-logs--f-ci_sut_1)
- [`echo "Exited with status code: $(docker wait ci_sut_1)"`](#echo-exited-with-status-code-docker-wait-ci_sut_1)
- [`cd tests && ./test.sh;`](#cd-tests--testsh)
- [`echo "Exited with status code: $?"`](#echo-exited-with-status-code-)
- [Inspiration](#inspiration)
- [Contributing](#contributing)
- [License](#license)
Expand Down Expand Up @@ -188,13 +188,13 @@ ldi 3000 3306
git clone https://github.com/mattrayner/docker-lamp.git
cd docker-lamp

# Build the 18.04, 16.04 image and the 14.04 images
docker build -t=mattrayner/lamp:latest -f ./1804/Dockerfile-php7 .
docker build -t=mattrayner/lamp:latest-1604 -f ./1604/Dockerfile-php7 .
docker build -t=mattrayner/lamp:latest-1404 -f ./1404/Dockerfile-php7 .
# Build the images
docker build -t=mattrayner/lamp:latest -f ./1804/Dockerfile .
docker build -t=mattrayner/lamp:latest-1604 -f ./1604/Dockerfile .
docker build -t=mattrayner/lamp:latest-1804 -f ./1804/Dockerfile .

# Run the 14.04 image as a container
docker run -p "3000:80" mattrayner/lamp:latest-1404 -d
# Run the image as a container
docker run -p "3000:80" mattrayner/lamp:latest-1804 -d

# Sleep to allow the container to boot
sleep 5
Expand All @@ -209,7 +209,7 @@ We use `docker-compose` to setup, build and run our testing environment. It allo
### One-line testing command
We've developed a single-line test command you can run on your machine within the `docker-lamp` directory. This will test any changes that may have been made, as well as comparing installed versions of Apache, MySQL, PHP and phpMyAdmin against those expected.
```bash
docker-compose -f docker-compose.test.yml -p ci build; docker-compose -f docker-compose.test.yml -p ci up -d; docker logs -f ci_sut_1; echo "Exited with status code: $(docker wait ci_sut_1)";
docker-compose -f docker-compose.test.yml -p ci build; docker-compose -f docker-compose.test.yml -p ci up -d; cd tests && ./test.sh; echo "Exited with status code: $?";
```

So what does this command do?
Expand All @@ -218,13 +218,13 @@ So what does this command do?
First, build that latest version of our docker-compose images.

#### `docker-compose -f docker-compose.test.yml -p ci up -d;`
Launch our docker containers (`web1804`, `web1604`, `web1404` and `sut` or *system under tests*) in daemon mode.
Launch our docker containers (`web1804` and `web1604`) in daemon mode.

#### `docker logs -f ci_sut_1;`
Display all of the logging output from the `sut` container (extremely useful for debugging)
#### `cd tests && ./test.sh;`
Change into the test directory and run out tests

#### `echo "Exited with status code: $(docker wait ci_sut_1)"`
Report back the status code that the `sut` container ended with.
#### `echo "Exited with status code: $?"`
Report back whether the tests passed or not


## Inspiration
Expand Down
7 changes: 0 additions & 7 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
sut:
build: tests/.
dockerfile: Dockerfile.test
links:
- web1804-php7
- web1604-php7

web1804-php7:
build: .
dockerfile: ./1804/Dockerfile
Expand Down
3 changes: 2 additions & 1 deletion supporting_files/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ chown -R www-data:staff /var/run/mysqld

if [ -e /var/run/mysqld/mysqld.sock ]; then rm /var/run/mysqld/mysqld.sock; fi

sed -i "/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/mysqld.cnf
sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/mysqld.cnf
sed -i "/user.*/user = www-data/" /etc/mysql/mysql.conf.d/mysqld.cnf

if [[ ! -d $VOLUME_HOME/mysql ]]; then
Expand Down
17 changes: 0 additions & 17 deletions tests/Dockerfile.test

This file was deleted.

6 changes: 3 additions & 3 deletions tests/expected/1604-php7.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ <h2>Welcome to <a href="https://github.com/mattrayner/docker-lamp" target="_blan
<pre>
OS: Linux<br/>
Apache: Apache/2.4.18 (Ubuntu)<br/>
MySQL Version: 5.7.26-0ubuntu0.16.04.1-log<br/>
PHP Version: 7.3.6-1+ubuntu16.04.1+deb.sury.org+1<br/>
phpMyAdmin Version: 4.9.0.1 </pre>
MySQL Version: 5.7.29-0ubuntu0.16.04.1-log<br/>
PHP Version: 7.4.3<br/>
phpMyAdmin Version: 5.0.1 </pre>
</section>
</div>
</body>
Expand Down
6 changes: 3 additions & 3 deletions tests/expected/1804-php7.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ <h2>Welcome to <a href="https://github.com/mattrayner/docker-lamp" target="_blan
<pre>
OS: Linux<br/>
Apache: Apache/2.4.29 (Ubuntu)<br/>
MySQL Version: 5.7.26-0ubuntu0.18.04.1-log<br/>
PHP Version: 7.3.6-1+ubuntu18.04.1+deb.sury.org+1<br/>
phpMyAdmin Version: 4.9.0.1 </pre>
MySQL Version: 5.7.29-0ubuntu0.18.04.1-log<br/>
PHP Version: 7.4.3<br/>
phpMyAdmin Version: 5.0.1 </pre>
</section>
</div>
</body>
Expand Down

0 comments on commit be56abc

Please sign in to comment.