mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 12:41:31 +00:00
Implement and integrate TerminadoEvendHandler to docker container
This commit is contained in:
parent
6b6f4942c0
commit
83b66c47b5
@ -33,7 +33,7 @@ RUN curl -fSL -o pyenv-installer ${PYENV_INSTALLER_URL} &&\
|
||||
. $HOME/.pyenvrc &&\
|
||||
pyenv install ${PYTHON_VERSION} &&\
|
||||
pyenv global ${PYTHON_VERSION} &&\
|
||||
pip install tornado pyzmq transitions
|
||||
pip install tornado pyzmq transitions terminado
|
||||
|
||||
USER root
|
||||
WORKDIR /data/
|
||||
@ -43,15 +43,17 @@ RUN yarn build --no-progress
|
||||
|
||||
ENV TFW_WEB_PORT=4242
|
||||
ENV TFW_LOGIN_APP_PORT=6666
|
||||
ENV TFW_TERMINADO_PORT=7878
|
||||
ENV TFW_PUBLIC_PORT=8888
|
||||
ENV TFW_SUPERVISOR_HTTP_PORT=9001
|
||||
|
||||
EXPOSE ${TFW_PUBLIC_PORT}
|
||||
EXPOSE ${TFW_PUBLIC_PORT} ${TFW_TERMINADO_PORT}
|
||||
|
||||
ENV TFW_EVENT_HANDLERS_DIR="/opt/event_handlers"
|
||||
ENV TFW_APP_DIR="/srv/app"
|
||||
ENV TFW_FRONTEND_DIR="/srv/frontend"
|
||||
ENV TFW_LOGIN_APP_DIR="/tmp/source_code_server"
|
||||
ENV TFW_TERMINADO_DIR="/tmp/terminado_server"
|
||||
ENV TFW_LIB_DIR="/usr/local/lib/"
|
||||
|
||||
ENV TFW_SUPERVISORD_CONF="/etc/supervisor/supervisord.conf"
|
||||
|
@ -5,7 +5,9 @@ RECEIVER_PORT = os.getenv('RECEIVER_PORT', 8765)
|
||||
WEB_PORT = os.getenv('TFW_WEB_PORT', 4242)
|
||||
SUPERVISOR_HTTP_PORT = os.getenv('TFW_SUPERVISOR_PORT', 9001)
|
||||
LOGIN_APP_PORT= os.getenv('TFW_LOGIN_APP_PORT', 6666)
|
||||
TERMINADO_PORT= os.getenv('TFW_TERMINADO_PORT', 9999)
|
||||
|
||||
SUPERVISOR_HTTP_URI = 'http://localhost:{}'.format(SUPERVISOR_HTTP_PORT)
|
||||
|
||||
LOGIN_APP_DIR = os.getenv('TFW_LOGIN_APP_DIR')
|
||||
TERMINADO_DIR = os.getenv('TFW_TERMINADO_DIR')
|
||||
|
@ -5,6 +5,7 @@ from functools import partial
|
||||
import source_code
|
||||
from event_handler_base import EventHandlerBase
|
||||
from source_code_event_handler import SourceCodeEventHandler
|
||||
from terminado_event_handler import TerminadoEventHandler
|
||||
from tornado.ioloop import IOLoop
|
||||
|
||||
from login_component import authorize_login
|
||||
@ -86,5 +87,6 @@ if __name__ == '__main__':
|
||||
anchor_b = Rot13Handler('anchor_b')
|
||||
anchor_c = ReverseHandler('anchor_c')
|
||||
anchor_webide = SourceCodeEventHandler('anchor_webide', 'login_component.py', 'login')
|
||||
anchor_terminado = TerminadoEventHandler('anchor_terminado', 'terminado')
|
||||
IOLoop.instance().start()
|
||||
|
||||
|
@ -1,33 +1,21 @@
|
||||
import logging
|
||||
from shutil import rmtree, copytree
|
||||
|
||||
from event_handler_base import EventHandlerBase
|
||||
from tornado.ioloop import IOLoop
|
||||
from tornado.web import Application
|
||||
from terminado import TermSocket, SingleTermManager
|
||||
from util import SupervisorMixin
|
||||
from config import TERMINADO_DIR
|
||||
|
||||
|
||||
class CORSTermSocket(TermSocket):
|
||||
def check_origin(self, origin):
|
||||
return True
|
||||
|
||||
|
||||
class TerminadoEventHandler(EventHandlerBase):
|
||||
def __init__(self, anchor, zmq_context=None):
|
||||
class TerminadoEventHandler(EventHandlerBase, SupervisorMixin):
|
||||
def __init__(self, anchor, process_name, zmq_context=None):
|
||||
super().__init__(anchor, zmq_context)
|
||||
self.working_directory = 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.supervisor.startProcess(self.process_name)
|
||||
|
||||
def handle_event(self, anchor, data_json):
|
||||
raise NotImplementedError # TODO: wat do?
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
application = Application(
|
||||
[(
|
||||
r'/terminal',
|
||||
CORSTermSocket,
|
||||
{'term_manager': SingleTermManager(shell_command=['bash'])}
|
||||
)]
|
||||
)
|
||||
HOST, PORT = 'localhost', 7878
|
||||
application.listen(PORT, HOST)
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
logging.info('Terminado Mini Server listening on {}:{}'.format(HOST, PORT))
|
||||
IOLoop.instance().start()
|
||||
|
24
src/event_handlers/terminado_server/server.py
Normal file
24
src/event_handlers/terminado_server/server.py
Normal file
@ -0,0 +1,24 @@
|
||||
import logging
|
||||
from tornado.ioloop import IOLoop
|
||||
from tornado.web import Application
|
||||
from terminado import TermSocket, SingleTermManager
|
||||
|
||||
from config import TERMINADO_PORT
|
||||
|
||||
|
||||
class CORSTermSocket(TermSocket):
|
||||
def check_origin(self, origin):
|
||||
return True
|
||||
|
||||
if __name__ == '__main__':
|
||||
application = Application(
|
||||
[(
|
||||
r'/terminal',
|
||||
CORSTermSocket,
|
||||
{'term_manager': SingleTermManager(shell_command=['bash'])}
|
||||
)]
|
||||
)
|
||||
application.listen(TERMINADO_PORT)
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
logging.info('Terminado Mini Server listening on {}'.format(TERMINADO_PORT))
|
||||
IOLoop.instance().start()
|
@ -29,6 +29,11 @@ directory=%(ENV_TFW_LOGIN_APP_DIR)s
|
||||
command=env python server.py
|
||||
autostart=false
|
||||
|
||||
[program:terminado]
|
||||
directory=%(ENV_TFW_TERMINADO_DIR)s
|
||||
command=env python server.py
|
||||
autostart=false
|
||||
|
||||
[program:nginx]
|
||||
command=/usr/sbin/nginx -g 'daemon off;'
|
||||
autostart=true
|
||||
|
Loading…
Reference in New Issue
Block a user