diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0f070bb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.5 + +ENV PYTHONUNBUFFERED 1 + +RUN mkdir /code +WORKDIR /code +ADD . /code/ + + +RUN pip3 install -r /code/requirements.txt +RUN python3 /code/setup.py install + + +ENTRYPOINT ["python3", "/code/laos/service/laos_api.py"] +EXPOSE 10001 diff --git a/Dockerfile.env.example b/Dockerfile.env.example new file mode 100644 index 0000000..89c1953 --- /dev/null +++ b/Dockerfile.env.example @@ -0,0 +1,6 @@ +LAOS_HOST=0.0.0.0 +LAOS_PORT=10001 +LAOS_DB=mysql://root:ubuntu@192.168.0.120/functions +KEYSTONE_ENDPOINT=http://192.168.0.120:5000/v3 +FUNCTIONS_URL=http://192.168.0.120:8080/v1 +LAOS_LOG_LEVEL=INFO diff --git a/README.md b/README.md index ab24c15..62e601c 100644 --- a/README.md +++ b/README.md @@ -99,10 +99,7 @@ Once it is finished you will have a console script `laos-api`: --port INTEGER API service bind port. --db-uri TEXT LaOS persistence storage URI. --keystone-endpoint TEXT OpenStack Identity service endpoint. - --functions-host TEXT Functions API host - --functions-port INTEGER Functions API port - --functions-api-version TEXT Functions API version - --functions-api-protocol TEXT Functions API protocol + --functions-url TEXT IronFunctions API URL --log-level TEXT Logging file --log-file TEXT Log file path --help Show this message and exit. @@ -111,10 +108,37 @@ Minimum required options to start LaOS API service: --db-uri mysql://root:root@192.168.0.112/functions --keystone-endpoint http://192.168.0.112:5000/v3 - --functions-host 192.168.0.112 - --functions-port 10501 + --functions-url http://192.168.0.112:8080/v1 --log-level INFO +Creating and running LaOS inside Docker container +------------------------------------------------- + +As part of regular Python distribution, LaOS also has its own Docker container to run. +There are two options: + +* run from sources +* run from Docker Hub + +In order to build container from sources run following commands: + + export DOCKER_HOST=tcp://: + docker build -t laos-api -f Dockerfile . + +After that it is required to create correct version of [Dockerfile.env](Dockerfile.env.example). +It container all required options to start LaOS API service properly. +Once it is done run following commands: + + docker run -d -p 10001:10001 --env-file Dockerfile.env laos-api + +Navigate to your web browser to check if service is running: + + :10001/api + +or using CLI + + curl -X GET http://:10001/api/swagger.json | python -mjson.tool + Examining API ------------- diff --git a/laos/service/laos_api.py b/laos/service/laos_api.py index c17ddd5..9cfd927 100644 --- a/laos/service/laos_api.py +++ b/laos/service/laos_api.py @@ -15,8 +15,10 @@ import asyncio import click +import os import uvloop + from aioservice.http import service from laos.api.controllers import apps @@ -30,6 +32,8 @@ from laos.api.middleware import keystone from laos.common import config from laos.common import logger as log +from urllib import parse + class API(service.HTTPService): @@ -71,31 +75,33 @@ class API(service.HTTPService): @click.command(name='laos-api') -@click.option('--host', default='0.0.0.0', help='API service bind host.') -@click.option('--port', default=10001, help='API service bind port.') -@click.option('--db-uri', default='mysql://root:root@localhost/functions', +@click.option('--host', + default=os.getenv("LAOS_HOST", '0.0.0.0'), + help='API service host.') +@click.option('--port', default=int(os.getenv("LAOS_PORT", 10001)), + help='API service port.') +@click.option('--db-uri', + default=os.getenv( + "LAOS_DB", + 'mysql://root:root@localhost/functions'), help='LaOS persistence storage URI.') -@click.option('--keystone-endpoint', default='http://localhost:5000/v3', +@click.option('--keystone-endpoint', + default=os.getenv("KEYSTONE_ENDPOINT", + 'http://localhost:5000/v3'), help='OpenStack Identity service endpoint.') -@click.option('--functions-host', default='localhost', +@click.option('--functions-url', + default=os.getenv( + "FUNCTIONS_URL", 'http://localhost:8080/v1'), help='Functions API host') -@click.option('--functions-port', default=10501, - help='Functions API port') -@click.option('--functions-api-version', default='v1', - help='Functions API version') -@click.option('--functions-api-protocol', default='http', - help='Functions API protocol') -@click.option('--log-level', default='INFO', +@click.option('--log-level', + default=os.getenv("LAOS_LOG_LEVEL", 'INFO'), help='Logging file') -@click.option('--log-file', default=None, +@click.option('--log-file', default=os.getenv("LAOS_LOG_FILE"), help='Log file path') @click.option('--debug', default=False, is_flag=True) def server(host, port, db_uri, keystone_endpoint, - functions_host, - functions_port, - functions_api_version, - functions_api_protocol, + functions_url, log_level, log_file, debug, @@ -111,11 +117,13 @@ def server(host, port, db_uri, asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) loop = asyncio.get_event_loop() + parts = parse.urlparse(functions_url) + fnclient = config.FunctionsClient( - functions_host, - api_port=functions_port, - api_protocol=functions_api_protocol, - api_version=functions_api_version, + parts.hostname, + api_port=parts.port, + api_protocol=parts.scheme, + api_version=parts.path[1:] ) loop.run_until_complete(fnclient.ping(loop=loop)) connection_pool = config.Connection(db_uri, loop=loop)