Debuggin' whats wrong with service detection.

This commit is contained in:
Greyscale 2024-06-25 15:19:09 +02:00
parent 02e1cd19de
commit a909cba332
No known key found for this signature in database
GPG key ID: 74BAFF55434DA4B2
2 changed files with 26 additions and 5 deletions

View file

@ -6,6 +6,13 @@ services:
build:
context: .
target: loadbalancer
args:
MAINTAINER: "Test <test@oneupsales.co.uk>"
SOURCE_URL: "https://github.com/doesntmatter"
GIT_SHA: "1234"
GIT_BUILD_ID: "test"
GIT_COMMIT_MESSAGE: "testy mctestface"
BUILD_DATE: "1970-01-01"
additional_contexts:
- php:cli=docker-image://ghcr.io/benzine-framework/php:cli-8.2
volumes:

View file

@ -8,16 +8,19 @@ use AdamBrett\ShellWrapper\Command\Builder as CommandBuilder;
use AdamBrett\ShellWrapper\Runners\Exec;
use Aws\S3\S3Client;
use Bouncer\Logger\AbstractLogger;
use Bouncer\Logger\Formatter;
use Bouncer\Logger\Logger;
use Bouncer\Settings\Settings;
use GuzzleHttp\Client as Guzzle;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\ServerException;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
use League\Flysystem\FileAttributes;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
use League\Flysystem\Local\LocalFilesystemAdapter;
use Bouncer\Logger\Logger;
use Bouncer\Logger\Formatter;
use Monolog\Processor;
use Spatie\Emoji\Emoji;
use Symfony\Component\Yaml\Yaml;
use Twig\Environment as Twig;
@ -25,9 +28,6 @@ use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Loader\FilesystemLoader as TwigLoader;
use GuzzleHttp\Exception\GuzzleException;
use Monolog\Processor;
use Bouncer\Settings\Settings;
class Bouncer
{
@ -186,6 +186,7 @@ class Bouncer
public function findContainersContainerMode(): array
{
$bouncerTargets = [];
$this->logger->warning('Interrogating CONTAINERS for BOUNCER_* environment variables.', ['emoji' => Emoji::magnifyingGlassTiltedLeft()]);
$containers = json_decode($this->docker->request('GET', 'containers/json')->getBody()->getContents(), true);
foreach ($containers as $container) {
@ -262,11 +263,14 @@ class Bouncer
}
}
$this->logger->warning('Interrogating CONTAINERS for BOUNCER_* environment variables found {count} containers.', ['emoji' => Emoji::magnifyingGlassTiltedLeft(), 'count' => count($validBouncerTargets)]);
return $validBouncerTargets;
}
public function findContainersSwarmMode(): array
{
$this->logger->warning('Interrogating SERVICES for BOUNCER_* environment variables.', ['emoji' => Emoji::magnifyingGlassTiltedLeft()]);
$bouncerTargets = [];
$services = json_decode($this->docker->request('GET', 'services')->getBody()->getContents(), true);
@ -365,6 +369,8 @@ class Bouncer
}
}
$this->logger->warning('Interrogating SERVICES for BOUNCER_* environment variables found {count} containers.', ['emoji' => Emoji::magnifyingGlassTiltedLeft(), 'count' => count($validBouncerTargets)]);
return $validBouncerTargets;
}
@ -670,6 +676,7 @@ class Bouncer
$this->logger->debug(' > Swarm mode is {enabled}.', ['emoji' => Emoji::honeybee(), 'enabled' => $this->isSwarmMode() ? 'enabled' : 'disabled']);
/** @var Target[] $targets */
$targets = array_values(
array_merge(
$this->findContainersContainerMode(),
@ -677,6 +684,13 @@ class Bouncer
)
);
foreach($targets as $target){
$this->logger->info('Found target {target}', ['emoji' => Emoji::magnifyingGlassTiltedLeft(), 'target' => $target->getName()]);
\Kint::dump(
$target->getDomains(),
);
}
// Use some bs to sort the targets by domain from right to left.
$sortedTargets = [];
foreach ($targets as $target) {