Open mkkl opened 5 years ago
Update ...
After changing the host_name and port in lang.py
def run_all(databases = None, host_name = '0.0.0.0', port = 8090, routing_rules = None, run = None, state_cache_size = 1024): main_host = create_host(databases, state_cache_size) main_app = interface.Application(main_host, host_name, port, routing_rules, run) main_app.run()
I got the the API to listen to http://0.0.0.0:8090/ when Durable Rules runs locally e.i. python test.py
However, when a docker container is created (e.g. docker build -t test_container .), the API listens again to http://127.0.0.1:5000/ e.i. docker run -p 8080:8090 test_container
Injecting and event from outside the container yields "curl: (52) Empty reply from server" message
curl -H "content-type: application/json" -X POST -d '{"name": "mkkl", "location": "JP"}' http://0.0.0.0:8080/rules/events curl: (52) Empty reply from server
Injecting an event from the container itself works as expected, although not on port = 8090 from lang.py file, but on port 5000
curl -H "content-type: application/json" -X POST -d '{"name": "mkkl", "location": "JP"}' http://0.0.0.0:5000/rules/events {"outcome": 0}root@4de969e00b66:/app#
How could I get the API to listen to http://0.0.0.0 and any other port but 5000 when deployed in a Docker container?
Thank you!
Hi, thank you for asking the question. How are you getting the app started in the docker container?
If you are starting your app following the test example, you can set the host name and the port:
from durable.lang import *
with ruleset('test'):
@when_all(m.subject == 'World')
def say_hello(c):
print ('Hello {0}'.format(c.m.subject))
@when_start
def start(host):
host.post('test', { 'subject': 'World' })
run_all(None, '0.0.0.0', 8090)
Thanks a lot for your guidance.
The app can be deployed in AWS cloud and events can be injected throughout its API
curl -H "content-type: application/json" -X POST -d '{"name": "mkkl", "location": "JP"}' http://durable.us-west-2.elasticbeanstalk.com/rules/events {"outcome": 0}
Re earlier question "How are you getting the app started in the docker container?", by inserting the following line at the bottom of Dockerfile
CMD ["python", "rules.py"]
Best Regards
Hi, one more question, what are the contents of rules.py? Is the last statement run_all()
, would you be able to change it to run_all(None, '0.0.0.0', 8090)
?
When an event is injected in Durable Rules deployed in a docker container, the host sends back a curl: (52) Empty reply from server message
curl -H "content-type: application/json" -X POST -d '{"name": "mkkl", "location": "JP"}' http://:8000/rules/events
curl: (52) Empty reply from server
even though the container's port 5000 is exposed in the Docker file
FROM python:3.6 COPY . /app WORKDIR /app RUN pip install -r requirements.txt EXPOSE 5000 CMD ["python", "rules.py"]
and published it in Dockerrun.aws.json file
{ "AWSEBDockerrunVersion": "1", "Ports": [ { "ContainerPort": 5000, "HostPort": 8000 } ] }
Should the Durable Rules API listen to 0.0.0.0 (any IP address of the host) instead of the 127.0.0.1 (localhost) only? If yes, where in the code I could make that change?
Thank you!