Merge pull request #63 from brendandburns/examples

Added the example dockerfiles.
pull/6/head
Joe Beda 2014-06-12 11:34:12 -07:00
commit 880059fb8a
6 changed files with 108 additions and 0 deletions

View File

@ -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

View File

@ -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(",");
});
});

View File

@ -0,0 +1,25 @@
<html ng-app="redis">
<head>
<title>Guestbook</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script>
<script src="/controllers.js"></script>
<script src="ui-bootstrap-tpls-0.10.0.min.js"></script>
</head>
<body ng-controller="RedisCtrl">
<div style="width: 50%; margin-left: 20px">
<h2>Guestbook</h2>
<form>
<fieldset>
<input ng-model="msg" placeholder="Messages" class="form-control" type="text" name="input"><br>
<button type="button" class="btn btn-primary" ng-click="controller.onRedis()">Submit</button>
</fieldset>
</form>
<div>
<div ng-repeat="msg in messages">
{{msg}}
</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,37 @@
<?
set_include_path('.:/usr/share/php:/usr/share/pear:/vendor/predis');
error_reporting(E_ALL);
ini_set('display_errors', 1);
require 'predis/autoload.php';
if (isset($_GET['cmd']) === true) {
header('Content-Type: application/json');
if ($_GET['cmd'] == 'set') {
$client = new Predis\Client([
'scheme' => '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();
} ?>

View File

@ -0,0 +1,7 @@
FROM dockerfile/redis
ADD run.sh /run.sh
RUN chmod a+x /run.sh
CMD /run.sh

View File

@ -0,0 +1,3 @@
#!/bin/bash
redis-server --slaveof $SERVICE_HOST $REDISMASTER_SERVICE_PORT