From 03c64a2a156a33baf95cfbc6042d03a6d4464c06 Mon Sep 17 00:00:00 2001 From: mickol34 <80098155+mickol34@users.noreply.github.com> Date: Wed, 2 Oct 2024 16:05:43 +0200 Subject: [PATCH] Migrate frontend to Vite (#409) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bump frontend dependencies and migrate from CRA to Vite Co-authored-by: MichaƂ Jura --- .dockerignore | 2 +- .gitignore | 2 + MANIFEST.in | 2 +- deploy/docker/dev.frontend.Dockerfile | 2 +- deploy/docker/dev.web.Dockerfile | 15 +- deploy/docker/web.Dockerfile | 4 +- src/app.py | 6 +- src/mqueryfront/{public => }/index.html | 14 +- src/mqueryfront/package-lock.json | 31318 ---------------- src/mqueryfront/package.json | 104 +- src/mqueryfront/src/query/QueryMatchesItem.js | 2 +- .../src/status/DatabaseTopology.js | 2 +- src/mqueryfront/vite.config.js | 48 + src/mqueryfront/yarn.lock | 2687 ++ 14 files changed, 2814 insertions(+), 31394 deletions(-) rename src/mqueryfront/{public => }/index.html (64%) delete mode 100644 src/mqueryfront/package-lock.json create mode 100644 src/mqueryfront/vite.config.js create mode 100644 src/mqueryfront/yarn.lock diff --git a/.dockerignore b/.dockerignore index a870d208..e4a671a8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,5 +8,5 @@ samples/ index/ e2e-state mquery.ini -src/mqueryfront/build +src/mqueryfront/dist src/mqueryfront/node_modules diff --git a/.gitignore b/.gitignore index e5c1f544..8687e9dd 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ mquery.egg-info/ package-lock.json build/ postgres/ +node_modules/ +dist/ diff --git a/MANIFEST.in b/MANIFEST.in index 6ce0c703..bd5bc2a9 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -graft src/mqueryfront/build +graft src/mqueryfront/dist diff --git a/deploy/docker/dev.frontend.Dockerfile b/deploy/docker/dev.frontend.Dockerfile index 45517b8f..c2f2a129 100644 --- a/deploy/docker/dev.frontend.Dockerfile +++ b/deploy/docker/dev.frontend.Dockerfile @@ -1,4 +1,4 @@ -FROM node:16 AS build +FROM node:18 AS build RUN npm install -g serve COPY src/mqueryfront /app diff --git a/deploy/docker/dev.web.Dockerfile b/deploy/docker/dev.web.Dockerfile index 6d45ab8f..24c037e7 100644 --- a/deploy/docker/dev.web.Dockerfile +++ b/deploy/docker/dev.web.Dockerfile @@ -1,6 +1,11 @@ -FROM python:3.10 +FROM node:18 AS build + +RUN npm install -g serve +COPY src/mqueryfront /app +WORKDIR /app +RUN npm install --legacy-peer-deps && npm run build -WORKDIR /usr/src/app/src +FROM python:3.10 RUN apt update; apt install -y cmake @@ -8,4 +13,8 @@ RUN apt update; apt install -y cmake COPY requirements.txt src/plugins/requirements-*.txt /tmp/ RUN ls /tmp/requirements*.txt | xargs -i,, pip --no-cache-dir install -r ,, -CMD pip install -e /usr/src/app && uvicorn mquery.app:app --host 0.0.0.0 --port 5000 --reload +COPY requirements.txt setup.py MANIFEST.in /usr/src/app/ +COPY src /usr/src/app/src/ +COPY --from=build "/app/dist" "/usr/src/app/src/mqueryfront/dist" +RUN pip3 install /usr/src/app +CMD uvicorn mquery.app:app --host 0.0.0.0 --port 5000 --reload diff --git a/deploy/docker/web.Dockerfile b/deploy/docker/web.Dockerfile index 18d3b759..fb3592a0 100644 --- a/deploy/docker/web.Dockerfile +++ b/deploy/docker/web.Dockerfile @@ -1,4 +1,4 @@ -FROM node:16 AS build +FROM node:18 AS build RUN npm install -g serve COPY src/mqueryfront /app @@ -15,6 +15,6 @@ RUN ls /tmp/requirements*.txt | xargs -i,, pip --no-cache-dir install -r ,, COPY requirements.txt setup.py MANIFEST.in /usr/src/app/ COPY src /usr/src/app/src/ -COPY --from=build "/app/build" "/usr/src/app/src/mqueryfront/build" +COPY --from=build "/app/dist" "/usr/src/app/src/mqueryfront/dist" RUN pip3 install /usr/src/app CMD ["uvicorn", "mquery.app:app", "--host", "0.0.0.0", "--port", "5000"] diff --git a/src/app.py b/src/app.py index eb42bc4f..7a22e499 100644 --- a/src/app.py +++ b/src/app.py @@ -575,7 +575,7 @@ def server() -> ServerSchema: @app.get("/query/{path}", include_in_schema=False) def serve_index(path: str) -> FileResponse: - return FileResponse(Path(__file__).parent / "mqueryfront/build/index.html") + return FileResponse(Path(__file__).parent / "mqueryfront/dist/index.html") @app.get("/recent", include_in_schema=False) @@ -586,14 +586,14 @@ def serve_index(path: str) -> FileResponse: @app.get("/about", include_in_schema=False) def serve_index_sub() -> FileResponse: # Static routes are always publicly accessible without authorisation. - return FileResponse(Path(__file__).parent / "mqueryfront/build/index.html") + return FileResponse(Path(__file__).parent / "mqueryfront/dist/index.html") app.mount( "/", StaticFiles( directory=os.path.join( - os.path.dirname(__file__), "mqueryfront", "build" + os.path.dirname(__file__), "mqueryfront", "dist" ), html=True, ), diff --git a/src/mqueryfront/public/index.html b/src/mqueryfront/index.html similarity index 64% rename from src/mqueryfront/public/index.html rename to src/mqueryfront/index.html index 8d5d9747..7df0635e 100644 --- a/src/mqueryfront/public/index.html +++ b/src/mqueryfront/index.html @@ -11,17 +11,8 @@ manifest.json provides metadata used when your web app is added to the homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/ --> - - - + + mquery | CERT.PL>_ @@ -29,6 +20,7 @@ You need to enable JavaScript to run this app.
+