-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.php
More file actions
169 lines (147 loc) · 4.66 KB
/
test.php
File metadata and controls
169 lines (147 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/*
* example script for direct testing of the docker API
* e.g.
* https://webfactx.webfact.vptt.ch/sites/all/modules/custom/webfact/test.php
*/
# comment out the next line to enable tests
# this script not not be enabled permanently
#exit;
require_once '/var/www/html/sites/all/libraries/composer/autoload.php';
$client = new Docker\Http\DockerClient(array(), 'unix:///var/run/docker.sock');
$docker = new Docker\Docker($client);
$manager = $docker->getContainerManager();
$lookfor='vanilla2';
$container = $manager->find($lookfor);
## page header
$html = <<<END
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Twitter Bootstrap Version2.0 default form layout example</title>
<meta name="description" content="tests">
<link type="text/css" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" media="all" />
</head>
<body>
END;
echo $html;
/*
* example: list images with menu
*/
/*
$lookfor='vanilla2';
$imagemgr = $docker->getImageManager();
$images = $imagemgr->findAll();
$markup = "<h2>Images of $lookfor: </h2>";
$markup .= '<div class="container">';
foreach ($images as $image) {
if (! strcmp($lookfor, $image->getRepository())) {
$data=$imagemgr->inspect($image);
$imagename=$image->__toString();
#print("$imagename " . $data['Created'] . " " . $image->getID() . "\n");
$markup .= '<div class="row"><div class="span9"><p>'
. "$imagename "
. $data['Created'] . " ${data['Author']}, ${data['Comment']} \n"
. '</p></div><div class="span3">';
$html = <<<END
<!-- Bootstrap: Single button -->
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Action <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="/website/imres/8/$imagename">Restore now</a></li>
<li class="divider"></li>
<li><a href="/website/imdel/8/$imagename">Delete</a></li>
</ul>
</div>
END;
$markup .= $html . '</div></div>';;
}
}
$markup .= '</div>';
echo $markup;
*
*/
#header("Content-type: text/plain");
#disable_ob();
# Create + start a container
/*
if ($container) {
print("vanilla2: stop, remove \n");
$manager->stop($container)->remove($container);
}
$config = ['Image'=> 'boran/drupal',
'Hostname' => '[\'vanilla2\']',
'WorkingDir' => '/var/www/html',
#'Cmd' =>'git status',
];
$container= new Docker\Container($config);
$container->setName('vanilla2');
$config = [
'Cmd' =>'bash',
#'VolumesFrom' => '[\'drupal8003\']'
];
*/
/*
#$manager->create($container)->start($container, $config);
#print_r("Running=" . $container->getRuntimeInformations()['State']['Running']. "<br>");
print("create and wait for logs ...\n");
#print '<pre>';
try {
$manager->run($container, function($output, $type) { print $output; }, $config);
} catch (Exception $e) {
if ($e->hasResponse()) {
print($e->getResponse()->getReasonPhrase() .
" (error code " . $e->getResponse()->getStatusCode(). " ");
}
else {
print($e->getMessage());
}
}
#print '</pre><br>';
print_r("Running=" . $container->getRuntimeInformations()['State']['Running']. "<br>");
*/
/* real time logging
echo "<h3>'attach' logging for $lookfor</h3>";
echo "<pre>";
$manager->attach($container, function ($output, $type) {print($output);} , true)->getBody()->getContents();
echo "</pre>";
*/
#echo "Last 20 logs<br>";
#$logs=$manager->logs($container, false, true, true, false, 20);
#print_r($logs);
/* interact() test
*/
#echo "<h3>interact for $lookfor</h3>";
#$manager->interact($container);
## page bottom
$html = <<<END
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
</body>
</html>
END;
echo $html;
function disable_ob() {
ini_set('output_buffering', 'off');
ini_set('zlib.output_compression', false);
ini_set('implicit_flush', true);
ob_implicit_flush(true);
// Clear, and turn off output buffering
while (ob_get_level() > 0) {
// Get the curent level
$level = ob_get_level();
// End the buffering
ob_end_clean();
// If the current level has not changed, abort
if (ob_get_level() == $level) break;
}
// Disable apache output buffering/compression
if (function_exists('apache_setenv')) {
apache_setenv('no-gzip', '1');
apache_setenv('dont-vary', '1');
}
}
?>