Useful version output

This commit is contained in:
Greyscale 2024-01-25 14:57:59 +01:00
parent 01633941f3
commit aa65d2630c
No known key found for this signature in database
GPG key ID: 74BAFF55434DA4B2
7 changed files with 59 additions and 18 deletions

View file

@ -47,7 +47,9 @@ jobs:
push: true
target: bouncer
build-args: |
GIT_SHA=${{ github.sha }}
GIT_SHA="${{ github.sha }}"
BUILD_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
GIT_COMMIT_MESSAGE="$(git log -1 --pretty=%B)"
tags: |
benzine/bouncer
ghcr.io/benzine-framework/bouncer:latest

View file

@ -1,9 +1,4 @@
FROM benzine/php:cli-8.1 as bouncer
ARG BUILD_DATE
ARG GIT_SHA
ENV BUILD_DATE=${BUILD_DATE} \
GIT_SHA=${GIT_SHA}
LABEL maintainer="Matthew Baggett <matthew@baggett.me>" \
org.label-schema.vcs-url="https://github.com/benzine-framework/docker" \
org.opencontainers.image.source="https://github.com/benzine-framework/docker"
@ -37,7 +32,10 @@ RUN apt-get -qq update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/lib/dpkg/status.old /var/cache/debconf/templates.dat /var/log/dpkg.log /var/log/lastlog /var/log/apt/*.log
# copy some default self-signed certs
COPY self-signed-certificates /certs
# Install runits for services
COPY nginx.runit /etc/service/nginx/run
COPY logs.runit /etc/service/nginx-logs/run
COPY bouncer.runit /etc/service/bouncer/run
@ -45,28 +43,40 @@ COPY bouncer.finish /etc/service/bouncer/finish
COPY logs-nginx-access.runit /etc/service/logs-nginx-access/run
COPY logs-nginx-error.runit /etc/service/logs-nginx-error/run
RUN chmod +x /etc/service/*/run /etc/service/*/finish
# Copy default nginx bits
COPY NginxDefault /etc/nginx/sites-enabled/default.conf
COPY Nginx-tweak.conf /etc/nginx/conf.d/tweak.conf
# Disable daemonising in nginx
RUN sed -i '1s;^;daemon off\;\n;' /etc/nginx/nginx.conf && \
sed -i 's|include /etc/nginx/sites-enabled/*|include /etc/nginx/sites-enabled/*.conf|g' /etc/nginx/nginx.conf && \
rm /etc/nginx/sites-enabled/default && \
rm -R /etc/nginx/sites-available
# Copy over vendored code plus install just in case
COPY vendor /app/vendor
COPY composer.* /app/
RUN composer install
# Copy over application code
COPY public /app/public
COPY bin /app/bin
COPY src /app/src
COPY templates /app/templates
RUN chmod +x /app/bin/bouncer
# Create some volumes for logs and certs
VOLUME /etc/letsencrypt
VOLUME /var/log/bouncer
RUN chmod +x /app/bin/bouncer && \
mkdir -p /var/log/bouncer
# stuff some envs from build
ARG BUILD_DATE
ARG GIT_SHA
ARG GIT_COMMIT_MESSAGE
ENV BUILD_DATE=${BUILD_DATE} \
GIT_SHA=${GIT_SHA} \
GIT_COMMIT_MESSAGE=${GIT_COMMIT_MESSAGE}
FROM benzine/php:nginx-8.1 as test-app-a
COPY ./test/public-web-a /app/public

View file

@ -6,8 +6,9 @@ fix: php-cs-fixer
build-n-push: fix
docker build \
--build-arg BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") \
--build-arg GIT_SHA=$(shell git rev-parse HEAD) \
--build-arg BUILD_DATE="$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--build-arg GIT_SHA="$(shell git rev-parse HEAD)" \
--build-arg GIT_COMMIT_MESSAGE="$(shell git log -1 --pretty=%B | head -n1)" \
--tag benzine/bouncer \
--tag ghcr.io/benzine-framework/bouncer \
--target bouncer \

View file

@ -16,6 +16,7 @@ These should not be confused.
| LOG_NAME | bouncer | | The name of the log file to write to |
| LOG_FILE | /var/log/bouncer/bouncer.log | | The path to the log file to write to |
| LOG_LEVEL | debug | info, debug, critical etc | The level of logging to write to the log file. See Monolog docs. |
| LOG_LEVEL_NAME_LENGTH | 4 | positive numbers | The length of the level name to be written to the log file. See Monolog docs. |
| LOG_LINE_FORMAT | [%datetime%] %level_name%: %channel%: %message% | | The format of the log line. See Monolog docs. |
| LOG_COLOUR | true | true, false | Whether to colourise the log output sent to stdout. | |

View file

@ -303,11 +303,11 @@ class Bouncer
public function run(): void
{
$gitHash = substr($this->environment['GIT_SHA'], 0, 7);
$this->logger->info('{emoji} Starting Bouncer (Build {git_sha})...', ['emoji' => Emoji::timerClock(), 'git_sha' => '#' . $gitHash]);
$buildDate = Carbon::parse($this->environment['BUILD_DATE']);
$this->logger->info('{emoji} Built on {build_date}, {build_ago}', ['emoji' => Emoji::redHeart(), 'build_date' => $buildDate->toDateTimeString(), 'build_ago' => $buildDate->ago()]);
$gitHash = substr($this->environment['GIT_SHA'], 0, 7);
$buildDate = Carbon::parse($this->environment['BUILD_DATE']);
$gitMessage = trim($this->environment['GIT_COMMIT_MESSAGE']);
$this->logger->info('{emoji} Starting Bouncer. Built on {build_date}, {build_ago}', ['emoji' => Emoji::redHeart(), 'build_date' => $buildDate->toDateTimeString(), 'build_ago' => $buildDate->ago()]);
$this->logger->info('{emoji} Build #{git_sha}: "{git_message}"', ['emoji' => Emoji::memo(), 'git_sha' => $gitHash, 'git_message' => $gitMessage]);
try {
$this->stateHasChanged();
@ -325,6 +325,11 @@ class Bouncer
{
foreach ($envs as $eKey => $eVal) {
switch ($eKey) {
case 'BOUNCER_NAME':
$bouncerTarget->setName($eVal);
break;
case 'BOUNCER_DOMAIN':
$domains = explode(',', $eVal);
array_walk($domains, function (&$domain, $key): void {

View file

@ -47,7 +47,7 @@ class Settings implements SettingsInterface
'path' => Settings::getEnvironment('LOG_FILE', '/var/log/bouncer/bouncer.log'),
'level' => Level::fromName(Settings::getEnvironment('LOG_LEVEL', 'DEBUG')),
'line_format' => Settings::getEnvironment('LOG_LINE_FORMAT', '[%datetime%] %level_name%: %channel%: %message%') . "\n",
'max_level_name_length' => 9,
'max_level_name_length' => Settings::getEnvironment('LOG_LEVEL_NAME_LENGTH', 4),
'coloured_output' => Settings::isEnabled('LOG_COLOUR', true),
],
];

View file

@ -4,12 +4,13 @@ declare(strict_types=1);
namespace Bouncer;
use Monolog\Logger;
use Bouncer\Logger\Logger;
use Spatie\Emoji\Emoji;
class Target
{
private string $id;
private ?string $name = null;
private array $domains;
private string $endpointHostnameOrIp;
private ?int $port = null;
@ -214,6 +215,7 @@ class Target
public function setDomains(array $domains): self
{
$this->domains = $domains;
$this->updateLogger();
return $this;
}
@ -273,7 +275,15 @@ class Target
public function getName()
{
return reset($this->domains);
return $this->name ?? reset($this->domains);
}
public function setName(string $name): self
{
$this->name = $name;
$this->updateLogger();
return $this;
}
public function isAllowNonSSL(): bool
@ -288,6 +298,18 @@ class Target
return $this;
}
public function getLogger(): Logger
{
return $this->logger;
}
public function updateLogger(): self
{
$this->logger = $this->logger->withName($this->getName());
return $this;
}
public function isEndpointValid(): bool
{
// Is it just an IP?