chore: always assume TRAEFIK_INSTANCE
points to host.docker.internal
This commit is contained in:
parent
79492a47c8
commit
5830244af0
1 changed files with 34 additions and 6 deletions
40
app.py
40
app.py
|
@ -2,6 +2,7 @@ import base64
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
|
import urllib3
|
||||||
from concurrent.futures import Future, ThreadPoolExecutor, wait as gather_futures
|
from concurrent.futures import Future, ThreadPoolExecutor, wait as gather_futures
|
||||||
|
|
||||||
import fabric
|
import fabric
|
||||||
|
@ -14,6 +15,8 @@ TRAEFIK_HOST = os.getenv('TRAEFIK_HOST') or ''
|
||||||
INTERNAL_DESTS = (os.getenv('INTERNAL_DESTS') or '').split(',') or []
|
INTERNAL_DESTS = (os.getenv('INTERNAL_DESTS') or '').split(',') or []
|
||||||
EXTERNAL_DESTS = (os.getenv('EXTERNAL_DESTS') or '').split(',') or []
|
EXTERNAL_DESTS = (os.getenv('EXTERNAL_DESTS') or '').split(',') or []
|
||||||
PRIVATE_KEY = os.getenv('PRIVATE_KEY') or ''
|
PRIVATE_KEY = os.getenv('PRIVATE_KEY') or ''
|
||||||
|
HOST = os.getenv('HOST') or '0.0.0.0'
|
||||||
|
PORT = os.getenv('PORT') or '80'
|
||||||
|
|
||||||
assert NODE_NAME != '_traefik'
|
assert NODE_NAME != '_traefik'
|
||||||
assert TRAEFIK_INSTANCE
|
assert TRAEFIK_INSTANCE
|
||||||
|
@ -49,10 +52,35 @@ class Observer:
|
||||||
@classmethod
|
@classmethod
|
||||||
def _init(cls):
|
def _init(cls):
|
||||||
try:
|
try:
|
||||||
data = requests.get(TRAEFIK_INSTANCE + '/rawdata').json()
|
with urllib3.HTTPSConnectionPool(
|
||||||
except Exception: ...
|
'host.docker.internal',
|
||||||
else:
|
server_hostname=TRAEFIK_INSTANCE
|
||||||
cls.update(data)
|
) as pool:
|
||||||
|
runtime_conf = pool.request(
|
||||||
|
'GET',
|
||||||
|
'/api/rawdata',
|
||||||
|
headers={'Host': TRAEFIK_INSTANCE},
|
||||||
|
assert_same_host=False
|
||||||
|
).json()
|
||||||
|
except Exception:
|
||||||
|
return
|
||||||
|
dynamic_conf = {
|
||||||
|
'http': {
|
||||||
|
'middlewares': runtime_conf.get('middlewares') or {},
|
||||||
|
'routers': runtime_conf.get('routers') or {},
|
||||||
|
'services': runtime_conf.get('services') or {},
|
||||||
|
},
|
||||||
|
'tcp': {
|
||||||
|
'middlewares': runtime_conf.get('tcpMiddlewares') or {},
|
||||||
|
'routers': runtime_conf.get('tcpRouters') or {},
|
||||||
|
'services': runtime_conf.get('tcpServices') or {},
|
||||||
|
},
|
||||||
|
'udp': {
|
||||||
|
'routers': runtime_conf.get('udpRouters') or {},
|
||||||
|
'services': runtime_conf.get('udpServices') or {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cls.update(dynamic_conf)
|
||||||
print("Initialized!")
|
print("Initialized!")
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,7 +125,7 @@ class Observer:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_raw_data(cls, data: dict):
|
def parse_raw_data(cls, data: dict):
|
||||||
http = (data.get('http') or {}) | (data.get('tcp') or {}) | (data.get('udp') or {}) or data
|
http = data.get('http') or {}
|
||||||
flt = lambda ep: set([x.group(1) for x in [re.match(PATTERN, x['rule']) for x in http['routers'].values() if ep in x['entryPoints']] if x])
|
flt = lambda ep: set([x.group(1) for x in [re.match(PATTERN, x['rule']) for x in http['routers'].values() if ep in x['entryPoints']] if x])
|
||||||
|
|
||||||
internal = flt(INTERNAL_ENTRYPOINT)
|
internal = flt(INTERNAL_ENTRYPOINT)
|
||||||
|
@ -120,6 +148,6 @@ def callback():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
app.run(host='0.0.0.0', port=80)
|
app.run(host=HOST, port=int(PORT))
|
||||||
finally:
|
finally:
|
||||||
Observer._close()
|
Observer._close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue