Skip to content

Commit 405503d

Browse files
committed
feat(reverse-proxy-ip): now possible to pass and handle reverse-proxy-ip host lines
- update README.md - fix some generated files and docker spec from real world
1 parent e8f7cf7 commit 405503d

19 files changed

+1046
-938
lines changed

.jane-openapi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
declare(strict_types=1);
33

44
return [
5-
'openapi-file' => __DIR__ . '/spec/docker-v1.48-oa-v3.0.1.yaml',
5+
'openapi-file' => __DIR__ . '/spec/docker-v1.48-patched.yaml',
66
'namespace' => 'WebProject\DockerApi\Library\Generated',
77
'directory' => __DIR__ . '/generated',
88
'strict' => true,

.php-cs-fixer.cache

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22
> A PHP docker API client with a cli tool to sync your hosts file with running docker containers to add hostnames for every network
33
> (inspired by https://github.com/iamluc/docker-hostmanager)
44
5-
## todo:
6-
- [ ] add example usage to readme
7-
- [ ] explain it
5+
## Example
6+
```shell
7+
bin/docker-api --help
8+
9+
#
10+
## add --hosts_file=/etc/hosts and run with sudo to sync file OR see result in ./tmp-hosts if not
11+
#
12+
13+
# use php 8.3 with symfony cli
14+
symfony php bin/docker-api synchronize-hosts -v --reverse-proxy-host-ip=172.16.238.100
15+
# on php 8.3+
16+
php bin/docker-api synchronize-hosts -v --reverse-proxy-host-ip=172.16.238.100
17+
```
818

919
## hosts file (/etc/hosts) sync
1020
```shell
@@ -14,16 +24,24 @@ docker run -d --name docker-hostfile-sync --restart=always -v /var/run/docker.so
1424
## Example of hosts file
1525
This is based on 2 containers
1626
* container 1 (jwilder-proxy) has multiple aliases
17-
* container 2 (my-dev-server) has multiple aliases, an alias with a "normal" url (actual.realFancyUrl.tld set on the proxyNet network)
27+
* container 2 (actual_server) has multiple aliases, an alias with a "normal" url (actual.realFancyUrl.tld set on the proxyNet network)
1828

1929

2030
```text
2131
[...your stuff]
2232
2333
## docker-hostsfile-sync
24-
172.16.238.100 jwilder-proxy.docker jwilder-proxy.proxyNet jwilder.proxyNet proxy.local
34+
# container - reverse proxy
35+
172.16.238.100 proxy.local
36+
37+
# container - default network
38+
172.19.0.2 actual_server.docker actual_server.actual-server_default
39+
40+
# container - proxyNet network (reverse proxy net)
41+
172.16.238.2 actual_server.proxyNet
2542
26-
172.19.0.2 my-dev-server.docker my-dev-server.my-dev-server_default
27-
172.16.238.2 my-dev-server.proxyNet actual.realFancyUrl.tld
43+
# reverse proxy entry from container env var: DOMAIN_NAME (multiple possible with)
44+
# and reverse proxy entry from container network alias (with dot like "actual.my-reverse-proxy-url.xyz")
45+
172.16.238.100 actual.my-reverse-proxy-url.xyz dev-actual.my-reverse-proxy-url.xyz
2846
## docker-hostsfile-sync-end
2947
```

generated/Model/HealthcheckResult.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public function isInitialized($property): bool
2222
* Date and time at which this check started in
2323
* [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format with nano-seconds.
2424
*
25-
* @var DateTime
25+
* @var DateTime|null
2626
*/
2727
protected $start;
2828
/**
2929
* Date and time at which this check ended in
3030
* [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format with nano-seconds.
3131
*
32-
* @var string
32+
* @var string|null
3333
*/
3434
protected $end;
3535
/**
@@ -40,7 +40,7 @@ public function isInitialized($property): bool
4040
* - `2` reserved (considered unhealthy)
4141
* - other values: error running probe
4242
*
43-
* @var int
43+
* @var int|null
4444
*/
4545
protected $exitCode;
4646
/**
@@ -54,9 +54,9 @@ public function isInitialized($property): bool
5454
* Date and time at which this check started in
5555
* [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format with nano-seconds.
5656
*
57-
* @return DateTime
57+
* @return DateTime|null
5858
*/
59-
public function getStart(): DateTime
59+
public function getStart(): ?DateTime
6060
{
6161
return $this->start;
6262
}
@@ -65,11 +65,11 @@ public function getStart(): DateTime
6565
* Date and time at which this check started in
6666
* [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format with nano-seconds.
6767
*
68-
* @param DateTime $start
68+
* @param DateTime|null $start
6969
*
7070
* @return self
7171
*/
72-
public function setStart(DateTime $start): self
72+
public function setStart(?DateTime $start): self
7373
{
7474
$this->initialized['start'] = true;
7575
$this->start = $start;
@@ -81,9 +81,9 @@ public function setStart(DateTime $start): self
8181
* Date and time at which this check ended in
8282
* [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format with nano-seconds.
8383
*
84-
* @return string
84+
* @return string|null
8585
*/
86-
public function getEnd(): string
86+
public function getEnd(): ?string
8787
{
8888
return $this->end;
8989
}
@@ -92,11 +92,11 @@ public function getEnd(): string
9292
* Date and time at which this check ended in
9393
* [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format with nano-seconds.
9494
*
95-
* @param string $end
95+
* @param string|null $end
9696
*
9797
* @return self
9898
*/
99-
public function setEnd(string $end): self
99+
public function setEnd(?string $end): self
100100
{
101101
$this->initialized['end'] = true;
102102
$this->end = $end;
@@ -112,9 +112,9 @@ public function setEnd(string $end): self
112112
* - `2` reserved (considered unhealthy)
113113
* - other values: error running probe
114114
*
115-
* @return int
115+
* @return int|null
116116
*/
117-
public function getExitCode(): int
117+
public function getExitCode(): ?int
118118
{
119119
return $this->exitCode;
120120
}
@@ -127,11 +127,11 @@ public function getExitCode(): int
127127
* - `2` reserved (considered unhealthy)
128128
* - other values: error running probe
129129
*
130-
* @param int $exitCode
130+
* @param int|null $exitCode
131131
*
132132
* @return self
133133
*/
134-
public function setExitCode(int $exitCode): self
134+
public function setExitCode(?int $exitCode): self
135135
{
136136
$this->initialized['exitCode'] = true;
137137
$this->exitCode = $exitCode;

generated/Model/HostConfig.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public function isInitialized($property): bool
324324
* If a container's port is mapped for multiple protocols, separate entries
325325
* are added to the mapping table.
326326
*
327-
* @var array<string, list<PortBinding>>|null
327+
* @var array<string, mixed>|null
328328
*/
329329
protected $portBindings;
330330
/**
@@ -417,7 +417,7 @@ public function isInitialized($property): bool
417417
/**
418418
* A list of DNS search domains.
419419
*
420-
* @var list<string>
420+
* @var list<string>|null
421421
*/
422422
protected $dnsSearch;
423423
/**
@@ -1643,7 +1643,7 @@ public function setNetworkMode(string $networkMode): self
16431643
* If a container's port is mapped for multiple protocols, separate entries
16441644
* are added to the mapping table.
16451645
*
1646-
* @return array<string, list<PortBinding>>|null
1646+
* @return array<string, mixed>|null
16471647
*/
16481648
public function getPortBindings(): ?iterable
16491649
{
@@ -1658,7 +1658,7 @@ public function getPortBindings(): ?iterable
16581658
* If a container's port is mapped for multiple protocols, separate entries
16591659
* are added to the mapping table.
16601660
*
1661-
* @param array<string, list<PortBinding>>|null $portBindings
1661+
* @param array<string, mixed>|null $portBindings
16621662
*
16631663
* @return self
16641664
*/
@@ -2003,21 +2003,21 @@ public function setDnsOptions(?array $dnsOptions): self
20032003
/**
20042004
* A list of DNS search domains.
20052005
*
2006-
* @return list<string>
2006+
* @return list<string>|null
20072007
*/
2008-
public function getDnsSearch(): array
2008+
public function getDnsSearch(): ?array
20092009
{
20102010
return $this->dnsSearch;
20112011
}
20122012

20132013
/**
20142014
* A list of DNS search domains.
20152015
*
2016-
* @param list<string> $dnsSearch
2016+
* @param list<string>|null $dnsSearch
20172017
*
20182018
* @return self
20192019
*/
2020-
public function setDnsSearch(array $dnsSearch): self
2020+
public function setDnsSearch(?array $dnsSearch): self
20212021
{
20222022
$this->initialized['dnsSearch'] = true;
20232023
$this->dnsSearch = $dnsSearch;

generated/Model/NetworkSettings.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function isInitialized($property): bool
6161
* If a container's port is mapped for multiple protocols, separate entries
6262
* are added to the mapping table.
6363
*
64-
* @var array<string, list<PortBinding>>|null
64+
* @var array<string, mixed>|null
6565
*/
6666
protected $ports;
6767
/**
@@ -346,7 +346,7 @@ public function setLinkLocalIPv6PrefixLen(?int $linkLocalIPv6PrefixLen): self
346346
* If a container's port is mapped for multiple protocols, separate entries
347347
* are added to the mapping table.
348348
*
349-
* @return array<string, list<PortBinding>>|null
349+
* @return array<string, mixed>|null
350350
*/
351351
public function getPorts(): ?iterable
352352
{
@@ -361,7 +361,7 @@ public function getPorts(): ?iterable
361361
* If a container's port is mapped for multiple protocols, separate entries
362362
* are added to the mapping table.
363363
*
364-
* @param array<string, list<PortBinding>>|null $ports
364+
* @param array<string, mixed>|null $ports
365365
*
366366
* @return self
367367
*/

generated/Normalizer/ContainerConfigNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a
146146
}
147147
if (array_key_exists('Entrypoint', $data)) {
148148
$values_4 = [];
149-
foreach ($data['Entrypoint'] as $value_4) {
149+
foreach ($data['Entrypoint'] ?? [] as $value_4) {
150150
$values_4[] = $value_4;
151151
}
152152
$object->setEntrypoint($values_4);

generated/Normalizer/HealthcheckResultNormalizer.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,23 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a
5151
if (null === $data || false === is_array($data)) {
5252
return $object;
5353
}
54-
if (array_key_exists('Start', $data)) {
55-
$object->setStart(DateTime::createFromFormat('Y-m-d\TH:i:sP', $data['Start']));
54+
if (array_key_exists('Start', $data) && null !== $data['Start']) {
55+
$object->setStart(DateTime::createFromFormat('Y-m-d\TH:i:sP', $data['Start']) ?: new DateTime($data['Start']));
5656
unset($data['Start']);
57+
} elseif (array_key_exists('Start', $data) && null === $data['Start']) {
58+
$object->setStart(null);
5759
}
58-
if (array_key_exists('End', $data)) {
60+
if (array_key_exists('End', $data) && null !== $data['End']) {
5961
$object->setEnd($data['End']);
6062
unset($data['End']);
63+
} elseif (array_key_exists('End', $data) && null === $data['End']) {
64+
$object->setEnd(null);
6165
}
62-
if (array_key_exists('ExitCode', $data)) {
66+
if (array_key_exists('ExitCode', $data) && null !== $data['ExitCode']) {
6367
$object->setExitCode($data['ExitCode']);
6468
unset($data['ExitCode']);
69+
} elseif (array_key_exists('ExitCode', $data) && null === $data['ExitCode']) {
70+
$object->setExitCode(null);
6571
}
6672
if (array_key_exists('Output', $data)) {
6773
$object->setOutput($data['Output']);
@@ -80,7 +86,7 @@ public function normalize(mixed $object, ?string $format = null, array $context
8086
{
8187
$data = [];
8288
if ($object->isInitialized('start') && null !== $object->getStart()) {
83-
$data['Start'] = $object->getStart()?->format('Y-m-d\TH:i:sP');
89+
$data['Start'] = $object->getStart()->format('Y-m-d\TH:i:sP');
8490
}
8591
if ($object->isInitialized('end') && null !== $object->getEnd()) {
8692
$data['End'] = $object->getEnd();
@@ -138,17 +144,23 @@ public function denormalize($data, $type, $format = null, array $context = [])
138144
if (null === $data || false === is_array($data)) {
139145
return $object;
140146
}
141-
if (array_key_exists('Start', $data)) {
147+
if (array_key_exists('Start', $data) && null !== $data['Start']) {
142148
$object->setStart(DateTime::createFromFormat('Y-m-d\TH:i:sP', $data['Start']));
143149
unset($data['Start']);
150+
} elseif (array_key_exists('Start', $data) && null === $data['Start']) {
151+
$object->setStart(null);
144152
}
145-
if (array_key_exists('End', $data)) {
153+
if (array_key_exists('End', $data) && null !== $data['End']) {
146154
$object->setEnd($data['End']);
147155
unset($data['End']);
156+
} elseif (array_key_exists('End', $data) && null === $data['End']) {
157+
$object->setEnd(null);
148158
}
149-
if (array_key_exists('ExitCode', $data)) {
159+
if (array_key_exists('ExitCode', $data) && null !== $data['ExitCode']) {
150160
$object->setExitCode($data['ExitCode']);
151161
unset($data['ExitCode']);
162+
} elseif (array_key_exists('ExitCode', $data) && null === $data['ExitCode']) {
163+
$object->setExitCode(null);
152164
}
153165
if (array_key_exists('Output', $data)) {
154166
$object->setOutput($data['Output']);
@@ -170,7 +182,7 @@ public function normalize($object, $format = null, array $context = [])
170182
{
171183
$data = [];
172184
if ($object->isInitialized('start') && null !== $object->getStart()) {
173-
$data['Start'] = $object->getStart()?->format('Y-m-d\TH:i:sP');
185+
$data['Start'] = $object->getStart()->format('Y-m-d\TH:i:sP');
174186
}
175187
if ($object->isInitialized('end') && null !== $object->getEnd()) {
176188
$data['End'] = $object->getEnd();

0 commit comments

Comments
 (0)