Skip to content

Commit

Permalink
split target host port and no subdomain in proxymode
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Yves <7360784+docjyJ@users.noreply.github.com>
  • Loading branch information
docjyJ committed Jul 14, 2024
1 parent cbfd69f commit 5737873
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 36 deletions.
10 changes: 8 additions & 2 deletions Containers/apache/caddyfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ function template_loop_route {
IFS=',' read -ra array <<< "$1"
ROUTE="${array[0]}"
URI_STRIP_PREFIX="${array[1]}"
TARGET="${array[2]}"
TARGET_HOST="${array[2]}"
TARGET_PORT="${array[3]}"

cat << CADDY
route $(test -z "$ROUTE" || echo "$ROUTE/* "){
$([ "$URI_STRIP_PREFIX" == "1" ] && echo "uri strip_prefix $ROUTE")
reverse_proxy $TARGET
reverse_proxy $TARGET_HOST:$TARGET_PORT
}
CADDY
}
Expand All @@ -55,6 +56,11 @@ function template_loop_subdomain {
SUBDOMAIN="${array[0]}"
ROUTES="${array[1]}"

if [ -z "$TRUSTED_DOMAINS" ] && [ -n "$SUBDOMAIN" ]; then
# Ignore subdomains if in proxy mode
exit 0
fi

cat << CADDY
$(echo "$TRUSTED_DOMAINS" | tr ',' '\n' | sed "s/.*/$PROTOCOL:\/\/$SUBDOMAIN&:$APACHE_PORT/" | sed '$ ! s/$/,/') {
Expand Down
9 changes: 1 addition & 8 deletions community-containers/lldap/lldap.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@
"image_tag": "v0-alpine",
"internal_port": "17170",
"restart": "unless-stopped",
"ports": [
{
"ip_binding": "%APACHE_IP_BINDING%",
"port_number": "17170",
"protocol": "tcp"
}
],
"caddy_routes": [
{
"route": "",
"sub_domain": "ldap.",
"target": "nextcloud-aio-lldap:17170",
"target_port": "17170",
"uri_strip_prefix": false
}
],
Expand Down
9 changes: 1 addition & 8 deletions community-containers/nocodb/nocodb.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@
"image_tag": "%AIO_CHANNEL%",
"internal_port": "10028",
"restart": "unless-stopped",
"ports": [
{
"ip_binding": "%APACHE_IP_BINDING%",
"port_number": "10028",
"protocol": "tcp"
}
],
"caddy_routes": [
{
"route": "",
"sub_domain": "tables.",
"target": "nextcloud-aio-nocodb:10028",
"target_port": "10028",
"uri_strip_prefix": false
}
],
Expand Down
7 changes: 1 addition & 6 deletions community-containers/stalwart/stalwart.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,13 @@
"ip_binding": "",
"port_number": "4190",
"protocol": "tcp"
},
{
"ip_binding": "%APACHE_IP_BINDING%",
"port_number": "10003",
"protocol": "tcp"
}
],
"caddy_routes": [
{
"route": "",
"sub_domain": "mail.",
"target": "nextcloud-aio-stalwart:10003",
"target_port": "10003",
"uri_strip_prefix": false
}
],
Expand Down
4 changes: 2 additions & 2 deletions php/containers-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@
"type": "string",
"pattern": "^([a-z-]*\\.)*$"
},
"target": {
"target_port": {
"type": "string",
"pattern": "^nextcloud-aio-[a-z-]+:[0-9]+$"
"pattern": "^[0-9]{1,5})$"
},
"uri_strip_prefix": {
"type": "boolean"
Expand Down
10 changes: 5 additions & 5 deletions php/containers.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
{
"route": "/push",
"sub_domain": "",
"target": "nextcloud-aio-notify-push:7867",
"target_port": "7867",
"uri_strip_prefix": true
}
],
Expand Down Expand Up @@ -336,19 +336,19 @@
{
"route": "/browser",
"sub_domain": "",
"target": "nextcloud-aio-collabora:9980",
"target_port": "9980",
"uri_strip_prefix": false
},
{
"route": "/hosting",
"sub_domain": "",
"target": "nextcloud-aio-collabora:9980",
"target_port": "9980",
"uri_strip_prefix": false
},
{
"route": "/cool",
"sub_domain": "",
"target": "nextcloud-aio-collabora:9980",
"target_port": "9980",
"uri_strip_prefix": false
}
],
Expand Down Expand Up @@ -405,7 +405,7 @@
{
"route": "/standalone-signaling",
"sub_domain": "",
"target": "nextcloud-aio-talk:8081",
"target_port": "8081",
"uri_strip_prefix": true
}
],
Expand Down
9 changes: 6 additions & 3 deletions php/src/Container/ContainerCaddyRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
class ContainerCaddyRoute {
public string $route;
public string $subDomain;
public string $target;
public string $target_host;
public string $target_port;
public string $uriStripPrefix;

public function __construct(
string $route,
string $subDomain,
string $target,
string $target_host,
string $target_port,
string $uriStripPrefix
) {
$this->route = $route;
$this->subDomain = $subDomain;
$this->target = $target;
$this->target_host = $target_host;
$this->target_port = $target_port;
$this->uriStripPrefix = $uriStripPrefix;
}
}
2 changes: 1 addition & 1 deletion php/src/Container/ContainerCaddyRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function GetFormatedEnv() : string {
if (!array_key_exists($subDomain, $caddyRouteBySubDomain)) {
$caddyRouteBySubDomain[$subDomain] = [];
}
$caddyRouteBySubDomain[$subDomain][] = $caddyRoute->route.",".$caddyRoute->uriStripPrefix.",".$caddyRoute->target ;
$caddyRouteBySubDomain[$subDomain][] = $caddyRoute->route.",".$caddyRoute->uriStripPrefix.",".$caddyRoute->target_host.",".$caddyRoute->target_port ;
}

$subDomainGroups = [];
Expand Down
3 changes: 2 additions & 1 deletion php/src/ContainerDefinitionFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ private function GetDefinition(): array
new ContainerCaddyRoute(
$value['route'],
$value['sub_domain'],
$value['target'],
$entry['container_name'],
$value['target_port'],
$value['uri_strip_prefix']
)
);
Expand Down

0 comments on commit 5737873

Please sign in to comment.