Last active
August 29, 2015 14:25
-
-
Save ebuildy/27694710e8ca13f0234f to your computer and use it in GitHub Desktop.
PhpMyAdmin on Rancher: Auto mysql server Docker container discovery. This will use Rancher API to browse the containers list, and search for container who expose 3306 port or has label "type:mysql"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$buffer = json_decode(file_get_contents('http://*****:*******@********/v1/containers'), true); | |
$containers = $buffer['data']; | |
$mysqlContainers = []; | |
$i = 0; | |
foreach($containers as $container) | |
{ | |
$valid = false; | |
if (!empty($container['ports'])) | |
{ | |
foreach ($container['ports'] as $port) | |
{ | |
if ($port === '3306/tcp') | |
{ | |
$valid = true; | |
break; | |
} | |
} | |
} | |
if (!empty($container['labels'])) | |
{ | |
foreach ($container['labels'] as $label => $value) | |
{ | |
if ($label === 'type' && $value === 'mysql') | |
{ | |
$valid = true; | |
break; | |
} | |
} | |
} | |
if ($valid) | |
{ | |
$i++; | |
/* Authentication type */ | |
$cfg['Servers'][$i]['auth_type'] = 'cookie'; | |
/* Server parameters */ | |
$cfg['Servers'][$i]['host'] = $container['primaryIpAddress']; | |
$cfg['Servers'][$i]['verbose'] = $container['name'] . ' (' . $container['primaryIpAddress'] . ')'; | |
$cfg['Servers'][$i]['connect_type'] = 'tcp'; | |
$cfg['Servers'][$i]['compress'] = false; | |
$cfg['Servers'][$i]['AllowNoPassword'] = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment