Merge pull request #8 from denismakogon/docker-pack
Implements Docker-based distribution
This commit is contained in:
commit
fee06d71a5
15
Dockerfile
Normal file
15
Dockerfile
Normal file
@ -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
|
6
Dockerfile.env.example
Normal file
6
Dockerfile.env.example
Normal file
@ -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
|
36
README.md
36
README.md
@ -99,10 +99,7 @@ Once it is finished you will have a console script `laos-api`:
|
|||||||
--port INTEGER API service bind port.
|
--port INTEGER API service bind port.
|
||||||
--db-uri TEXT LaOS persistence storage URI.
|
--db-uri TEXT LaOS persistence storage URI.
|
||||||
--keystone-endpoint TEXT OpenStack Identity service endpoint.
|
--keystone-endpoint TEXT OpenStack Identity service endpoint.
|
||||||
--functions-host TEXT Functions API host
|
--functions-url TEXT IronFunctions API URL
|
||||||
--functions-port INTEGER Functions API port
|
|
||||||
--functions-api-version TEXT Functions API version
|
|
||||||
--functions-api-protocol TEXT Functions API protocol
|
|
||||||
--log-level TEXT Logging file
|
--log-level TEXT Logging file
|
||||||
--log-file TEXT Log file path
|
--log-file TEXT Log file path
|
||||||
--help Show this message and exit.
|
--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
|
--db-uri mysql://root:root@192.168.0.112/functions
|
||||||
--keystone-endpoint http://192.168.0.112:5000/v3
|
--keystone-endpoint http://192.168.0.112:5000/v3
|
||||||
--functions-host 192.168.0.112
|
--functions-url http://192.168.0.112:8080/v1
|
||||||
--functions-port 10501
|
|
||||||
--log-level INFO
|
--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-host>:<docker-port>
|
||||||
|
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:
|
||||||
|
|
||||||
|
<docker-host>:10001/api
|
||||||
|
|
||||||
|
or using CLI
|
||||||
|
|
||||||
|
curl -X GET http://<docker-host>:10001/api/swagger.json | python -mjson.tool
|
||||||
|
|
||||||
Examining API
|
Examining API
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
@ -15,8 +15,10 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
import os
|
||||||
import uvloop
|
import uvloop
|
||||||
|
|
||||||
|
|
||||||
from aioservice.http import service
|
from aioservice.http import service
|
||||||
|
|
||||||
from laos.api.controllers import apps
|
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 config
|
||||||
from laos.common import logger as log
|
from laos.common import logger as log
|
||||||
|
|
||||||
|
from urllib import parse
|
||||||
|
|
||||||
|
|
||||||
class API(service.HTTPService):
|
class API(service.HTTPService):
|
||||||
|
|
||||||
@ -71,31 +75,33 @@ class API(service.HTTPService):
|
|||||||
|
|
||||||
|
|
||||||
@click.command(name='laos-api')
|
@click.command(name='laos-api')
|
||||||
@click.option('--host', default='0.0.0.0', help='API service bind host.')
|
@click.option('--host',
|
||||||
@click.option('--port', default=10001, help='API service bind port.')
|
default=os.getenv("LAOS_HOST", '0.0.0.0'),
|
||||||
@click.option('--db-uri', default='mysql://root:root@localhost/functions',
|
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.')
|
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.')
|
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')
|
help='Functions API host')
|
||||||
@click.option('--functions-port', default=10501,
|
@click.option('--log-level',
|
||||||
help='Functions API port')
|
default=os.getenv("LAOS_LOG_LEVEL", 'INFO'),
|
||||||
@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',
|
|
||||||
help='Logging file')
|
help='Logging file')
|
||||||
@click.option('--log-file', default=None,
|
@click.option('--log-file', default=os.getenv("LAOS_LOG_FILE"),
|
||||||
help='Log file path')
|
help='Log file path')
|
||||||
@click.option('--debug', default=False, is_flag=True)
|
@click.option('--debug', default=False, is_flag=True)
|
||||||
def server(host, port, db_uri,
|
def server(host, port, db_uri,
|
||||||
keystone_endpoint,
|
keystone_endpoint,
|
||||||
functions_host,
|
functions_url,
|
||||||
functions_port,
|
|
||||||
functions_api_version,
|
|
||||||
functions_api_protocol,
|
|
||||||
log_level,
|
log_level,
|
||||||
log_file,
|
log_file,
|
||||||
debug,
|
debug,
|
||||||
@ -111,11 +117,13 @@ def server(host, port, db_uri,
|
|||||||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
parts = parse.urlparse(functions_url)
|
||||||
|
|
||||||
fnclient = config.FunctionsClient(
|
fnclient = config.FunctionsClient(
|
||||||
functions_host,
|
parts.hostname,
|
||||||
api_port=functions_port,
|
api_port=parts.port,
|
||||||
api_protocol=functions_api_protocol,
|
api_protocol=parts.scheme,
|
||||||
api_version=functions_api_version,
|
api_version=parts.path[1:]
|
||||||
)
|
)
|
||||||
loop.run_until_complete(fnclient.ping(loop=loop))
|
loop.run_until_complete(fnclient.ping(loop=loop))
|
||||||
connection_pool = config.Connection(db_uri, loop=loop)
|
connection_pool = config.Connection(db_uri, loop=loop)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user