Skip to content

Commit

Permalink
Use Tornado webserver to fix subpath routing bug.
Browse files Browse the repository at this point in the history
Remove help request system components.
  • Loading branch information
manning-ncsa committed Jan 6, 2024
1 parent d1eb371 commit a3990ab
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 66 deletions.
41 changes: 9 additions & 32 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
FROM node:20 as build

# RUN apt-get update && \
# apt-get install -y \
# python3-pip \
# wget \
# && rm -rf /var/lib/apt/lists/*

# Basic python reqs
# RUN pip3 install --no-cache-dir jira
# RUN pip3 install --no-cache-dir netaddr
# RUN pip3 install --no-cache-dir bcrypt
# RUN pip3 install --no-cache-dir pyyaml
# RUN pip3 install --no-cache-dir tornado==5.0.1
# RUN pip install --no-cache-dir jsmin

# WORKDIR /tmp
# ADD https://nodejs.org/dist/v12.14.1/node-v12.14.1-linux-x64.tar.xz
# RUN tar -C /usr/local --strip-components 1 -xf /tmp/node-v12.14.1-linux-x64.tar.xz
RUN npm install -g [email protected]

# RUN useradd --create-home --shell /bin/bash des --uid 1001
# USER des
WORKDIR /opt
COPY --chown=des:des ./ ./

Expand All @@ -31,19 +11,16 @@ RUN vulcanize static/des_components/elements.html \
--exclude static/bower_components/polymer/lib/legacy/ \
--out-html static/des_components/elements-built.html

FROM jekyll/jekyll:3.8
## Currently jekyll/jekyll:4 fails with the error below so tag 3.8 is used instead.

ENV JEKYLL_UID=1000
ENV JEKYLL_GID=1000

USER ${JEKYLL_UID}
FROM python:3.9

## Install required gems
COPY ./Gemfile ./Gemfile
RUN bundle install
RUN pip install --no-cache-dir jira
RUN pip install --no-cache-dir netaddr
RUN pip install --no-cache-dir bcrypt
RUN pip install --no-cache-dir pyyaml
RUN pip install --no-cache-dir tornado==5.0.1
RUN pip install --no-cache-dir jsmin

## Copy source files
COPY --from=build --chown=${JEKYLL_UID}:${JEKYLL_GID} /opt/ ./
COPY --from=build /opt/ ./

CMD ["bundle", "exec", "jekyll", "serve", "--host=0.0.0.0", "--watch", "--drafts"]
CMD [ "python", "main.py" ]
18 changes: 18 additions & 0 deletions Settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
""" Settings for app"""
import os
DEBUG = False
DIRNAME = os.path.dirname(__file__)
if os.environ['APP_ROOT'] == '' or os.environ['APP_ROOT'] == '/':
APP_ROOT = ''
else:
APP_ROOT = r'/{}/'.format(os.environ['APP_ROOT'])
# Ensure string is like "/APP_ROOT" without trailing slash :
APP_ROOT = os.path.normpath(APP_ROOT)
STATIC_PATH = os.path.join(DIRNAME, 'static')
TEMPLATE_PATH = os.path.join(DIRNAME, 'templates')
import logging
# log linked to the standard error stream
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(levelname)-8s - %(message)s',
datefmt='%d/%m/%Y %Hh%Mm%Ss')
# console = logging.StreamHandler(sys.stderr)
12 changes: 12 additions & 0 deletions global_vars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
import logging

# Configure logging
logging.basicConfig(
format='%(asctime)s [%(name)-12s] %(levelname)-8s %(message)s',
)
log = logging.getLogger("desdm-public")
try:
log.setLevel(os.environ['LOG_LEVEL'])
except:
log.setLevel('WARNING')
75 changes: 75 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
""" Main application for public release"""
import tornado.auth
import tornado.escape
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.log
import Settings
from tornado.options import define, options
import os
from global_vars import log

define("port", default=8080, help="run on the given port", type=int)

BASE_URL = os.environ['BASE_URL']

class BaseHandler(tornado.web.RequestHandler):
def get_current_user(self):
return self.get_secure_cookie("user")

class MainHandler(tornado.web.RequestHandler):
"""
Class that handle most of the request, all the rest of the handling is done
by page.js
"""
@tornado.web.asynchronous
def get(self, path = ''):
self.render('index.html', rootPath = r'{}/'.format(Settings.APP_ROOT))

#passwords = read_passwd_file()
#if verify_password(passwords, basicauth_user, basicauth_pass):
#self.render('index.html')

class My404Handler(tornado.web.RequestHandler):
"""
Handles 404 requests, basically bust just changin the status to 404
"""
def get(self):
self.set_status(404)
self.render('index.html', chichi=False)
def post(self):
self.set_status(404)
self.render('index.html', chichi=False)

class Application(tornado.web.Application):
"""
The tornado application class
"""
def __init__(self):
# The order of the route handlers matters!
handlers = [
(r"{}".format(Settings.APP_ROOT), MainHandler),
(r"{}/static/(.*)".format(Settings.APP_ROOT), tornado.web.StaticFileHandler, {'path':Settings.STATIC_PATH}),
(r"{}/(.*)".format(Settings.APP_ROOT), MainHandler),
]
settings = {
"template_path":Settings.TEMPLATE_PATH,
"debug":Settings.DEBUG,
"default_handler_class": My404Handler,
}
tornado.web.Application.__init__(self, handlers, **settings)

def main():
"""
The main function
"""
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(Application())
#http_server = tornado.httpserver.HTTPServer(Application(), ssl_options={"certfile": "/etc/httpd/ssl/des.crt", "keyfile": "/etc/httpd/ssl/des.key",})
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()

if __name__ == "__main__":
main()
9 changes: 0 additions & 9 deletions templates/already_received.html

This file was deleted.

8 changes: 0 additions & 8 deletions templates/easyweb_bypass.html

This file was deleted.

8 changes: 0 additions & 8 deletions templates/invalid_token.html

This file was deleted.

9 changes: 0 additions & 9 deletions templates/submission_confirmed.html

This file was deleted.

0 comments on commit a3990ab

Please sign in to comment.