Skip to content

Commit

Permalink
Merge pull request #86 from target/strelka-ui-app-refactor
Browse files Browse the repository at this point in the history
Strelka UI App, Improving Node Edge Readability, Encryption, and More
  • Loading branch information
phutelmyer authored May 30, 2024
2 parents e08ef3b + 0894f16 commit 15859e9
Show file tree
Hide file tree
Showing 59 changed files with 2,700 additions and 565 deletions.
36 changes: 20 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ FROM node:16-slim AS UI_BUILDER
# We are using a multi-stage build as we require node for
# building react.

# Copy package.json and package-lock.json into the builder.
# Copying just these files first allows us to take advantage
# of cached Docker layers.

# Define UI build arguments.
ARG REACT_APP_SEARCH_NAME
ARG REACT_APP_SEARCH_URL
Expand All @@ -10,9 +14,6 @@ ARG REACT_APP_SEARCH_URL
ENV REACT_APP_SEARCH_NAME=$REACT_APP_SEARCH_NAME
ENV REACT_APP_SEARCH_URL=$REACT_APP_SEARCH_URL

# Copy package.json and package-lock.json into the builder.
# Copying just these files first allows us to take advantage
# of cached Docker layers.
WORKDIR /usr/src/app
COPY ./ui/package.json ./ui/yarn.lock ./

Expand All @@ -24,43 +25,46 @@ COPY ./ui .
# Build the js app for production
RUN yarn run build

# Since we are serving it all from python, switch over to
# Since we are serving it all from python, switch over to
# a more appropriate base image.
FROM python:3.9-slim

RUN apt-get -y update && apt-get -y upgrade
RUN apt-get install -y build-essential libpq-dev

# Copy over just the Python backend app code.
WORKDIR /app
ENV ENV=production
RUN apt-get -y update && apt-get -y upgrade
RUN apt-get install -y build-essential libpq-dev libmagic1

# Set Runtime Variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH /app

# Install Poetry globally and copy project files
RUN python3 -m pip install -U pip setuptools && \
python3 -m pip install poetry && \
rm -rf /root/.cache/pip

# Set the working directory and copy the project files
COPY ./app/pyproject.toml ./app/poetry.lock ./
WORKDIR /app

# Use Poetry to install the project dependencies globally
# This step is after the COPY step because it is more likely to change,
# and therefore should not be included in earlier layers that can be cached.

COPY ./app/pyproject.toml ./app/poetry.lock ./

RUN poetry config virtualenvs.create false && \
poetry install --no-dev && \
poetry install --no-root --no-dev && \
rm -rf /root/.cache/pypoetry

WORKDIR /app
# Copy the other project files
COPY ./app .

# Copy the production UI assets into the new base image.
COPY --from=UI_BUILDER /usr/src/app/build/ ./react-app/
# Use Poetry to install the local package strelka-ui
RUN poetry install --only-root && \
rm -rf /root/.cache/pypoetry

# Copy the production UI assets into the new base image.
COPY --from=UI_BUILDER /usr/src/app/build/ ./strelka_ui/react-app/

# Run App
COPY entrypoint.sh .
RUN chmod +x entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2022 Target Brands, Inc.
Copyright (c) 2024 Target Brands, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Empty file removed app/__init__.py
Empty file.
Empty file removed app/blueprints/__init__.py
Empty file.
Empty file removed app/config/__init__.py
Empty file.
10 changes: 0 additions & 10 deletions app/node_modules/.yarn-integrity

This file was deleted.

621 changes: 620 additions & 1 deletion app/poetry.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions app/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "strelka-ui"
version = "0.1.0"
version = "2.43"
description = "Strelka's File Submission Portal"
authors = [
"Paul Hutelmyer <[email protected]>",
Expand Down Expand Up @@ -46,6 +46,7 @@ Pyrsistent = "0.18.0"
python = "^3.8"
Python-Dotenv = "0.17.1"
Python-Dateutil = "2.8.1"
rarfile = "^4.2"
Requests = "2.31.0"
Six = "1.16.0"
SQLAlchemy = "1.4.15"
Expand All @@ -57,7 +58,8 @@ Urllib3 = "1.26.18"
Waitress = "2.1.2"
Wrapt = "1.13.3"
vt-py = "0.18.0"

py7zr = "^0.21.0"
python-magic = "^0.4.27"

[tool.poetry.dev-dependencies]

Expand Down
Empty file removed app/strelka/__init__.py
Empty file.
19 changes: 11 additions & 8 deletions app/app.py → app/strelka_ui/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
from paste.translogger import TransLogger
from waitress import serve

from blueprints.auth import auth
from blueprints.strelka import strelka
from blueprints.ui import ui
from models import db

from strelka_ui.blueprints.auth import auth
from strelka_ui.blueprints.strelka import strelka
from strelka_ui.blueprints.ui import ui
from strelka_ui.models import db

def create_app() -> Flask:
"""Start and serve app assets and API endpoints"""
Expand All @@ -32,9 +31,9 @@ def create_app() -> Flask:
app.logger.info("Serving app static assets from %s", ui_folder)

if app.config["ENV"] == "production":
app.config.from_object("config.config.ProductionConfig")
app.config.from_object("strelka_ui.config.config.ProductionConfig")
else:
app.config.from_object("config.config.DevelopmentConfig")
app.config.from_object("strelka_ui.config.config.DevelopmentConfig")

app.logger.info(
"Using %s configuration",
Expand All @@ -60,9 +59,13 @@ def create_app() -> Flask:
if __name__ == "__main__":
logging.basicConfig(stream=sys.stdout, level=logging.INFO)

# Suppress thread wait warnings for Waitress
waitress_logger = logging.getLogger("waitress.queue")
waitress_logger.setLevel(logging.ERROR)

main_app: Flask = create_app()

serve(TransLogger(main_app, setup_console_handler=False), host="0.0.0.0", port=8080)

# uncomment below for local flask app development with hot reloading
main_app.run(host="0.0.0.0", port=80, threaded=True)
# main_app.run(host="0.0.0.0", port=80, threaded=True)
6 changes: 3 additions & 3 deletions app/blueprints/auth.py → app/strelka_ui/blueprints/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from flask import Blueprint, current_app, jsonify, request, session
from jsonschema import ValidationError, validate

from database import db
from models import ApiKey, User
from services.auth import auth_required, check_credentials
from strelka_ui.database import db
from strelka_ui.models import ApiKey, User
from strelka_ui.services.auth import auth_required, check_credentials

auth = Blueprint("auth", __name__, url_prefix="/auth")

Expand Down
Loading

0 comments on commit 15859e9

Please sign in to comment.