diff --git a/bin/geomag_webservice.py b/bin/geomag_webservice.py index 039f401531353065143ddeed20a6fa9e5da7c9c1..00e6b81667ee21b20e703e68b2717e95440d0bc6 100755 --- a/bin/geomag_webservice.py +++ b/bin/geomag_webservice.py @@ -22,6 +22,7 @@ if __name__ == '__main__': factory_type = os.getenv('GEOMAG_FACTORY_TYPE', 'edge') webservice_host = os.getenv('GEOMAG_WEBSERVICE_HOST', '') webservice_port = int(os.getenv('GEOMAG_WEBSERVICE_PORT', '7981')) + version = os.getenv('GEOMAG_VERSION', None) # configure factory if factory_type == 'edge': @@ -30,6 +31,6 @@ if __name__ == '__main__': raise "Unknown factory type '%s'" % factory_type print("Starting webservice on %s:%d" % (webservice_host, webservice_port)) - app = geomagio.WebService(factory) + app = geomagio.WebService(factory, version) httpd = make_server(webservice_host, webservice_port, app) httpd.serve_forever() diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..8c95f16b76452a81be49596a84d8857c935f12d9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3" +services: + web: + image: usgs/geomag-algorithms:latest + environment: + - EDGE_HOST=cwbpub.cr.usgs.gov + - EDGE_PORT=2060 + - GEOMAG_WEBSERVICE_PORT=8000 + - GEOMAG_VERSION=0.3.1 + ports: + - "8000:8000" + entrypoint: /geomag-algorithms/bin/geomag_webservice.py diff --git a/geomagio/WebService.py b/geomagio/WebService.py index a06a7181c21b98e5ed5ac23c4a46d01a19aba013..f5ac8ba19a5713cc9e9bd44acfcb15f048eee230 100644 --- a/geomagio/WebService.py +++ b/geomagio/WebService.py @@ -4,8 +4,6 @@ from __future__ import print_function from cgi import parse_qs, escape from datetime import datetime -from json import load -import os.path import sys from geomagio.edge import EdgeFactory @@ -74,14 +72,10 @@ def _get_param(params, key, required=False): class WebService(object): - def __init__(self, factory=None, metadata=None): + def __init__(self, factory=None, version=None, metadata=None): self.factory = factory or EdgeFactory() self.metadata = metadata or ObservatoryMetadata().metadata - base = os.path.dirname(__file__) - filepath = os.path.abspath(os.path.join(base, '..', 'package.json')) - with open(filepath) as package: - specifications = load(package) - self.version = specifications['version'] + self.version = version def __call__(self, environ, start_response): """Implement WSGI interface""" @@ -185,9 +179,10 @@ class WebService(object): 'Request:\n' + \ environ['PATH_INFO'] + '?' + environ['QUERY_STRING'] + \ '\n\n' + 'Request Submitted:\n' + \ - datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") + '\n\n' + \ - 'Service version:\n' + \ - str(self.version) + datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") + '\n\n' + # Check if there is version information available + if self.version is not None: + http_error_body += 'Service version:\n' + str(self.version) return http_error_body def parse(self, params):