Fettling.
This commit is contained in:
parent
23f1de698f
commit
2fb7319011
9 changed files with 1287 additions and 2 deletions
|
@ -17,6 +17,10 @@ runtimes:
|
||||||
- python@3.10.8
|
- python@3.10.8
|
||||||
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
|
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
|
||||||
lint:
|
lint:
|
||||||
|
disabled:
|
||||||
|
- trufflehog # Trufflehog duplicates gitleaks functionality.
|
||||||
|
- terrascan
|
||||||
|
- trivy
|
||||||
enabled:
|
enabled:
|
||||||
- gitleaks@8.18.2
|
- gitleaks@8.18.2
|
||||||
- markdownlint@0.40.0
|
- markdownlint@0.40.0
|
||||||
|
@ -25,8 +29,6 @@ lint:
|
||||||
- checkov@3.2.92
|
- checkov@3.2.92
|
||||||
- git-diff-check
|
- git-diff-check
|
||||||
- prettier@3.2.5
|
- prettier@3.2.5
|
||||||
- trivy@0.51.1
|
|
||||||
- trufflehog@3.76.2
|
|
||||||
- yamllint@1.35.1
|
- yamllint@1.35.1
|
||||||
definitions:
|
definitions:
|
||||||
- name: markdownlint
|
- name: markdownlint
|
||||||
|
|
31
Dockerfile
Normal file
31
Dockerfile
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# checkov:skip=CKV_DOCKER_3 user cannot be determined at this stage.
|
||||||
|
FROM php:nginx as connect-target
|
||||||
|
LABEL maintainer="Matthew Baggett <matthew@baggett.me>" \
|
||||||
|
org.label-schema.vcs-url="https://github.com/benzine-framework/docker-swarm-connectivity-tester" \
|
||||||
|
org.opencontainers.image.source="https://github.com/benzine-framework/docker-swarm-connectivity-tester"
|
||||||
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||||
|
RUN echo -e "#!/bin/bash\n\ntail -f /var/log/php8.2-fpm.log" > /etc/service/logs-phpfpm-error/run && \
|
||||||
|
chmod +x /etc/service/logs-phpfpm-error/run
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
HEALTHCHECK --interval=30s --timeout=3s \
|
||||||
|
CMD curl -f http://localhost/ping.php || exit 1
|
||||||
|
COPY ./public-target /app/public
|
||||||
|
|
||||||
|
# checkov:skip=CKV_DOCKER_3 user cannot be determined at this stage.
|
||||||
|
FROM php:nginx as connect-reporter
|
||||||
|
LABEL maintainer="Matthew Baggett <matthew@baggett.me>" \
|
||||||
|
org.label-schema.vcs-url="https://github.com/benzine-framework/docker-swarm-connectivity-tester" \
|
||||||
|
org.opencontainers.image.source="https://github.com/benzine-framework/docker-swarm-connectivity-tester"
|
||||||
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||||
|
RUN echo -e "#!/bin/bash\n\ntail -f /var/log/php8.2-fpm.log" > /etc/service/logs-phpfpm-error/run && \
|
||||||
|
chmod +x /etc/service/logs-phpfpm-error/run
|
||||||
|
WORKDIR /app
|
||||||
|
HEALTHCHECK --interval=30s --timeout=3s \
|
||||||
|
CMD curl -f http://localhost/ping.php || exit 1
|
||||||
|
COPY ./composer.* /app/
|
||||||
|
COPY ./vendor /app/vendor
|
||||||
|
RUN composer install -q
|
||||||
|
|
||||||
|
COPY ./public-reporter /app/public
|
||||||
|
|
20
composer.json
Normal file
20
composer.json
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"name": "benzine/swarm-connectivity-tester",
|
||||||
|
"type": "project",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Benzine\\SwarmConnectivityTester\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Matthew Baggett",
|
||||||
|
"email": "matthew@baggett.me"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"guzzlehttp/guzzle": "^7.8",
|
||||||
|
"vlucas/phpdotenv": "^5.6",
|
||||||
|
"kint-php/kint": "^5.1"
|
||||||
|
}
|
||||||
|
}
|
1140
composer.lock
generated
Normal file
1140
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
27
docker-compose.yml
Normal file
27
docker-compose.yml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
version: "3.8"
|
||||||
|
services:
|
||||||
|
alive-target:
|
||||||
|
deploy:
|
||||||
|
replicas: 3
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
target: connect-target
|
||||||
|
additional_contexts:
|
||||||
|
- php:nginx=docker-image://ghcr.io/benzine-framework/php:nginx-8.2
|
||||||
|
image: ghcr.io/benzine-framework/swarm-connectivity-tester:target
|
||||||
|
|
||||||
|
reporter:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
target: connect-reporter
|
||||||
|
additional_contexts:
|
||||||
|
- php:nginx=docker-image://ghcr.io/benzine-framework/php:nginx-8.2
|
||||||
|
image: ghcr.io/benzine-framework/swarm-connectivity-tester:reporter
|
||||||
|
ports:
|
||||||
|
- "127.0.0.6:8080:80"
|
||||||
|
environment:
|
||||||
|
TARGETS: "alive-target,dead-target"
|
||||||
|
DEBUG: "true"
|
||||||
|
volumes:
|
||||||
|
- ./:/app
|
||||||
|
- ./public-reporter:/app/public
|
52
public-reporter/index.php
Normal file
52
public-reporter/index.php
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use GuzzleHttp\Promise\Utils;
|
||||||
|
|
||||||
|
require_once("../vendor/autoload.php");
|
||||||
|
|
||||||
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . "/../");
|
||||||
|
$dotenv->safeLoad();
|
||||||
|
|
||||||
|
$targets = explode(",", $_ENV['TARGETS']);
|
||||||
|
# trim whitespace from each target
|
||||||
|
$targets = array_map('trim', $targets);
|
||||||
|
|
||||||
|
# For each $target, resolve the target to IP addresses
|
||||||
|
foreach($targets as $target) {
|
||||||
|
$targetIps[$target] = gethostbynamel($target) ?: [];
|
||||||
|
$targetIps[$target] = array_values($targetIps[$target]);
|
||||||
|
}
|
||||||
|
# For each $target, Create a guzzle request to get the status of each target
|
||||||
|
$guzzle = new GuzzleHttp\Client();
|
||||||
|
$promises = [];
|
||||||
|
foreach ($targets as $target) {
|
||||||
|
$url = "http://$target:80/";
|
||||||
|
$promises[$target] = $guzzle->getAsync($url);
|
||||||
|
}
|
||||||
|
# Wait for all the requests to complete
|
||||||
|
$responses = Utils::settle($promises)->wait();
|
||||||
|
$rollup = true;
|
||||||
|
$json = [];
|
||||||
|
foreach($responses as $target => $response) {
|
||||||
|
if(!isset($response['value']) || $response['value']->getStatusCode() != 200) {
|
||||||
|
$rollup = false;
|
||||||
|
if ($response['reason'] instanceof \Exception) {
|
||||||
|
$json[$target] = ['Status' => 'ERROR', 'Reason' => $response['reason']->getMessage()];
|
||||||
|
} else {
|
||||||
|
$json[$target] = ['Status' => "ERROR", 'Reason' => 'Unknown'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$json[$target] = json_decode($response['value']->getBody()->getContents(), true);
|
||||||
|
}
|
||||||
|
$json[$target]['IP'] = $targetIps[$target];
|
||||||
|
|
||||||
|
}
|
||||||
|
if(!$rollup) {
|
||||||
|
header("HTTP/1.0 500 Internal Server Error");
|
||||||
|
}
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
echo json_encode([
|
||||||
|
'Status' => $rollup ? "OK" : "ERROR",
|
||||||
|
'Hostname' => gethostname(),
|
||||||
|
'Targets' => $json,
|
||||||
|
]);
|
3
public-reporter/ping.php
Normal file
3
public-reporter/ping.php
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
echo json_encode(['Pong',]);
|
7
public-target/index.php
Normal file
7
public-target/index.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
echo json_encode([
|
||||||
|
'Status' => 'OK',
|
||||||
|
'Hostname' => gethostname(),
|
||||||
|
]);
|
3
public-target/ping.php
Normal file
3
public-target/ping.php
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
echo json_encode(['Pong',]);
|
Loading…
Reference in a new issue