custom proxy domain - #188
Conversation
- Added support for dynamic Traefik rules in mail, proxy, and tracing services using environment variables. - Implemented a new CertificateDownloader class for downloading certificates from specified URLs. - Introduced ProxyDomainCommand for managing proxy domains, including add, update, remove, and import functionalities. - Enhanced ProxyDomainConfiguration to handle domain normalization and conflict checks. - Updated init scripts for mail, proxy, and tracing services to utilize new domain management features. - Added tests for ProxyDomainCommand and ProxyRuntimeCommand to ensure proper functionality of domain management and TLS configurations.
…LS filenames and registry checks
…e conflict handling in domain commands
| touch .flag-built | ||
| else | ||
| run docker-compose -p my127ws-logger start | ||
| run docker-compose -p my127ws-logger up -d |
There was a problem hiding this comment.
start would not pick up the new generated Traefik rule.
Logger now writes TRAEFIK_KIBANA_RULE into .env before enabling the service. That value is used inside the Compose labels:
labels:
- traefik.enable=true
- traefik.http.routers.kibana.rule=${TRAEFIK_KIBANA_RULE}
docker-compose up -d reconciles the Compose project: if the interpolated label changed, it recreates the affected container; if nothing changed, it is effectively a start/no-op.
…ement file writing
| echo -ne "\\033[1E" >&2 | ||
| } | ||
|
|
||
| updateEnvGeneratedKey() |
There was a problem hiding this comment.
updates one generated key in a .env file.
It rewrites the file by removing any existing line that starts with the same KEY=, preserves all other lines, then appends the new KEY=value at the end.
| use my127\Console\Usage\Input; | ||
| use Symfony\Component\Yaml\Yaml; | ||
|
|
||
| class ProxyDomainCommand |
There was a problem hiding this comment.
ProxyDomainCommand manages the registered proxy-domain data.
It handles user-facing registry operations such as:
- list domains
- add domain
- update domain
- remove domain
- import domains
There was a problem hiding this comment.
Supporting multiple domains seems quite complex.
I wonder if we could keep it down to one with a custom option/env var file override the config file or folder to read from, which is more common in multi use tools
like docker compose -f alternate-compose.yml ...
DOCKER_COMPOSE_FILE=alternate-compose.yml docker compose ...
There was a problem hiding this comment.
ok, well it'd mean you couldn't run both proxies at the same time as they bind to same host port, but it's quite troubling this PR complexity, when ideally we should be lowering complexity
There was a problem hiding this comment.
I wanted to keep compatibility with my127.site
so that a developer could work on multiple projects: some that still use the my127.site while other projects might ported to a custom domain progressively.
|
|
||
| use my127\Console\Usage\Input; | ||
|
|
||
| class ProxyRuntimeCommand |
There was a problem hiding this comment.
ProxyRuntimeCommand turns the effective proxy-domain config into runtime artifacts used by services.
It handles generated output such as:
- Traefik host rules
- Traefik TLS YAML
- downloaded certificate files
|
|
||
| use Symfony\Component\Yaml\Yaml; | ||
|
|
||
| class ProxyDomainConfiguration |
There was a problem hiding this comment.
ProxyDomainConfiguration validates and normalizes proxy-domain definitions.
It handles:
- built-in default domain injection
- valid proxy-domain IDs
- valid bare DNS names
- required certificate/key URLs
- derived certificate/key filenames
- duplicate domain/filename conflict checks
|
|
||
| use Symfony\Component\Yaml\Yaml; | ||
|
|
||
| class ProxyDomainRegistry |
There was a problem hiding this comment.
ProxyDomainRegistry reads and writes the user-managed proxy-domain registry file.
It handles:
- reading domains from
~/.config/my127/workspace/proxy-domains.yml - writing registered domains back to that file
- creating the config directory when needed
- excluding the built-in
defaultdomain from the saved registry
|
|
||
| use Symfony\Component\Yaml\Yaml; | ||
|
|
||
| class ProxyRuntimeConfiguration |
There was a problem hiding this comment.
ProxyRuntimeConfiguration converts proxy-domain config into Traefik runtime config.
It handles:
- generating Traefik
Host(...)rules for services - mapping services to host prefixes, such as
mail.orkibana. - generating Traefik TLS YAML
- pointing Traefik at local
/tls/*.crtand/tls/*.keyfiles
|
|
||
| namespace my127\Workspace\GlobalService\Proxy; | ||
|
|
||
| class CertificateDownloader |
There was a problem hiding this comment.
CertificateDownloader downloads configured certificate material onto disk.
It handles:
- resolving the TLS output directory
- downloading certificate/key URLs
- writing them using the configured local filenames
- cleaning up temporary files if a download fails
| { | ||
| return $this->attributes->getAttributeMetadata($key); | ||
| } | ||
|
|
There was a problem hiding this comment.
the function attributeMetadata is needed because domain update/remove must know whether the effective domain comes from proxy-domains.yml, given that it only edits proxy-domains.yml.
…RLs for certificates
| $serviceHostPrefix = [ | ||
| 'proxy' => '', | ||
| 'mail' => 'mail.', | ||
| 'logger' => 'kibana.', | ||
| 'tracing' => 'tracing.', | ||
| ]; |
There was a problem hiding this comment.
feels a bit centralised being here rather than in the services, not obvious to update this if a new service is created
There was a problem hiding this comment.
I agree. I can change the command so that no longer takes a service name.
Instead of:
global service proxy config rule <service>
it becomes:
global service proxy config rule [<host-prefix>]
So the proxy runtime no longer needs a centralized service => host prefix map. Each service passes the public hostname prefix it wants to expose:
mail -> config rule mail
logger -> config rule kibana
tracing -> config rule tracing
proxy -> config rule
This also means a future service can use any hostname prefix without having to update a centralised map, and the prefix does not need to match the service name.
would that me good for you?
…and add validation for invalid prefixes
…ificateDownloader
Summary
Adds configurable multi-domain support for the Global Proxy while keeping
my127.siteas the built-in default domain.Changes
~/.config/my127/workspace/proxy-domains.yml.ws global service proxy config domain ...commands for listing, adding, updating, removing, and importing domains..envvalues while keeping the existing Docker Compose service layout.Notes
my127.siteremains the default and is not persisted in the registry.Testing
vendor/bin/phpunit tests/Test/GlobalService/Proxy --testdoxphp -d phar.readonly=0 vendor/bin/phpunit --testdoxvendor/bin/phpstan analyse --memory-limit=1Gvendor/bin/php-cs-fixer fix --dry-run --diff --config=.php-cs-fixer.php src/GlobalService/Proxy tests/Test/GlobalService/Proxy