From 952d7696c35efd2265ac74b572f404ad3a1e5fe3 Mon Sep 17 00:00:00 2001 From: Phil Edwards Date: Mon, 24 Nov 2025 16:14:20 -0500 Subject: [PATCH 1/5] Make .sh implementation of copy_fonts.py - Do copy_fonts.py without python - Expand echo statements - Make it cwd-independent --- scripts/copy_fonts.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 scripts/copy_fonts.sh diff --git a/scripts/copy_fonts.sh b/scripts/copy_fonts.sh new file mode 100755 index 0000000000..2c9f95f3e0 --- /dev/null +++ b/scripts/copy_fonts.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -euo pipefail + +script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) +cd "$script_dir/.." # go up above script folder + +dest_dir='./jsapp/fonts' + +# create folder if it doesn't exist +mkdir -p $dest_dir + +# copy fonts +shopt -s failglob +echo "Copying fonts from node_modules to jsapp/fonts..." +cp -v ./node_modules/@fontsource/roboto/files/roboto-latin-ext-*.wof* $dest_dir +cp -v ./node_modules/@fontsource/roboto-mono/files/roboto-mono-latin-ext-*.wof* $dest_dir +echo "DONE copying fonts." From 3ce96079899724eccbf30b5a556cdd9d17d56853 Mon Sep 17 00:00:00 2001 From: Phil Edwards Date: Mon, 24 Nov 2025 16:18:46 -0500 Subject: [PATCH 2/5] Use copy_fonts.sh in npm postinstall --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e96f868d0e..26d5b78e2e 100644 --- a/package.json +++ b/package.json @@ -245,7 +245,7 @@ "fix:css": "npm run lint:css -- --fix", "show-icons": "opn jsapp/fonts/k-icons.html", "generate-icons": "node ./scripts/generate_icons.js", - "copy-fonts": "python3 ./scripts/copy_fonts.py && npm run generate-icons", + "copy-fonts": "./scripts/copy_fonts.sh && npm run generate-icons", "hint": "node ./scripts/hints.js", "storybook": "npm run storybook:watch", "storybook:launch": "npx http-server storybook-static --port 6006 --silent", From 4eaae8d64f908e7966dc96bb415764a9c093b53b Mon Sep 17 00:00:00 2001 From: Phil Edwards Date: Mon, 24 Nov 2025 16:20:46 -0500 Subject: [PATCH 3/5] Remove copy_fonts.py --- scripts/copy_fonts.py | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 scripts/copy_fonts.py diff --git a/scripts/copy_fonts.py b/scripts/copy_fonts.py deleted file mode 100644 index a1a588078e..0000000000 --- a/scripts/copy_fonts.py +++ /dev/null @@ -1,35 +0,0 @@ -# coding: utf-8 -import glob -import os -import shutil - -dest_dir = "./jsapp/fonts/" - - -def create_folder_if_not_exists(): - if not os.path.exists(dest_dir): - try: - os.makedirs(dest_dir) - print("Destination folder has been created!") - except Exception as e: - print("Could not create fonts folder - Error: {}".format(str(e))) - - -def copy_fonts(): - - create_folder_if_not_exists() - - print("Copying fonts...") - - for file in glob.glob("./node_modules/@fontsource/roboto/files/roboto-latin-ext-*.wof*"): - print(file) - shutil.copy(file, dest_dir) - - for file in glob.glob("./node_modules/@fontsource/roboto-mono/files/roboto-mono-latin-ext-*.wof*"): - print(file) - shutil.copy(file, dest_dir) - - print("DONE") - - -copy_fonts() From 102dbb53f52c5ccb54a735798c9ac316aa99776b Mon Sep 17 00:00:00 2001 From: Phil Edwards Date: Mon, 24 Nov 2025 16:59:42 -0500 Subject: [PATCH 4/5] wip: Docker node build stage --- Dockerfile | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Dockerfile b/Dockerfile index 6d6ebbc4c3..c1031c3718 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,9 @@ # If you update this base image, make sure to update the base runners # in .github/workflows/ to the corresponding Ubuntu version + +###################### +# Python build stage # +###################### FROM ghcr.io/astral-sh/uv:python3.10-bookworm AS build-python @@ -11,7 +15,50 @@ ENV PATH="$VIRTUAL_ENV/bin:$PATH" COPY ./dependencies/pip/requirements.txt "${TMP_DIR}/pip_dependencies.txt" RUN uv pip sync "${TMP_DIR}/pip_dependencies.txt" 1>/dev/null +#################### +# Node build stage # +#################### +FROM node:20.19-bookworm-slim AS build-node +ENV KPI_SRC_DIR=/srv/src/kpi \ + TMP_DIR=/srv/tmp +WORKDIR "${KPI_SRC_DIR}" + +# Use a non-root user +RUN addgroup -S kobo && adduser -S -G kobo kobo + +# Install npm dependencies & run post-install steps +COPY --chown=kobo:kobo scripts ./scripts +COPY --chown=kobo:kobo patches ./patches +COPY --chown=kobo:kobo \ + .browserslistrc \ + package.json \ + package-lock.json \ + ./ +RUN mkdir -p "${TMP_DIR}/.npm" && \ + npm config set cache "${TMP_DIR}/.npm" --global && \ + mkdir -p "./jsapp/fonts" && \ + npm ci && \ + npm cache clean --force + +# Build the frontend +COPY --chown=kobo:kobo test ./test +COPY --chown=kobo:kobo static ./static +COPY --chown=kobo:kobo webpack ./webpack +COPY --chown=kobo:kobo jsapp ./jsapp +COPY --chown=kobo:kobo \ + .browserslistrc \ + .babelrc.json \ + .swcrc \ + package.json \ + package-lock.json \ + tsconfig.json \ + ./ +RUN SKIP_TS_CHECK=true \ + npm run build:app +###################### +# KPI dev/prod image # +###################### FROM ghcr.io/astral-sh/uv:python3.10-bookworm-slim ENV DEBIAN_FRONTEND=noninteractive From 1a50de8bde43f2b02482b42aaae86dbfb28a0cca Mon Sep 17 00:00:00 2001 From: Phil Edwards Date: Mon, 24 Nov 2025 17:01:24 -0500 Subject: [PATCH 5/5] wip note: todos for Docker node build stage --- Dockerfile | 4 ++++ docker/entrypoint.sh | 1 + 2 files changed, 5 insertions(+) diff --git a/Dockerfile b/Dockerfile index c1031c3718..6f7012f94c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -150,6 +150,8 @@ COPY --from=build-python "$VIRTUAL_ENV" "$VIRTUAL_ENV" # Install `npm` packages. # ########################### +# TODO: copy from npm build stage + WORKDIR ${KPI_SRC_DIR}/ RUN rm -rf ${KPI_NODE_PATH} && \ @@ -168,6 +170,8 @@ ENV PATH=$PATH:${KPI_NODE_PATH}/.bin # Build client code. # ###################### +# TODO: copy from npm build stage + RUN npm run build:app ########################### diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 6cf69a6fec..9e4b5fde3b 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -66,6 +66,7 @@ if [[ ! -d "${KPI_SRC_DIR}/staticfiles" ]] || ! python "${KPI_SRC_DIR}/docker/ch # Create folder to be sure following `rsync` command does not fail mkdir -p "${KPI_SRC_DIR}/staticfiles" else + # TODO - revisit this in context of separate node build stage echo "Cleaning old build…" rm -rf "${KPI_SRC_DIR}/jsapp/fonts" && \ rm -rf "${KPI_SRC_DIR}/jsapp/compiled"