diff --git a/Readme.md b/Readme.md index bb388b9..24b8cc8 100644 --- a/Readme.md +++ b/Readme.md @@ -5,6 +5,7 @@ Goal of this project is to aggregate responses from different services while not ## configuration configuration happens using env vars prefixed with `version.`. +you may not use static and url together, static will take priority. ## usage @@ -18,5 +19,6 @@ docker run --rm \ -eversion.client.url='http://esel:3100/version' \ -eversion.nuxt-client.url='http://esel:4000/nuxtversion' \ -eversion.server.url='http://esel:3030/serverversion' \ +-eversion.dof_app_deploy.static='696' version-aggregator ``` \ No newline at end of file diff --git a/ansible/roles/version-aggregator/templates/deployment.yml.j2 b/ansible/roles/version-aggregator/templates/deployment.yml.j2 index f869233..9a3f4d4 100644 --- a/ansible/roles/version-aggregator/templates/deployment.yml.j2 +++ b/ansible/roles/version-aggregator/templates/deployment.yml.j2 @@ -52,6 +52,10 @@ spec: envFrom: - configMapRef: name: version-aggregator-configmap + env: + # we need that env here to ensure to get restarted when it changes! + - name: version.dof_app_deploy.static + value: {{ DOF_APP_DEPLOY_BRANCH_NAME }} resources: limits: cpu: {{ VERSION_AGGREGATOR__CPU_LIMITS|default("1000m", true) }} diff --git a/app.py b/app.py index fbeeafa..b3cfec9 100644 --- a/app.py +++ b/app.py @@ -17,17 +17,21 @@ def do_GET(self): result = {} encountered_issues = False for service in services: - service_url = services[service] - logging.info('calling for client ' + service + ': ' + service_url) - request = urllib.request.Request(service_url) - try: - with urllib.request.urlopen(request) as response: - data = json.loads(response.read().decode('UTF-8')) - result[service] = data - except URLError: - logging.error('service not available ' + service_url, exc_info=True) - encountered_issues = True - result[service] = 'unavailable' + static_version, _value = services[service] + if static_version: + result[service] = _value + else: + service_url = _value + logging.info('calling for client ' + service + ': ' + service_url) + request = urllib.request.Request(service_url) + try: + with urllib.request.urlopen(request) as response: + data = json.loads(response.read().decode('UTF-8')) + result[service] = data + except URLError: + logging.error('service not available ' + service_url, exc_info=True) + encountered_issues = True + result[service] = 'unavailable' result['services-unavailable'] = encountered_issues self.send_response(200) @@ -41,8 +45,14 @@ def do_GET(self): for key, value in os.environ.items(): if key.startswith('version.'): - re_result = re.search(r"(\bversion\.\b)(\b.+\b)\.url", key) - services[re_result.group(2)] = value + re_match = re.search(r"^(version\.(.+))\.(static|url)$", key) + if re_match: + service_name = re_match.group(2) + is_static = re_match.group(3) == 'static' + services[service_name] = (is_static, value) + else: + logging.error("config is neither static nor an url: " + key) + httpd = HTTPServer(('0.0.0.0', 8080), WebServer) httpd.serve_forever()