diff --git a/imageroot/bin/redis2yml b/imageroot/bin/redis2yml index aa53c81..77581f3 100755 --- a/imageroot/bin/redis2yml +++ b/imageroot/bin/redis2yml @@ -19,7 +19,6 @@ try: except: instance = 'traefik1' -config_tls = { "tls": { "stores": { "default": { "defaultCertificate": { "certFile": "", "keyFile": "" } } } } } middlewares = {} services = {} routers = {} @@ -27,10 +26,6 @@ routers = {} prefix = f'module/{instance}/kv/' rdb = agent.redis_connect(host='127.0.0.1', privileged = True) -# TLS default certificate -for key in ["certFile", "keyFile"]: - config_tls["tls"]["stores"]["default"]["defaultCertificate"][key] = rdb.get(f'{prefix}tls/stores/default/defaultCertificate/{key}') - # HTTP for kv in rdb.scan_iter(f'{prefix}http/*'): value = rdb.get(kv) @@ -77,33 +72,21 @@ for kv in rdb.scan_iter(f'{prefix}http/*'): # module/traefik1/kv/http/routers/instance1-https/tls/domains/0/main routers[tmp[1]]['tls']['domains'].append({last: value}) -# cleanup routes using default cert +# Cleanup routes using default cert for r in routers: if "tls" in routers[r] and (not routers[r]["tls"]["certresolver"] and not routers[r]["tls"]["domains"]): routers[r]["tls"] = {} -# Generate config files -os.makedirs('configs', exist_ok = True) -with open('configs/_default_cert.yml', 'w') as fpc: - fpc.write(yaml.safe_dump(config_tls, default_flow_style=False, sort_keys=False, allow_unicode=True)) - -config_middleware = {"http": {"middlewares": {'http2https-redirectscheme': middlewares.pop('http2https-redirectscheme')}}} -with open('configs/_http2https.yml', 'w') as fpm: - fpm.write(yaml.safe_dump(config_middleware, default_flow_style=False, sort_keys=False, allow_unicode=True)) - -route_api = routers.pop('ApisEndpointHttp') -route_api['priority'] = '100000' -config_api = {"http": {"middlewares": {'ApisEndpointMw0': middlewares.pop('ApisEndpointMw0'), 'ApisEndpointMw1': middlewares.pop('ApisEndpointMw1')}, "routers": {"ApisEndpointHttp": route_api}}} -with open('configs/_api.yml', 'w') as fpm: - fpm.write(yaml.safe_dump(config_api, default_flow_style=False, sort_keys=False, allow_unicode=True)) - -route_api_server_https = routers.pop('ApiServer-https') -route_api_server_https['priority'] = '100000' -route_api_server_http = routers.pop('ApiServer-http') -route_api_server_http['priority'] = '100000' -config_api_server = {"http": {"middlewares": {'ApiServerMw2': middlewares.pop('ApiServerMw2'), 'ApiServer-stripprefix': middlewares.pop('ApiServer-stripprefix')}, "routers": {"ApiServer-https": route_api_server_https, "ApiServer-https": route_api_server_http}, "services": {"ApiServer": services.pop("ApiServer")}}} -with open('configs/_api_server.yml', 'w') as fpm: - fpm.write(yaml.safe_dump(config_api_server, default_flow_style=False, sort_keys=False, allow_unicode=True)) +# Remove well-known configs +try: + middlewares.pop('http2https-redirectscheme') + middlewares.pop('ApisEndpointMw0') + middlewares.pop('ApisEndpointMw1') + routers.pop('ApisEndpointHttp') + routers.pop('ApiServer-https') + routers.pop('ApiServer-http') +except: + pass for service in services: config_service = {"http": { "routers": {}, "services": {service: services[service]}}} diff --git a/imageroot/bin/upgrade_to_beta2 b/imageroot/bin/upgrade_to_beta2 index 66d55e5..f7a04c7 100755 --- a/imageroot/bin/upgrade_to_beta2 +++ b/imageroot/bin/upgrade_to_beta2 @@ -6,5 +6,6 @@ # ~/.config/actions/create-module/10expandconfig +~/.config/actions/create-module/50create ~/.config/bin/redis2yaml systemctl --user restart traefik