From 30f7fc5e3b3989b69017250706ae3350670540b3 Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Wed, 11 Jun 2014 12:33:39 -0700 Subject: [PATCH] Added the example dockerfiles. --- examples/guestbook/php-redis/Dockerfile | 7 ++++ examples/guestbook/php-redis/controllers.js | 29 ++++++++++++++++ examples/guestbook/php-redis/index.html | 25 ++++++++++++++ examples/guestbook/php-redis/index.php | 37 +++++++++++++++++++++ examples/guestbook/redis-slave/Dockerfile | 7 ++++ examples/guestbook/redis-slave/run.sh | 3 ++ 6 files changed, 108 insertions(+) create mode 100644 examples/guestbook/php-redis/Dockerfile create mode 100644 examples/guestbook/php-redis/controllers.js create mode 100644 examples/guestbook/php-redis/index.html create mode 100644 examples/guestbook/php-redis/index.php create mode 100644 examples/guestbook/redis-slave/Dockerfile create mode 100644 examples/guestbook/redis-slave/run.sh diff --git a/examples/guestbook/php-redis/Dockerfile b/examples/guestbook/php-redis/Dockerfile new file mode 100644 index 0000000000..3cf7c2cfa2 --- /dev/null +++ b/examples/guestbook/php-redis/Dockerfile @@ -0,0 +1,7 @@ +FROM brendanburns/php + +ADD index.php /var/www/index.php +ADD controllers.js /var/www/controllers.js +ADD index.html /var/www/index.html + +CMD /run.sh diff --git a/examples/guestbook/php-redis/controllers.js b/examples/guestbook/php-redis/controllers.js new file mode 100644 index 0000000000..1ea5bdce18 --- /dev/null +++ b/examples/guestbook/php-redis/controllers.js @@ -0,0 +1,29 @@ +var redisApp = angular.module('redis', ['ui.bootstrap']); + +/** + * Constructor + */ +function RedisController() {} + +RedisController.prototype.onRedis = function() { + this.scope_.messages.push(this.scope_.msg); + this.scope_.msg = ""; + var value = this.scope_.messages.join(); + this.http_.get("/index.php?cmd=set&key=messages&value=" + value) + .success(angular.bind(this, function(data) { + this.scope_.redisResponse = "Updated."; + })); +}; + +redisApp.controller('RedisCtrl', function ($scope, $http, $location) { + $scope.controller = new RedisController(); + $scope.controller.scope_ = $scope; + $scope.controller.location_ = $location; + $scope.controller.http_ = $http; + + $scope.controller.http_.get("/index.php?cmd=get&key=messages") + .success(function(data) { + console.log(data); + $scope.messages = data.data.split(","); + }); +}); diff --git a/examples/guestbook/php-redis/index.html b/examples/guestbook/php-redis/index.html new file mode 100644 index 0000000000..0d33d6d8ae --- /dev/null +++ b/examples/guestbook/php-redis/index.html @@ -0,0 +1,25 @@ + + + Guestbook + + + + + + +
+

Guestbook

+
+
+
+ +
+
+
+
+ {{msg}} +
+
+
+ + diff --git a/examples/guestbook/php-redis/index.php b/examples/guestbook/php-redis/index.php new file mode 100644 index 0000000000..5774b32090 --- /dev/null +++ b/examples/guestbook/php-redis/index.php @@ -0,0 +1,37 @@ + 'tcp', + 'host' => getenv('SERVICE_HOST'), + 'port' => getenv('REDISMASTER_SERVICE_PORT'), + ]); + $client->set($_GET['key'], $_GET['value']); + print('{"message": "Updated"}'); + } else { + $read_port = getenv('REDISMASTER_SERVICE_PORT'); + + if (isset($_ENV['REDISSLAVE_SERVICE_PORT'])) { + $read_port = getenv('REDISSLAVE_SERVICE_PORT'); + } + $client = new Predis\Client([ + 'scheme' => 'tcp', + 'host' => getenv('SERVICE_HOST'), + 'port' => $read_port, + ]); + + $value = $client->get($_GET['key']); + print('{"data": "' . $value . '"}'); + } +} else { + phpinfo(); +} ?> diff --git a/examples/guestbook/redis-slave/Dockerfile b/examples/guestbook/redis-slave/Dockerfile new file mode 100644 index 0000000000..1ce50fcc34 --- /dev/null +++ b/examples/guestbook/redis-slave/Dockerfile @@ -0,0 +1,7 @@ +FROM dockerfile/redis + +ADD run.sh /run.sh + +RUN chmod a+x /run.sh + +CMD /run.sh diff --git a/examples/guestbook/redis-slave/run.sh b/examples/guestbook/redis-slave/run.sh new file mode 100644 index 0000000000..103809cd39 --- /dev/null +++ b/examples/guestbook/redis-slave/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +redis-server --slaveof $SERVICE_HOST $REDISMASTER_SERVICE_PORT