From 7f60b32b6307537586dd3afb2ab33e5d37cd5ac9 Mon Sep 17 00:00:00 2001 From: Pike Date: Mon, 19 Sep 2016 13:34:49 +0800 Subject: [PATCH 1/2] get containerID fron php server --- Dockerfile | 11 +++++------ hostname.php | 6 ++++++ js/application.js | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 hostname.php diff --git a/Dockerfile b/Dockerfile index 0d4f85f..b8677ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,18 @@ # Using a compact OS -FROM alpine:latest +FROM php:5-zts-alpine -MAINTAINER Golfen Guo +MAINTAINER Golfen Guo # Install and configure Nginx RUN apk --update add nginx RUN sed -i "s#root html;#root /usr/share/nginx/html;#g" /etc/nginx/nginx.conf RUN ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.log - + # Add 2048 stuff into Nginx server COPY . /usr/share/nginx/html EXPOSE 80 -# Start Nginx and keep it from running background -CMD ["nginx", "-g", "pid /tmp/nginx.pid; daemon off;"] - +# Start Nginx and keep it running background and start php +CMD nginx -g "pid /tmp/nginx.pid; daemon on;" && php -S 0.0.0.0:8888 /usr/share/nginx/html/hostname.php diff --git a/hostname.php b/hostname.php new file mode 100644 index 0000000..7974716 --- /dev/null +++ b/hostname.php @@ -0,0 +1,6 @@ + diff --git a/js/application.js b/js/application.js index 2c1108e..7ddab5c 100644 --- a/js/application.js +++ b/js/application.js @@ -2,3 +2,20 @@ window.requestAnimationFrame(function () { new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager); }); + +function httpGet(url) { + var xmlHttp = new XMLHttpRequest(); + xmlHttp.open("GET", url, false); + xmlHttp.send(null); + return xmlHttp.responseText; +} + +function setContainerID() { + var hostname = httpGet("http://" + window.location.hostname + ":8888"); + var container = document.getElementsByClassName("container")[0]; + var tmp = document.createElement('div'); + tmp.innerHTML = '

ContainerID: ' + hostname + "

"; + container.insertBefore(tmp, container.children[0]); +} + +setContainerID(); From efadbf44818f686d58ad23e3edfbd84abd0e9f5e Mon Sep 17 00:00:00 2001 From: Pike Date: Mon, 19 Sep 2016 18:13:18 +0800 Subject: [PATCH 2/2] remove php && use sed --- Dockerfile | 4 ++-- hostname.php | 6 ------ index.html | 1 + js/application.js | 17 ----------------- 4 files changed, 3 insertions(+), 25 deletions(-) delete mode 100644 hostname.php diff --git a/Dockerfile b/Dockerfile index b8677ce..78981eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Using a compact OS -FROM php:5-zts-alpine +FROM alpine:latest MAINTAINER Golfen Guo @@ -15,4 +15,4 @@ COPY . /usr/share/nginx/html EXPOSE 80 # Start Nginx and keep it running background and start php -CMD nginx -g "pid /tmp/nginx.pid; daemon on;" && php -S 0.0.0.0:8888 /usr/share/nginx/html/hostname.php +CMD sed -i "s/ContainerID: /ContainerID: "$(hostname)"/g" /usr/share/nginx/html/index.html && nginx -g "pid /tmp/nginx.pid; daemon off;" diff --git a/hostname.php b/hostname.php deleted file mode 100644 index 7974716..0000000 --- a/hostname.php +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/index.html b/index.html index 0da0ee0..f718cc0 100644 --- a/index.html +++ b/index.html @@ -18,6 +18,7 @@
+

ContainerID:

2048

diff --git a/js/application.js b/js/application.js index 7ddab5c..2c1108e 100644 --- a/js/application.js +++ b/js/application.js @@ -2,20 +2,3 @@ window.requestAnimationFrame(function () { new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager); }); - -function httpGet(url) { - var xmlHttp = new XMLHttpRequest(); - xmlHttp.open("GET", url, false); - xmlHttp.send(null); - return xmlHttp.responseText; -} - -function setContainerID() { - var hostname = httpGet("http://" + window.location.hostname + ":8888"); - var container = document.getElementsByClassName("container")[0]; - var tmp = document.createElement('div'); - tmp.innerHTML = '

ContainerID: ' + hostname + "

"; - container.insertBefore(tmp, container.children[0]); -} - -setContainerID();