diff --git a/.travis.yml b/.travis.yml index 51cd08d..25c5275 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ before_install: - docker build -f 06-ci/test/Dockerfile -t wordpress06 06-ci - docker build -f 10-role/test/Dockerfile -t wordpress10 10-role - docker build -f 11-galaxy/test/Dockerfile -t wordpress11 11-galaxy + - docker build -f 20-cluster/test/Dockerfile -t wordpress20 20-cluster script: - docker run -d --name wordpress06 wordpress06 @@ -26,8 +27,16 @@ script: - IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' wordpress11) ; echo http://$IP:80/ > url - cat url | xargs -t -n 1 curl -v --retry 5 --retry-max-time 120 -o result-wordpress11 + - docker run -d --name db20 db20 + - sleep 60 + - docker run -d --name wordpress20 --link db20:MYSQL_ADDRESS wordpress20 + - sleep 300 + - IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' wordpress20) ; echo http://$IP:80/ > url + - cat url | xargs -t -n 1 curl -v -o result-wordpress20 + - echo "==> Validating the test results..." - grep 'ANSIBLE_TEST' result-wordpress06 - grep '<title>ANSIBLE_TEST' result-wordpress10 - grep '<title>ANSIBLE_TEST' result-wordpress11 + - grep '<title>ANSIBLE_TEST' result-wordpress20 diff --git a/20-cluster/README.md b/20-cluster/README.md index d1ef77d..ebdb5fc 100644 --- a/20-cluster/README.md +++ b/20-cluster/README.md @@ -44,6 +44,4 @@ Separated by... - Avoid the "all hosts" `%` setting in the MySQL `GRANT PRIVILEGES` statement. -- Use the [container links](https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/) feature of Docker to simplify the testing Dockerfiles. - - Use [Docker Compose](https://github.com/docker/compose) to simplify the testing job. diff --git a/20-cluster/Vagrantfile b/20-cluster/Vagrantfile index 3fce2a2..5da35f1 100644 --- a/20-cluster/Vagrantfile +++ b/20-cluster/Vagrantfile @@ -29,4 +29,28 @@ Vagrant.configure("2") do |config| end end + + # docker: for auto build & testing (e.g., Travis CI) + config.vm.define "docker" do |node| + node.vm.box = "williamyeh/ubuntu-trusty64-docker" + + node.vm.provision "shell", inline: <<-SHELL + cd /vagrant + + docker build -f test/Dockerfile-db -t db . + docker build -f test/Dockerfile-wordpress -t wordpress . + + docker run -d --name db db + sleep 60 + docker run -d --name wordpress --link db:MYSQL_ADDRESS wordpress + sleep 300 + + IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' wordpress) ; echo http://$IP:80/ > url + cat url | xargs -t -n 1 curl -v -o result-wordpress + + echo "==> Validating the test results..." + grep '<title>ANSIBLE_TEST' result-wordpress + SHELL + end + end diff --git a/20-cluster/test/Dockerfile-wordpress b/20-cluster/test/Dockerfile-wordpress new file mode 100644 index 0000000..7ad5cb4 --- /dev/null +++ b/20-cluster/test/Dockerfile-wordpress @@ -0,0 +1,49 @@ +# Dockerfile for building image that contains software stack provisioned by Ansible. +# +# USAGE: +# $ docker build -t wordpress . +# $ docker run -d wordpress +# +# Version 1.1 +# + + +# pull base image +FROM williamyeh/ansible:ubuntu14.04-onbuild + +MAINTAINER William Yeh <william.pjyeh@gmail.com> + + +# +# build phase +# + + +# fix policy-rc.d for Docker +# @see http://www.monblocnotes.com/node/2057 +# @see http://askubuntu.com/a/365912 +RUN sed -i -e 's/exit\s\s*101/exit 0/' /usr/sbin/policy-rc.d + + +# ==> Specify requirements filename; default = "requirements.yml" +#ENV REQUIREMENTS requirements.yml + +ENV PLAYBOOK wordpress.yml +RUN ansible-playbook-wrapper \ + --extra-vars "modify_hostname=false mysql_address=MYSQL_ADDRESS" + +EXPOSE 80 + + +# +# start the service via CMD +# + +CMD \ + service php7.0-fpm start && \ + service nginx start && \ + IP=`head -n 1 /etc/hosts | sed 's/\t.*//'` && \ + PLAYBOOK=init-wordpress.yml \ + ansible-playbook-wrapper -vvv \ + --extra-vars `echo hostname=$IP` && \ + tail -f /dev/null \ No newline at end of file diff --git a/circle.yml b/circle.yml index 5cd9fd6..597c6cb 100644 --- a/circle.yml +++ b/circle.yml @@ -10,6 +10,7 @@ dependencies: - docker build -f 06-ci/test/Dockerfile -t wordpress06 06-ci - docker build -f 10-role/test/Dockerfile -t wordpress10 10-role - docker build -f 11-galaxy/test/Dockerfile -t wordpress11 11-galaxy + - docker build -f 20-cluster/test/Dockerfile -t wordpress20 20-cluster test: @@ -29,8 +30,16 @@ test: - IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' wordpress11) ; echo http://$IP:80/ > url - cat url | xargs -t -n 1 curl -v --retry 5 --retry-max-time 120 -o result-wordpress11 + - docker run -d --name db20 db20 + - sleep 60 + - docker run -d --name wordpress20 --link db20:MYSQL_ADDRESS wordpress20 + - sleep 300 + - IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' wordpress20) ; echo http://$IP:80/ > url + - cat url | xargs -t -n 1 curl -v -o result-wordpress20 + - echo "==> Validating the test results..." - grep '<title>ANSIBLE_TEST' result-wordpress06 - grep '<title>ANSIBLE_TEST' result-wordpress10 - grep '<title>ANSIBLE_TEST' result-wordpress11 + - grep '<title>ANSIBLE_TEST' result-wordpress20