Skip to content

Commit

Permalink
Merge pull request oracle#395 from mikarinneoracle/rolling-router-sti…
Browse files Browse the repository at this point in the history
…cky-sessions-management-ui

rolling-router-sticky-sessions ui added
  • Loading branch information
mikeraab authored May 24, 2017
2 parents 9c4e6a5 + 4d10b06 commit ca72955
Show file tree
Hide file tree
Showing 16 changed files with 702 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ FROM __REGISTRY_NAME__/confd:__VERSION_CONFD__
RUN \
build_pkgs="build-base linux-headers openssl-dev pcre-dev wget zlib-dev" && \
runtime_pkgs="ca-certificates openssl pcre zlib" && \
apk --update add ${build_pkgs} ${runtime_pkgs} && \
php_pkgs="php5-fpm php5-mcrypt php5-soap php5-openssl php5-gmp php5-pdo_odbc php5-json php5-dom php5-pdo php5-zip php5-mysql php5-mysqli php5-sqlite3 php5-apcu php5-pdo_pgsql php5-bcmath php5-gd php5-xcache php5-odbc php5-pdo_mysql php5-pdo_sqlite php5-gettext php5-xmlreader php5-xmlrpc php5-bz2 php5-memcache php5-mssql php5-iconv php5-pdo_dblib php5-curl php5-ctype" && \
apk --update add ${build_pkgs} ${runtime_pkgs} ${php_pkgs} && \
cd /tmp && \
mkdir unzip && \
wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/08a395c66e42.zip && \
Expand Down Expand Up @@ -46,6 +47,8 @@ RUN \
&& make && \
make install

RUN sed -i -e "s/include/;include/g" /etc/php5/php-fpm.conf

# Lay down the configuration templates
ADD confd-files/00-upstream.toml.toml \
/etc/confd/conf.d/00-upstream.toml.toml
Expand Down Expand Up @@ -73,6 +76,19 @@ ADD nginx-files/00-upstream-placeholder \
ADD nginx.sh /etc/sv/nginx/run
RUN chmod +x /etc/sv/nginx/run

RUN mkdir -pv /etc/sv/php-fpm && \
chmod 2775 /etc/sv/php-fpm && \
ln -sv /etc/sv/php-fpm /service

ADD php-fpm.sh /tmp
RUN chmod +x /tmp/php-fpm.sh

ADD php-fpm2.sh /etc/sv/php-fpm/run
RUN chmod +x /etc/sv/php-fpm/run

ADD ui /etc/nginx/html
ADD mime.types /etc/nginx

# Override the confd start script
ADD confd.sh /etc/sv/confd/run
RUN chmod +x /etc/sv/confd/run
Expand Down
10 changes: 10 additions & 0 deletions ContainerCloud/images/rolling-router-sticky-sessions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ Four service discovery keys are required for this implementation:

The router configuration is based on NGINX. The NGINX configuration files need to dynamically change when containers are deployed in OCCS. Confd provides the mechanism to watch service discovery keys in OCCS and generate dynamic configuraiton files for NGINX.

### Management UI in port 8080

Router configuration can also be done via an interactive management UI.

The management UI listens on port 8080 in the container. When running the container, map some port, e.g. 8080, to port 8080 in the container.

### Virtual Host

The [nginx-files/99-app](./nginx-files/99-app) file defines the virtual host that will proxy to the backend services.
Expand All @@ -75,3 +81,7 @@ Second, Confd automatically uses the generated files to generate a new file. The
NGINX's frontend listens on port 80 in the container. When running the container, map some port, e.g. 8000, to port 80 in the container.

Once the image is up and running, you can then access the frontend by navigating to http://mgr:8000 (where *mgr* is the host or IP address of the host running your router container, and port 8000 is the host port mapped to port 80 in the container).

The management UI listens on port 8080 in the container. When running the container, map some port, e.g. 8080, to port 8080 in the container.

