From 6b01ab816cfe3b816112320008c722ff9d9158ca Mon Sep 17 00:00:00 2001 From: William Yeh Date: Mon, 21 Mar 2016 20:54:11 +0800 Subject: [PATCH] Fix: better handling for multi-container testing with Docker. --- .travis.yml | 6 +----- 20-cluster/README.md | 2 -- 20-cluster/Vagrantfile | 9 ++++----- 20-cluster/test/Dockerfile-wordpress | 16 ++++++++++------ circle.yml | 5 +---- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0689e41..40ad099 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,14 +29,10 @@ 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 - - IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' db20) ; echo MYSQL_ADDRESS=$IP > db-ip - sleep 60 - - - docker run -d --name wordpress20 -e `cat db-ip` wordpress20 + - 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 diff --git a/20-cluster/README.md b/20-cluster/README.md index 6e621a4..a380fec 100644 --- a/20-cluster/README.md +++ b/20-cluster/README.md @@ -46,6 +46,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 21ea3b0..732aefc 100644 --- a/20-cluster/Vagrantfile +++ b/20-cluster/Vagrantfile @@ -38,13 +38,12 @@ Vagrant.configure("2") do |config| node.vm.provision "shell", inline: <<-SHELL cd /vagrant - docker build -f test/Dockerfile-db -t db . + docker build -f test/Dockerfile-db -t db . + docker build -f test/Dockerfile-wordpress -t wordpress . + docker run -d --name db db - IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' db) ; echo MYSQL_ADDRESS=$IP > db-ip sleep 60 - - docker build -f test/Dockerfile-wordpress -t wordpress . - docker run -d --name wordpress -e `cat db-ip` wordpress + docker run -d --name wordpress --link db:MYSQL_ADDRESS wordpress sleep 300 IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' wordpress) ; echo http://$IP:80/ > url diff --git a/20-cluster/test/Dockerfile-wordpress b/20-cluster/test/Dockerfile-wordpress index 91e13f6..7ad5cb4 100644 --- a/20-cluster/test/Dockerfile-wordpress +++ b/20-cluster/test/Dockerfile-wordpress @@ -28,6 +28,9 @@ 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 @@ -37,9 +40,10 @@ EXPOSE 80 # CMD \ - PLAYBOOK=wordpress.yml ansible-playbook-wrapper \ - --extra-vars "modify_hostname=false mysql_address=$MYSQL_ADDRESS" && \ - 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 + 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 53083c3..f29c027 100644 --- a/circle.yml +++ b/circle.yml @@ -33,12 +33,9 @@ test: - docker run -d --name db20 db20 - - IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' db20) ; echo MYSQL_ADDRESS=$IP > db-ip - sleep 60 - - - docker run -d --name wordpress20 -e `cat db-ip` wordpress20 + - 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