From 55ef87e08988cf1f8591cb8b0b151798802b1879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Thu, 8 Feb 2018 14:58:37 +0100 Subject: [PATCH 01/20] Add AVATAO_SECRET to envvars --- lib/tfw/config/envvars.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tfw/config/envvars.py b/lib/tfw/config/envvars.py index b9fa997..a8dd2bb 100644 --- a/lib/tfw/config/envvars.py +++ b/lib/tfw/config/envvars.py @@ -1,4 +1,4 @@ -from os import environ +from os import environ, getenv from collections import namedtuple TFW_PREFIX = 'TFW_' @@ -6,3 +6,5 @@ tfwenvvars = {envvar.replace(TFW_PREFIX, '', 1): environ.get(envvar) for envvar in environ.keys() if envvar.startswith(TFW_PREFIX)} tfwenv = namedtuple('tfwenvtuple', tfwenvvars)(**tfwenvvars) + +AVATAO_SECRET = getenv('AVATAO_SECRET', 'secret') From 03d6f587e9ea9dd865d53f75f563e4c43056c181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Thu, 8 Feb 2018 14:59:43 +0100 Subject: [PATCH 02/20] Create initial version of ControllerConnector --- lib/tfw/networking/controller_connector.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/tfw/networking/controller_connector.py diff --git a/lib/tfw/networking/controller_connector.py b/lib/tfw/networking/controller_connector.py new file mode 100644 index 0000000..b539163 --- /dev/null +++ b/lib/tfw/networking/controller_connector.py @@ -0,0 +1,18 @@ +import zmq +from zmq.eventloop import ioloop +from zmq.eventloop.zmqstream import ZMQStream + +from tfw.config import CONTROLLER_PORT +from tfw.util import ZMQConnectorBase + +ioloop.install() + + +class ControllerConnector(ZMQConnectorBase): + def __init__(self, zmq_context=None): + super(ControllerConnector, self).__init__(zmq_context) + self._zmq_rep_socket = self._zmq_context.socket(zmq.REP) + self._zmq_rep_socket.connect('tcp://localhost:{}'.format(CONTROLLER_PORT)) + self._zmq_rep_stream = ZMQStream(self._zmq_rep_socket) + + self.register_callback = self._zmq_rep_stream.on_recv From 27376ada2220b6cd94633d0c458fe14d137c67ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Thu, 8 Feb 2018 15:00:16 +0100 Subject: [PATCH 03/20] Create initial version of SolvableConnector --- lib/tfw/networking/solvable_connector.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/tfw/networking/solvable_connector.py diff --git a/lib/tfw/networking/solvable_connector.py b/lib/tfw/networking/solvable_connector.py new file mode 100644 index 0000000..d7f0425 --- /dev/null +++ b/lib/tfw/networking/solvable_connector.py @@ -0,0 +1,21 @@ +import zmq +from zmq.eventloop import ioloop + +from tfw.config import CONTROLLER_PORT +from tfw.util import ZMQConnectorBase +from tfw.networking.serialization import serialize_all, deserialize_all + +ioloop.install() + + +class SolvableConnector(ZMQConnectorBase): + def __init__(self, zmq_context=None): + super(SolvableConnector, self).__init__(zmq_context) + self._zmq_req_socket = self._zmq_context.socket(zmq.REQ) + self._zmq_req_socket.bind('tcp://*:{}'.format(CONTROLLER_PORT)) + + def send(self, key, message): + self._zmq_req_socket.send_multipart(serialize_all(key, message)) + + def recv(self): + return deserialize_all(*self._zmq_req_socket.recv_multipart()) From 95e1f907ee1ebd1a930c37e135f027b03a69bb0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Thu, 8 Feb 2018 15:08:19 +0100 Subject: [PATCH 04/20] Make serialization methods' parameter names more generic --- lib/tfw/networking/serialization.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/tfw/networking/serialization.py b/lib/tfw/networking/serialization.py index 7333873..73acc27 100644 --- a/lib/tfw/networking/serialization.py +++ b/lib/tfw/networking/serialization.py @@ -13,9 +13,9 @@ def decode_if_needed(value): return value -def serialize_all(anchor, message): - return [encode_if_needed(a) for a in (anchor, json.dumps(message))] +def serialize_all(key, data): + return [encode_if_needed(frame) for frame in (key, json.dumps(data))] -def deserialize_all(anchor, message): - return decode_if_needed(anchor), json.loads(message) +def deserialize_all(key, data): + return decode_if_needed(key), json.loads(data) From c015727153d4bb78c2fa0aec6ec857b782771193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Thu, 8 Feb 2018 16:26:28 +0100 Subject: [PATCH 05/20] Create initial version of controller --- src/controller/__init__.py | 0 src/controller/app.py | 19 +++++++++++++++++++ src/controller/handlers/__init__.py | 2 ++ .../handlers/solution_check_handler.py | 11 +++++++++++ src/controller/handlers/test_handler.py | 11 +++++++++++ 5 files changed, 43 insertions(+) create mode 100644 src/controller/__init__.py create mode 100644 src/controller/app.py create mode 100644 src/controller/handlers/__init__.py create mode 100644 src/controller/handlers/solution_check_handler.py create mode 100644 src/controller/handlers/test_handler.py diff --git a/src/controller/__init__.py b/src/controller/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/controller/app.py b/src/controller/app.py new file mode 100644 index 0000000..b3af301 --- /dev/null +++ b/src/controller/app.py @@ -0,0 +1,19 @@ +from tornado.ioloop import IOLoop +from tornado.web import Application + +from tfw.config import CRP_LISTENER_PORT, AVATAO_SECRET +from .handlers import SolutionCheckHandler, TestHandler +from tfw.networking.solvable_connector import SolvableConnector + + +if __name__ == '__main__': + solvable_connector = SolvableConnector() + routes = [ + (r'/{secret}/'.format(secret=AVATAO_SECRET), SolutionCheckHandler, {'solvable_connector': solvable_connector}), + (r'/{secret}/test'.format(secret=AVATAO_SECRET), TestHandler, {'solvable_connector': solvable_connector}) + ] + app = Application( + routes + ) + app.listen(CRP_LISTENER_PORT) + IOLoop.instance().start() diff --git a/src/controller/handlers/__init__.py b/src/controller/handlers/__init__.py new file mode 100644 index 0000000..ac7e0ba --- /dev/null +++ b/src/controller/handlers/__init__.py @@ -0,0 +1,2 @@ +from .solution_check_handler import SolutionCheckHandler +from .test_handler import TestHandler diff --git a/src/controller/handlers/solution_check_handler.py b/src/controller/handlers/solution_check_handler.py new file mode 100644 index 0000000..85bfe7c --- /dev/null +++ b/src/controller/handlers/solution_check_handler.py @@ -0,0 +1,11 @@ +from tornado.web import RequestHandler + + +class SolutionCheckHandler(RequestHandler): + def initialize(self, solvable_connector): + self.solvable_connector = solvable_connector + + def get(self): + self.solvable_connector.send('solution_check', {}) + resp_key, resp_data = self.solvable_connector.recv() + return resp_data diff --git a/src/controller/handlers/test_handler.py b/src/controller/handlers/test_handler.py new file mode 100644 index 0000000..0514e08 --- /dev/null +++ b/src/controller/handlers/test_handler.py @@ -0,0 +1,11 @@ +from tornado.web import RequestHandler + + +class TestHandler(RequestHandler): + def initialize(self, solvable_connector): + self.solvable_connector = solvable_connector + + def get(self): + self.solvable_connector.send('test', {}) + resp_key, resp_data = self.solvable_connector.recv() + return resp_data From 793fc45493658becbfea420a5366d39474087233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Fri, 9 Feb 2018 13:54:54 +0100 Subject: [PATCH 06/20] Add controller to Dockerfile This is a temporary measure to ease development and testing. The final project will contain a separate controller. --- Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Dockerfile b/Dockerfile index 195a4af..c5d1741 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,13 +44,17 @@ ENV TFW_LOGIN_APP_PORT=6666 ENV TFW_TERMINADO_PORT=7878 ENV TFW_SUPERVISOR_HTTP_PORT=9001 ENV TFW_PUBLIC_PORT=8888 +ENV TFW_CONTROLLER_PORT=7777 +ENV TFW_CRP_LISTENER_PORT=5555 ENV TFW_PUBLISHER_PORT=7654 ENV TFW_RECEIVER_PORT=8765 EXPOSE ${TFW_PUBLIC_PORT} +EXPOSE ${TFW_CRP_LISTENER_PORT} ENV TFW_SUPERVISOR_HTTP_URI="http://localhost:${TFW_SUPERVISOR_HTTP_PORT}" ENV TFW_EVENT_HANDLERS_DIR="/opt/event_handlers" ENV TFW_APP_DIR="/srv/app" +ENV TFW_CONTROLLER_DIR="/srv/controller" ENV TFW_FRONTEND_DIR="/srv/frontend" ENV TFW_LOGIN_APP_DIR="/tmp/source_code_server" ENV TFW_TERMINADO_DIR="/tmp/terminado_server" @@ -76,6 +80,7 @@ COPY supervisor/supervisord.conf ${TFW_SUPERVISORD_CONF} COPY supervisor/components/ ${TFW_SUPERVISORD_COMPONENTS} COPY src/app ${TFW_APP_DIR} COPY src/event_handlers ${TFW_EVENT_HANDLERS_DIR} +COPY src/controller ${TFW_CONTROLLER_DIR} RUN mv /data/dist ${TFW_FRONTEND_DIR} From 9a33ed06248d8f1b25bb192e96484e93008a0b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Fri, 9 Feb 2018 13:57:32 +0100 Subject: [PATCH 07/20] Create supervisor entry for controller --- supervisor/components/controller.conf | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 supervisor/components/controller.conf diff --git a/supervisor/components/controller.conf b/supervisor/components/controller.conf new file mode 100644 index 0000000..1cdb672 --- /dev/null +++ b/supervisor/components/controller.conf @@ -0,0 +1,3 @@ +[program:controller] +directory=%(ENV_TFW_CONTROLLER_DIR)s +command=env python app.py \ No newline at end of file From f3d53c2b5bc5d607db08a13e66650498173bc0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Fri, 9 Feb 2018 14:03:45 +0100 Subject: [PATCH 08/20] Fix handlers import --- src/controller/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/app.py b/src/controller/app.py index b3af301..ff3f946 100644 --- a/src/controller/app.py +++ b/src/controller/app.py @@ -2,7 +2,7 @@ from tornado.ioloop import IOLoop from tornado.web import Application from tfw.config import CRP_LISTENER_PORT, AVATAO_SECRET -from .handlers import SolutionCheckHandler, TestHandler +from handlers import SolutionCheckHandler, TestHandler from tfw.networking.solvable_connector import SolvableConnector From 1c3e946e29a00062d01b33647ca18548dc7ff415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Fri, 9 Feb 2018 14:04:47 +0100 Subject: [PATCH 09/20] Fix handlers' responses --- src/controller/handlers/solution_check_handler.py | 2 +- src/controller/handlers/test_handler.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controller/handlers/solution_check_handler.py b/src/controller/handlers/solution_check_handler.py index 85bfe7c..b45d7fd 100644 --- a/src/controller/handlers/solution_check_handler.py +++ b/src/controller/handlers/solution_check_handler.py @@ -8,4 +8,4 @@ class SolutionCheckHandler(RequestHandler): def get(self): self.solvable_connector.send('solution_check', {}) resp_key, resp_data = self.solvable_connector.recv() - return resp_data + self.write(resp_data) diff --git a/src/controller/handlers/test_handler.py b/src/controller/handlers/test_handler.py index 0514e08..bc4d690 100644 --- a/src/controller/handlers/test_handler.py +++ b/src/controller/handlers/test_handler.py @@ -8,4 +8,4 @@ class TestHandler(RequestHandler): def get(self): self.solvable_connector.send('test', {}) resp_key, resp_data = self.solvable_connector.recv() - return resp_data + self.write(resp_data) From e39b8b9283d75ea9093e5a1a0beab88ad652435c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Fri, 9 Feb 2018 14:05:34 +0100 Subject: [PATCH 10/20] Make trailing slash optional in URLs --- src/controller/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controller/app.py b/src/controller/app.py index ff3f946..8ee357a 100644 --- a/src/controller/app.py +++ b/src/controller/app.py @@ -9,8 +9,8 @@ from tfw.networking.solvable_connector import SolvableConnector if __name__ == '__main__': solvable_connector = SolvableConnector() routes = [ - (r'/{secret}/'.format(secret=AVATAO_SECRET), SolutionCheckHandler, {'solvable_connector': solvable_connector}), - (r'/{secret}/test'.format(secret=AVATAO_SECRET), TestHandler, {'solvable_connector': solvable_connector}) + (r'/{secret}/?'.format(secret=AVATAO_SECRET), SolutionCheckHandler, {'solvable_connector': solvable_connector}), + (r'/{secret}/test/?'.format(secret=AVATAO_SECRET), TestHandler, {'solvable_connector': solvable_connector}) ] app = Application( routes From eed3006055d67a681f8ba2102d318cd13bb5d578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Fri, 9 Feb 2018 14:06:11 +0100 Subject: [PATCH 11/20] Add logging to controller --- src/controller/app.py | 3 +++ src/controller/handlers/solution_check_handler.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/controller/app.py b/src/controller/app.py index 8ee357a..02873a3 100644 --- a/src/controller/app.py +++ b/src/controller/app.py @@ -5,6 +5,8 @@ from tfw.config import CRP_LISTENER_PORT, AVATAO_SECRET from handlers import SolutionCheckHandler, TestHandler from tfw.networking.solvable_connector import SolvableConnector +from tfw.config.logs import logging +log = logging.getLogger(__name__) if __name__ == '__main__': solvable_connector = SolvableConnector() @@ -16,4 +18,5 @@ if __name__ == '__main__': routes ) app.listen(CRP_LISTENER_PORT) + log.debug('Controller listening on {}'.format(CRP_LISTENER_PORT)) IOLoop.instance().start() diff --git a/src/controller/handlers/solution_check_handler.py b/src/controller/handlers/solution_check_handler.py index b45d7fd..5a79feb 100644 --- a/src/controller/handlers/solution_check_handler.py +++ b/src/controller/handlers/solution_check_handler.py @@ -1,11 +1,15 @@ from tornado.web import RequestHandler +from tfw.config.logs import logging +log = logging.getLogger(__name__) class SolutionCheckHandler(RequestHandler): def initialize(self, solvable_connector): self.solvable_connector = solvable_connector def get(self): + log.debug('Sending request to solvable') self.solvable_connector.send('solution_check', {}) resp_key, resp_data = self.solvable_connector.recv() + log.debug('Received answer from solvable') self.write(resp_data) From 28e83de0d7abef1a8b137d72fb25ad41169d7d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Fri, 9 Feb 2018 14:08:14 +0100 Subject: [PATCH 12/20] Create PoC of solvable with hardcoded responses --- lib/tfw/networking/controller_connector.py | 2 +- src/app/app.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/tfw/networking/controller_connector.py b/lib/tfw/networking/controller_connector.py index b539163..4a9caca 100644 --- a/lib/tfw/networking/controller_connector.py +++ b/lib/tfw/networking/controller_connector.py @@ -15,4 +15,4 @@ class ControllerConnector(ZMQConnectorBase): self._zmq_rep_socket.connect('tcp://localhost:{}'.format(CONTROLLER_PORT)) self._zmq_rep_stream = ZMQStream(self._zmq_rep_socket) - self.register_callback = self._zmq_rep_stream.on_recv + self.register_callback = self._zmq_rep_stream.on_recv_stream diff --git a/src/app/app.py b/src/app/app.py index 3dc6d8f..383fd9a 100644 --- a/src/app/app.py +++ b/src/app/app.py @@ -7,12 +7,28 @@ from tornado.ioloop import IOLoop from sql_injection_fsm import SQLInjectionFSM from tfw.config import tfwenv from tfw.config.logs import logging +from tfw.networking.controller_connector import ControllerConnector +from tfw.networking.serialization import deserialize_all, serialize_all + log = logging.getLogger(__name__) from tfw.networking.server.zmq_websocket_handler import FSMManagingSocketHandler +def zmq_callback(stream, msg_parts): + key, data = deserialize_all(*msg_parts) + if key == 'test': + stream.send_multipart(serialize_all(key, 'OK')) + if key == 'solution_check': + stream.send_multipart(serialize_all(key, { + 'solved': True, + 'message': 'solved' + })) + + if __name__ == '__main__': fsm = SQLInjectionFSM() + controller_connector = ControllerConnector() + controller_connector.register_callback(zmq_callback) routes = [ (r'/ws', FSMManagingSocketHandler, {'fsm': fsm}), ] From 2499c4759e25ce32dcad7204d08ced11bdef6385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Fri, 9 Feb 2018 14:21:17 +0100 Subject: [PATCH 13/20] Fix envvar imports --- lib/tfw/networking/controller_connector.py | 4 ++-- lib/tfw/networking/solvable_connector.py | 4 ++-- src/controller/app.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/tfw/networking/controller_connector.py b/lib/tfw/networking/controller_connector.py index 4a9caca..64f83b2 100644 --- a/lib/tfw/networking/controller_connector.py +++ b/lib/tfw/networking/controller_connector.py @@ -2,7 +2,7 @@ import zmq from zmq.eventloop import ioloop from zmq.eventloop.zmqstream import ZMQStream -from tfw.config import CONTROLLER_PORT +from tfw.config import tfwenv from tfw.util import ZMQConnectorBase ioloop.install() @@ -12,7 +12,7 @@ class ControllerConnector(ZMQConnectorBase): def __init__(self, zmq_context=None): super(ControllerConnector, self).__init__(zmq_context) self._zmq_rep_socket = self._zmq_context.socket(zmq.REP) - self._zmq_rep_socket.connect('tcp://localhost:{}'.format(CONTROLLER_PORT)) + self._zmq_rep_socket.connect('tcp://localhost:{}'.format(tfwenv.CONTROLLER_PORT)) self._zmq_rep_stream = ZMQStream(self._zmq_rep_socket) self.register_callback = self._zmq_rep_stream.on_recv_stream diff --git a/lib/tfw/networking/solvable_connector.py b/lib/tfw/networking/solvable_connector.py index d7f0425..7a77a57 100644 --- a/lib/tfw/networking/solvable_connector.py +++ b/lib/tfw/networking/solvable_connector.py @@ -1,7 +1,7 @@ import zmq from zmq.eventloop import ioloop -from tfw.config import CONTROLLER_PORT +from tfw.config import tfwenv from tfw.util import ZMQConnectorBase from tfw.networking.serialization import serialize_all, deserialize_all @@ -12,7 +12,7 @@ class SolvableConnector(ZMQConnectorBase): def __init__(self, zmq_context=None): super(SolvableConnector, self).__init__(zmq_context) self._zmq_req_socket = self._zmq_context.socket(zmq.REQ) - self._zmq_req_socket.bind('tcp://*:{}'.format(CONTROLLER_PORT)) + self._zmq_req_socket.bind('tcp://*:{}'.format(tfwenv.CONTROLLER_PORT)) def send(self, key, message): self._zmq_req_socket.send_multipart(serialize_all(key, message)) diff --git a/src/controller/app.py b/src/controller/app.py index 02873a3..73b321c 100644 --- a/src/controller/app.py +++ b/src/controller/app.py @@ -1,7 +1,7 @@ from tornado.ioloop import IOLoop from tornado.web import Application -from tfw.config import CRP_LISTENER_PORT, AVATAO_SECRET +from tfw.config import tfwenv, AVATAO_SECRET from handlers import SolutionCheckHandler, TestHandler from tfw.networking.solvable_connector import SolvableConnector @@ -17,6 +17,6 @@ if __name__ == '__main__': app = Application( routes ) - app.listen(CRP_LISTENER_PORT) - log.debug('Controller listening on {}'.format(CRP_LISTENER_PORT)) + app.listen(tfwenv.CRP_LISTENER_PORT) + log.debug('Controller listening on {}'.format(tfwenv.CRP_LISTENER_PORT)) IOLoop.instance().start() From 4f181b8f091a6af7d193ae8b3919c86148cfb97f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Fri, 9 Feb 2018 14:48:37 +0100 Subject: [PATCH 14/20] Separate the handling of envvars by prefix --- lib/envvars.py | 9 +++++++++ lib/tao/__init__.py | 0 lib/tao/config/__init__.py | 1 + lib/tao/config/envvars.py | 3 +++ lib/tfw/config/envvars.py | 11 ++--------- src/controller/app.py | 7 ++++--- 6 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 lib/envvars.py create mode 100644 lib/tao/__init__.py create mode 100644 lib/tao/config/__init__.py create mode 100644 lib/tao/config/envvars.py diff --git a/lib/envvars.py b/lib/envvars.py new file mode 100644 index 0000000..aeb2712 --- /dev/null +++ b/lib/envvars.py @@ -0,0 +1,9 @@ +from collections import namedtuple +from os import environ + + +def generate_namedtuple_from_prefixed_envvars(prefix: str, tuple_name: str): + envvars = {envvar.replace(prefix, '', 1): environ.get(envvar) + for envvar in environ.keys() + if envvar.startswith(prefix)} + return namedtuple(tuple_name, envvars)(**envvars) diff --git a/lib/tao/__init__.py b/lib/tao/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/tao/config/__init__.py b/lib/tao/config/__init__.py new file mode 100644 index 0000000..d3319d7 --- /dev/null +++ b/lib/tao/config/__init__.py @@ -0,0 +1 @@ +from .envvars import * diff --git a/lib/tao/config/envvars.py b/lib/tao/config/envvars.py new file mode 100644 index 0000000..6262ead --- /dev/null +++ b/lib/tao/config/envvars.py @@ -0,0 +1,3 @@ +from envvars import generate_namedtuple_from_prefixed_envvars + +taoenv = generate_namedtuple_from_prefixed_envvars('AVATAO_', 'taoenvtuple') diff --git a/lib/tfw/config/envvars.py b/lib/tfw/config/envvars.py index a8dd2bb..d94be2b 100644 --- a/lib/tfw/config/envvars.py +++ b/lib/tfw/config/envvars.py @@ -1,10 +1,3 @@ -from os import environ, getenv -from collections import namedtuple +from envvars import generate_namedtuple_from_prefixed_envvars -TFW_PREFIX = 'TFW_' -tfwenvvars = {envvar.replace(TFW_PREFIX, '', 1): environ.get(envvar) - for envvar in environ.keys() - if envvar.startswith(TFW_PREFIX)} -tfwenv = namedtuple('tfwenvtuple', tfwenvvars)(**tfwenvvars) - -AVATAO_SECRET = getenv('AVATAO_SECRET', 'secret') +tfwenv = generate_namedtuple_from_prefixed_envvars('TFW_', 'tfwenvtuple') diff --git a/src/controller/app.py b/src/controller/app.py index 73b321c..c304231 100644 --- a/src/controller/app.py +++ b/src/controller/app.py @@ -1,7 +1,8 @@ from tornado.ioloop import IOLoop from tornado.web import Application -from tfw.config import tfwenv, AVATAO_SECRET +from tao.config import taoenv +from tfw.config import tfwenv from handlers import SolutionCheckHandler, TestHandler from tfw.networking.solvable_connector import SolvableConnector @@ -11,8 +12,8 @@ log = logging.getLogger(__name__) if __name__ == '__main__': solvable_connector = SolvableConnector() routes = [ - (r'/{secret}/?'.format(secret=AVATAO_SECRET), SolutionCheckHandler, {'solvable_connector': solvable_connector}), - (r'/{secret}/test/?'.format(secret=AVATAO_SECRET), TestHandler, {'solvable_connector': solvable_connector}) + (r'/{secret}/?'.format(secret=taoenv.SECRET), SolutionCheckHandler, {'solvable_connector': solvable_connector}), + (r'/{secret}/test/?'.format(secret=taoenv.SECRET), TestHandler, {'solvable_connector': solvable_connector}) ] app = Application( routes From 1e9642912c9d88e878d14d6733d6a3240611a12b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Fri, 9 Feb 2018 17:27:51 +0100 Subject: [PATCH 15/20] Create initial implementation for solution check --- lib/tfw/fsm_base.py | 8 +++++++- src/app/app.py | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/tfw/fsm_base.py b/lib/tfw/fsm_base.py index d6a586c..fc1300f 100644 --- a/lib/tfw/fsm_base.py +++ b/lib/tfw/fsm_base.py @@ -1,11 +1,14 @@ +from typing import List + from transitions import Machine class FSMBase: states, transitions = [], [] - def __init__(self, initial: str = None): + def __init__(self, initial: str = None, accepted_states: List[str] = None): self.message_handlers = [] + self.accepted_states = accepted_states or [self.states[-1]] self.machine = Machine(model=self, states=self.states, transitions=self.transitions, @@ -24,3 +27,6 @@ class FSMBase: def unsubscribe_message_handler(self, msghandler): self.message_handlers.remove(msghandler) + + def is_solved(self): + return self.state in self.accepted_states diff --git a/src/app/app.py b/src/app/app.py index 383fd9a..70d3c65 100644 --- a/src/app/app.py +++ b/src/app/app.py @@ -20,8 +20,8 @@ def zmq_callback(stream, msg_parts): stream.send_multipart(serialize_all(key, 'OK')) if key == 'solution_check': stream.send_multipart(serialize_all(key, { - 'solved': True, - 'message': 'solved' + 'solved': fsm.is_solved(), + 'message': 'solved' if fsm.is_solved() else 'not solved' })) From bcd31de8521c1541bd79a0470e78c1e6c359bf78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sun, 11 Feb 2018 11:50:40 +0100 Subject: [PATCH 16/20] Begin refactoring app.py to TFWServer class --- src/app/app.py | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/src/app/app.py b/src/app/app.py index 70d3c65..3435903 100644 --- a/src/app/app.py +++ b/src/app/app.py @@ -14,30 +14,37 @@ log = logging.getLogger(__name__) from tfw.networking.server.zmq_websocket_handler import FSMManagingSocketHandler -def zmq_callback(stream, msg_parts): - key, data = deserialize_all(*msg_parts) - if key == 'test': - stream.send_multipart(serialize_all(key, 'OK')) - if key == 'solution_check': - stream.send_multipart(serialize_all(key, { - 'solved': fsm.is_solved(), - 'message': 'solved' if fsm.is_solved() else 'not solved' - })) +class TFWServer: + def __init__(self, fsm_type): + self._fsm = fsm_type() + self.application = Application( + [(r'/ws', FSMManagingSocketHandler, {'fsm': self.fsm})], + autoreload=True + ) + self.controller_connector = ControllerConnector() + self.controller_connector.register_callback(self.zmq_callback) + + @property + def fsm(self): + return self._fsm + + def zmq_callback(self, stream, msg_parts): + key, data = deserialize_all(*msg_parts) + if key == 'test': + stream.send_multipart(serialize_all(key, 'OK')) + if key == 'solution_check': + stream.send_multipart(serialize_all(key, { + 'solved': self.fsm.is_solved(), + 'message': 'solved' if self.fsm.is_solved() else 'not solved' + })) + + def listen(self, port): + self.application.listen(port) if __name__ == '__main__': - fsm = SQLInjectionFSM() - controller_connector = ControllerConnector() - controller_connector.register_callback(zmq_callback) - routes = [ - (r'/ws', FSMManagingSocketHandler, {'fsm': fsm}), - ] - application = Application( - routes, - autoreload=True - ) - - application.listen(tfwenv.WEB_PORT) + server = TFWServer(SQLInjectionFSM) + server.listen(tfwenv.WEB_PORT) log.debug('Python version: {}'.format(sys.version[:5])) log.debug('Tornado version: {}'.format(tornado.version)) log.debug('ZeroMQ version: {}'.format(zmq.zmq_version())) From 0f6ec24d450418ef1ceeffd9d8cc7ea3ae69109e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sun, 11 Feb 2018 12:04:18 +0100 Subject: [PATCH 17/20] Remove unnecessary overrides from ZMQWebSocketHandler --- lib/tfw/networking/server/zmq_websocket_handler.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/tfw/networking/server/zmq_websocket_handler.py b/lib/tfw/networking/server/zmq_websocket_handler.py index 3262f2a..35d5fec 100644 --- a/lib/tfw/networking/server/zmq_websocket_handler.py +++ b/lib/tfw/networking/server/zmq_websocket_handler.py @@ -26,15 +26,9 @@ class ZMQWebSocketHandler(WebSocketHandler): log.debug('Received on WebSocket: {}'.format(message)) self.send_message(*self.make_response(json.loads(message))) - def make_response(self, message): - raise NotImplementedError - def send_message(self, message: dict, anchor: str = None): self._event_handler_connector.send_message(message, anchor) - def on_close(self): - pass - # much secure, very cors, wow def check_origin(self, origin): return True From 4fe9d58681457455f2f0c5d9cae416525601444d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sun, 11 Feb 2018 12:32:30 +0100 Subject: [PATCH 18/20] Move TFWServer to tfw.networking.server package --- lib/tfw/networking/server/tfw_server.py | 33 ++++++++++++++++++++++++ src/app/app.py | 34 +------------------------ 2 files changed, 34 insertions(+), 33 deletions(-) create mode 100644 lib/tfw/networking/server/tfw_server.py diff --git a/lib/tfw/networking/server/tfw_server.py b/lib/tfw/networking/server/tfw_server.py new file mode 100644 index 0000000..fbd5ec3 --- /dev/null +++ b/lib/tfw/networking/server/tfw_server.py @@ -0,0 +1,33 @@ +from tornado.web import Application + +from tfw.networking.controller_connector import ControllerConnector +from tfw.networking.serialization import deserialize_all, serialize_all +from tfw.networking.server.zmq_websocket_handler import FSMManagingSocketHandler + + +class TFWServer: + def __init__(self, fsm_type): + self._fsm = fsm_type() + self.application = Application( + [(r'/ws', FSMManagingSocketHandler, {'fsm': self.fsm})], + autoreload=True + ) + self.controller_connector = ControllerConnector() + self.controller_connector.register_callback(self.zmq_callback) + + @property + def fsm(self): + return self._fsm + + def zmq_callback(self, stream, msg_parts): + key, data = deserialize_all(*msg_parts) + if key == 'test': + stream.send_multipart(serialize_all(key, 'OK')) + if key == 'solution_check': + stream.send_multipart(serialize_all(key, { + 'solved': self.fsm.is_solved(), + 'message': 'solved' if self.fsm.is_solved() else 'not solved' + })) + + def listen(self, port): + self.application.listen(port) diff --git a/src/app/app.py b/src/app/app.py index 3435903..de73eee 100644 --- a/src/app/app.py +++ b/src/app/app.py @@ -1,45 +1,13 @@ import sys import tornado import zmq -from tornado.web import Application from tornado.ioloop import IOLoop from sql_injection_fsm import SQLInjectionFSM +from tfw.networking.server.tfw_server import TFWServer from tfw.config import tfwenv from tfw.config.logs import logging -from tfw.networking.controller_connector import ControllerConnector -from tfw.networking.serialization import deserialize_all, serialize_all - log = logging.getLogger(__name__) -from tfw.networking.server.zmq_websocket_handler import FSMManagingSocketHandler - - -class TFWServer: - def __init__(self, fsm_type): - self._fsm = fsm_type() - self.application = Application( - [(r'/ws', FSMManagingSocketHandler, {'fsm': self.fsm})], - autoreload=True - ) - self.controller_connector = ControllerConnector() - self.controller_connector.register_callback(self.zmq_callback) - - @property - def fsm(self): - return self._fsm - - def zmq_callback(self, stream, msg_parts): - key, data = deserialize_all(*msg_parts) - if key == 'test': - stream.send_multipart(serialize_all(key, 'OK')) - if key == 'solution_check': - stream.send_multipart(serialize_all(key, { - 'solved': self.fsm.is_solved(), - 'message': 'solved' if self.fsm.is_solved() else 'not solved' - })) - - def listen(self, port): - self.application.listen(port) if __name__ == '__main__': From 1692b424b5eb992a198546accb76b4373b9e9ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sun, 11 Feb 2018 14:15:10 +0100 Subject: [PATCH 19/20] Move webide and terminado event handlers to lib/tfw/components --- Dockerfile | 14 +++++++------- .../tfw/components}/source_code_event_handler.py | 0 .../tfw/components}/terminado_event_handler.py | 7 ------- .../tfw/components/terminado_mini_server.py | 0 src/{app => demo}/app.py | 0 .../event_handler_main.py | 4 ++-- .../source_code_server/login_component.py | 0 .../source_code_server/server.py | 0 .../source_code_server/users.db | Bin src/{app => demo}/sql_injection_fsm.py | 0 supervisor/components/event_handlers.conf | 2 +- supervisor/components/terminado.conf | 2 +- 12 files changed, 11 insertions(+), 18 deletions(-) rename {src/event_handlers => lib/tfw/components}/source_code_event_handler.py (100%) rename {src/event_handlers => lib/tfw/components}/terminado_event_handler.py (72%) rename src/event_handlers/terminado_server/server.py => lib/tfw/components/terminado_mini_server.py (100%) rename src/{app => demo}/app.py (100%) rename src/{event_handlers => demo}/event_handler_main.py (65%) rename src/{event_handlers => demo}/source_code_server/login_component.py (100%) rename src/{event_handlers => demo}/source_code_server/server.py (100%) rename src/{event_handlers => demo}/source_code_server/users.db (100%) rename src/{app => demo}/sql_injection_fsm.py (100%) diff --git a/Dockerfile b/Dockerfile index c5d1741..07e969f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,7 +52,6 @@ EXPOSE ${TFW_PUBLIC_PORT} EXPOSE ${TFW_CRP_LISTENER_PORT} ENV TFW_SUPERVISOR_HTTP_URI="http://localhost:${TFW_SUPERVISOR_HTTP_PORT}" -ENV TFW_EVENT_HANDLERS_DIR="/opt/event_handlers" ENV TFW_APP_DIR="/srv/app" ENV TFW_CONTROLLER_DIR="/srv/controller" ENV TFW_FRONTEND_DIR="/srv/frontend" @@ -75,18 +74,19 @@ RUN chown -R ${AVATAO_USER} /var/log/nginx /var/lib/nginx &&\ envsubst "$(printenv | cut -d= -f1 | grep TFW_ | sed -e 's/^/$/g')" < $f > $f ;\ done -COPY lib ${TFW_LIB_DIR} COPY supervisor/supervisord.conf ${TFW_SUPERVISORD_CONF} COPY supervisor/components/ ${TFW_SUPERVISORD_COMPONENTS} -COPY src/app ${TFW_APP_DIR} -COPY src/event_handlers ${TFW_EVENT_HANDLERS_DIR} +COPY lib ${TFW_LIB_DIR} COPY src/controller ${TFW_CONTROLLER_DIR} +COPY lib/tfw/components/terminado_mini_server.py ${TFW_TERMINADO_DIR}/ RUN mv /data/dist ${TFW_FRONTEND_DIR} -COPY src/event_handlers/source_code_server/server.py ${TFW_LOGIN_APP_DIR}/ -COPY src/event_handlers/source_code_server/users.db ${TFW_LOGIN_APP_DIR}/ -COPY src/event_handlers/source_code_server/login_component.py ${TFW_WEBIDE_WD}/ +COPY src/demo ${TFW_APP_DIR}/ + +COPY src/demo/source_code_server/server.py ${TFW_LOGIN_APP_DIR}/ +COPY src/demo/source_code_server/users.db ${TFW_LOGIN_APP_DIR}/ +COPY src/demo/source_code_server/login_component.py ${TFW_WEBIDE_WD}/ RUN chown -R ${AVATAO_USER} ${TFW_WEBIDE_WD} && chmod -R 755 ${TFW_WEBIDE_WD} diff --git a/src/event_handlers/source_code_event_handler.py b/lib/tfw/components/source_code_event_handler.py similarity index 100% rename from src/event_handlers/source_code_event_handler.py rename to lib/tfw/components/source_code_event_handler.py diff --git a/src/event_handlers/terminado_event_handler.py b/lib/tfw/components/terminado_event_handler.py similarity index 72% rename from src/event_handlers/terminado_event_handler.py rename to lib/tfw/components/terminado_event_handler.py index 9852247..4222e05 100644 --- a/src/event_handlers/terminado_event_handler.py +++ b/lib/tfw/components/terminado_event_handler.py @@ -1,5 +1,3 @@ -from shutil import rmtree, copytree - from tfw.event_handler_base import EventHandlerBase from tfw.util import SupervisorMixin from tfw.config import tfwenv @@ -12,11 +10,6 @@ class TerminadoEventHandler(EventHandlerBase, SupervisorMixin): super().__init__(anchor) self.working_directory = tfwenv.TERMINADO_DIR self.process_name = process_name - self.setup_terminado_server() - - def setup_terminado_server(self): - rmtree(self.working_directory, ignore_errors=True) - copytree('terminado_server/', self.working_directory) self.start_process() def handle_event(self, anchor, data_json): diff --git a/src/event_handlers/terminado_server/server.py b/lib/tfw/components/terminado_mini_server.py similarity index 100% rename from src/event_handlers/terminado_server/server.py rename to lib/tfw/components/terminado_mini_server.py diff --git a/src/app/app.py b/src/demo/app.py similarity index 100% rename from src/app/app.py rename to src/demo/app.py diff --git a/src/event_handlers/event_handler_main.py b/src/demo/event_handler_main.py similarity index 65% rename from src/event_handlers/event_handler_main.py rename to src/demo/event_handler_main.py index b349b6b..f7623a9 100644 --- a/src/event_handlers/event_handler_main.py +++ b/src/demo/event_handler_main.py @@ -1,5 +1,5 @@ -from source_code_event_handler import SourceCodeEventHandler -from terminado_event_handler import TerminadoEventHandler +from tfw.components.source_code_event_handler import SourceCodeEventHandler +from tfw.components.terminado_event_handler import TerminadoEventHandler from tornado.ioloop import IOLoop from tfw.config import tfwenv diff --git a/src/event_handlers/source_code_server/login_component.py b/src/demo/source_code_server/login_component.py similarity index 100% rename from src/event_handlers/source_code_server/login_component.py rename to src/demo/source_code_server/login_component.py diff --git a/src/event_handlers/source_code_server/server.py b/src/demo/source_code_server/server.py similarity index 100% rename from src/event_handlers/source_code_server/server.py rename to src/demo/source_code_server/server.py diff --git a/src/event_handlers/source_code_server/users.db b/src/demo/source_code_server/users.db similarity index 100% rename from src/event_handlers/source_code_server/users.db rename to src/demo/source_code_server/users.db diff --git a/src/app/sql_injection_fsm.py b/src/demo/sql_injection_fsm.py similarity index 100% rename from src/app/sql_injection_fsm.py rename to src/demo/sql_injection_fsm.py diff --git a/supervisor/components/event_handlers.conf b/supervisor/components/event_handlers.conf index 887c1c6..a28afe5 100644 --- a/supervisor/components/event_handlers.conf +++ b/supervisor/components/event_handlers.conf @@ -1,3 +1,3 @@ [program:event_handler_main] -directory=%(ENV_TFW_EVENT_HANDLERS_DIR)s +directory=%(ENV_TFW_APP_DIR)s command=env python event_handler_main.py diff --git a/supervisor/components/terminado.conf b/supervisor/components/terminado.conf index ccf7595..30c441d 100644 --- a/supervisor/components/terminado.conf +++ b/supervisor/components/terminado.conf @@ -1,4 +1,4 @@ [program:terminado] directory=%(ENV_TFW_TERMINADO_DIR)s -command=env python server.py +command=env python terminado_mini_server.py autostart=false From ec83cbe7a0a0449da3300cb251e306663f0bbb9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sun, 11 Feb 2018 15:20:06 +0100 Subject: [PATCH 20/20] Make Dockerfile bootiful again --- Dockerfile | 97 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 47 deletions(-) diff --git a/Dockerfile b/Dockerfile index 07e969f..4147105 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,19 @@ FROM avatao/ubuntu:16.04 -RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - &&\ - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - &&\ +RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - &&\ + curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - &&\ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list &&\ - apt-get update &&\ + apt-get update &&\ apt-get install -y --no-install-recommends \ - nodejs \ - yarn \ - supervisor \ - libzmq5 \ - nginx \ - gettext-base \ - libbz2-dev \ - libreadline-dev \ - libsqlite3-dev &&\ + nodejs \ + yarn \ + supervisor \ + libzmq5 \ + nginx \ + gettext-base \ + libbz2-dev \ + libreadline-dev \ + libsqlite3-dev &&\ rm -rf /var/lib/apt/lists/* USER ${AVATAO_USER} @@ -23,14 +23,14 @@ COPY requirements.txt /tmp ARG PYTHON_VERSION="3.6.4" ARG PYENV_INSTALLER_URL="https://raw.githubusercontent.com/pyenv/pyenv-installer/78cfd4d/bin/pyenv-installer" ARG PYENV_INSTALLER_HASH=9509348b828f0564358fff456f7f693dd9ace351dc3f240854d7685ad8a8e1dd -RUN curl -fSL -o pyenv-installer ${PYENV_INSTALLER_URL} &&\ +RUN curl -fSL -o pyenv-installer ${PYENV_INSTALLER_URL} &&\ echo "${PYENV_INSTALLER_HASH} *pyenv-installer" | sha256sum -c - &&\ - bash pyenv-installer &&\ - rm pyenv-installer &&\ - echo "source $HOME/.pyenvrc" >> .bashrc &&\ - . $HOME/.pyenvrc &&\ - pyenv install ${PYTHON_VERSION} &&\ - pyenv global ${PYTHON_VERSION} &&\ + bash pyenv-installer &&\ + rm pyenv-installer &&\ + echo "source $HOME/.pyenvrc" >> .bashrc &&\ + . $HOME/.pyenvrc &&\ + pyenv install ${PYTHON_VERSION} &&\ + pyenv global ${PYTHON_VERSION} &&\ pip install -r /tmp/requirements.txt USER root @@ -39,38 +39,34 @@ COPY src/frontend /data/ RUN yarn install --frozen-lockfile RUN yarn build --no-progress -ENV TFW_WEB_PORT=4242 -ENV TFW_LOGIN_APP_PORT=6666 -ENV TFW_TERMINADO_PORT=7878 -ENV TFW_SUPERVISOR_HTTP_PORT=9001 -ENV TFW_PUBLIC_PORT=8888 -ENV TFW_CONTROLLER_PORT=7777 -ENV TFW_CRP_LISTENER_PORT=5555 -ENV TFW_PUBLISHER_PORT=7654 -ENV TFW_RECEIVER_PORT=8765 -EXPOSE ${TFW_PUBLIC_PORT} -EXPOSE ${TFW_CRP_LISTENER_PORT} +ENV TFW_PUBLIC_PORT=8888 \ + TFW_WEB_PORT=4242 \ + TFW_LOGIN_APP_PORT=6666 \ + TFW_TERMINADO_PORT=7878 \ + TFW_SUPERVISOR_HTTP_PORT=9001 \ + TFW_CONTROLLER_PORT=7777 \ + TFW_CRP_LISTENER_PORT=5555 \ + TFW_PUBLISHER_PORT=7654 \ + TFW_RECEIVER_PORT=8765 -ENV TFW_SUPERVISOR_HTTP_URI="http://localhost:${TFW_SUPERVISOR_HTTP_PORT}" -ENV TFW_APP_DIR="/srv/app" -ENV TFW_CONTROLLER_DIR="/srv/controller" -ENV TFW_FRONTEND_DIR="/srv/frontend" -ENV TFW_LOGIN_APP_DIR="/tmp/source_code_server" -ENV TFW_TERMINADO_DIR="/tmp/terminado_server" -ENV TFW_WEBIDE_WD="/home/${AVATAO_USER}/workdir" -ENV TFW_TERMINADO_WD=${TFW_WEBIDE_WD} -ENV TFW_LIB_DIR="/usr/local/lib/" -ENV TFW_SUPERVISORD_CONF="/etc/supervisor/supervisord.conf" -ENV TFW_SUPERVISORD_COMPONENTS="/etc/supervisor/conf" -ENV TFW_NGINX_CONF="/etc/nginx/sites-enabled/default" -ENV TFW_NGINX_COMPONENTS="/etc/nginx/components" -ENV PYTHONPATH=${TFW_LIB_DIR} +EXPOSE ${TFW_PUBLIC_PORT} ${TFW_CRP_LISTENER_PORT} + +ENV PYTHONPATH="/usr/local/lib/" \ + TFW_SUPERVISOR_HTTP_URI="http://localhost:${TFW_SUPERVISOR_HTTP_PORT}" \ + TFW_SUPERVISORD_CONF="/etc/supervisor/supervisord.conf" \ + TFW_SUPERVISORD_COMPONENTS="/etc/supervisor/conf" \ + TFW_NGINX_CONF="/etc/nginx/sites-enabled/default" \ + TFW_NGINX_COMPONENTS="/etc/nginx/components" \ + TFW_LIB_DIR="/usr/local/lib/" \ + TFW_CONTROLLER_DIR="/srv/controller" \ + TFW_TERMINADO_DIR="/tmp/terminado_server" \ + TFW_FRONTEND_DIR="/srv/frontend" COPY nginx/nginx.conf ${TFW_NGINX_CONF} COPY nginx/components/ ${TFW_NGINX_COMPONENTS} -RUN chown -R ${AVATAO_USER} /var/log/nginx /var/lib/nginx &&\ - sed -i 's#pid /run/nginx.pid;#pid /tmp/nginx.pid;#g' /etc/nginx/nginx.conf &&\ - for f in "${TFW_NGINX_CONF}" ${TFW_NGINX_COMPONENTS}/*.conf; do \ +RUN chown -R ${AVATAO_USER} /var/log/nginx /var/lib/nginx &&\ + sed -i 's#pid /run/nginx.pid;#pid /tmp/nginx.pid;#g' /etc/nginx/nginx.conf &&\ + for f in "${TFW_NGINX_CONF}" ${TFW_NGINX_COMPONENTS}/*.conf; do \ envsubst "$(printenv | cut -d= -f1 | grep TFW_ | sed -e 's/^/$/g')" < $f > $f ;\ done @@ -80,6 +76,13 @@ COPY lib ${TFW_LIB_DIR} COPY src/controller ${TFW_CONTROLLER_DIR} COPY lib/tfw/components/terminado_mini_server.py ${TFW_TERMINADO_DIR}/ +### TFW internals ^ ### DEMO v ############################################################### + +ENV TFW_APP_DIR="/srv/app" \ + TFW_LOGIN_APP_DIR="/tmp/source_code_server" \ + TFW_WEBIDE_WD="/home/${AVATAO_USER}/workdir" \ + TFW_TERMINADO_WD="/home/${AVATAO_USER}/workdir" + RUN mv /data/dist ${TFW_FRONTEND_DIR} COPY src/demo ${TFW_APP_DIR}/