Once the image is up and running, you can then access the management UI by navigating to http://mgr:8080 (where *mgr* is the host or IP address of the host running your router container, and port 8080 is the host port mapped to port 8080 in the container).
48 changes: 48 additions & 0 deletions ContainerCloud/images/rolling-router-sticky-sessions/mime.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
types {
text/html html htm shtml;
text/css css;
text/xml xml rss;
image/gif gif;
image/jpeg jpeg jpg;
application/x-javascript js;
text/plain txt;
text/x-component htc;
text/mathml mml;
image/png png;
image/x-icon ico;
image/x-jng jng;
image/vnd.wap.wbmp wbmp;
application/java-archive jar war ear;
application/mac-binhex40 hqx;
application/pdf pdf;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/zip zip;
application/octet-stream deb;
application/octet-stream bin exe dll;
application/octet-stream dmg;
application/octet-stream eot;
application/octet-stream iso img;
application/octet-stream msi msp msm;
audio/mpeg mp3;
audio/x-realaudio ra;
video/mpeg mpeg mpg;
video/quicktime mov;
video/x-flv flv;
video/x-msvideo avi;
video/x-ms-wmv wmv;
video/x-ms-asf asx asf;
video/x-mng mng;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@

server {
listen 8080;
root /etc/nginx/html;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}

server {
listen 80;
location / {
proxy_pass http://rollingservices;
proxy_pass http://rollingservices;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ events {
}

http {
include /etc/nginx/sites-enabled/*;
include /etc/nginx/sites-enabled/*;

include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# start php-fpm service and don't run this again

/usr/bin/php-fpm

sv down php-fpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

# run the script below to start php-fpm service

exec /tmp/php-fpm.sh
97 changes: 97 additions & 0 deletions ContainerCloud/images/rolling-router-sticky-sessions/ui/REST.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

if($_SERVER['REQUEST_METHOD'] == POST)
{
$token = $_POST['bearer'];
$host = $_POST['host'];
$url = $_POST['url'];
$method = $_POST['method'];
$data = $_POST['data'];

if(!$token || !$host || !$url || !$method)
{
$token = $argv[1];
$host = $argv[2];
$url = $argv[3];
$method = $argv[4];
$data = $argv[5];
}

if(!$token || !$host || !$url || !$method)
{
http_response_code(400);
echo "Please use POST parameters: bearer host url method [data]\n";
echo "Received:\n";
echo $_POST['bearer'] . "\n";
echo $_POST['host'] . "\n";
echo $_POST['url'] . "\n";
echo $_POST['method'] . "\n";
echo $_POST['data'] . "\n";
exit;
}

$auth = 'Bearer ' . $token;
$curl = curl_init();
$headers = ['Authorization: ' . $auth ];

if($method == 'POST')
{
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://' . $host . $url,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_FAILONERROR => 1,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data
));
} else if($method == 'PUT') {
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://' . $host . $url,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_FAILONERROR => 1,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => $data
));
} else if($method == 'DELETE') {
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://' . $host . $url,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_FAILONERROR => 1,
CURLOPT_CUSTOMREQUEST => 'DELETE'
));
} else {
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://' . $host . $url,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_FAILONERROR => 1
));
}

$resp = curl_exec($curl);
if($errno = curl_errno($curl)) {
$error_message = curl_strerror($errno);
curl_close($curl);
http_response_code(400);
echo $error_message . "\n";
echo $_POST['bearer'] . "\n";
echo $_POST['host'] . "\n";
echo $_POST['url'] . "\n";
echo $_POST['method'] . "\n";
echo $_POST['data'] . "\n";
var_dump($headers);
} else {
curl_close($curl);
echo $resp;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var app = angular
.module('rollingRouter', [
'ngRoute',
])

.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: '../views/setup.html',
controller: 'rollingRouterController'
})
.when('/manage', {
templateUrl: '../views/manage.html',
controller: 'rollingRouterController'
})
.otherwise({
redirectTo: '/'
});

});
Loading

0 comments on commit ca72955

Please sign in to comment.