2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-07-04 14:10:52 +00:00

build(docker): compile backend translations during image build (#12203)

* build(docker): compile backend trasnlations during image build

* test(docker): verify compiled backend translations exist in image

Add checks to the "Test Docker Image" step that assert the compiled
django.mo files are present for a few representative languages (de, fr,
ru, zh_Hans). This guards the newly added backend translation
compilation step in the production Dockerfile, ensuring the multilingual
artifacts are produced at the expected locale paths.

* test(docker): verify compiled frontend translations exist in image
This commit is contained in:
开源斗士
2026-06-20 20:51:38 +08:00
committed by GitHub
parent f1a1f6f18a
commit 8afc8b3d50
3 changed files with 31 additions and 0 deletions
+10
View File
@@ -84,6 +84,16 @@ jobs:
docker run --rm inventree-test test -f /home/inventree/gunicorn.conf.py
docker run --rm inventree-test test -f /home/inventree/src/backend/requirements.txt
docker run --rm inventree-test test -f /home/inventree/src/backend/InvenTree/manage.py
# Check that backend translations were compiled into the image (a few representative languages)
docker run --rm inventree-test test -f /home/inventree/src/backend/InvenTree/locale/de/LC_MESSAGES/django.mo
docker run --rm inventree-test test -f /home/inventree/src/backend/InvenTree/locale/fr/LC_MESSAGES/django.mo
docker run --rm inventree-test test -f /home/inventree/src/backend/InvenTree/locale/ru/LC_MESSAGES/django.mo
docker run --rm inventree-test test -f /home/inventree/src/backend/InvenTree/locale/zh_Hans/LC_MESSAGES/django.mo
# Check that frontend translations (lingui) were compiled into the static build output (a few representative languages)
docker run --rm inventree-test grep -q '"src/locales/de/messages.ts"' /home/inventree/src/backend/InvenTree/web/static/web/.vite/manifest.json
docker run --rm inventree-test grep -q '"src/locales/fr/messages.ts"' /home/inventree/src/backend/InvenTree/web/static/web/.vite/manifest.json
docker run --rm inventree-test grep -q '"src/locales/ru/messages.ts"' /home/inventree/src/backend/InvenTree/web/static/web/.vite/manifest.json
docker run --rm inventree-test grep -q '"src/locales/zh_Hans/messages.ts"' /home/inventree/src/backend/InvenTree/web/static/web/.vite/manifest.json
- name: Build Docker Image
# Build the development docker image (using docker-compose.yml)
run: docker compose --project-directory . -f contrib/container/dev-docker-compose.yml build --no-cache
+3
View File
@@ -145,6 +145,9 @@ ENV PATH=/root/.local/bin:$PATH
COPY --from=builder_stage ${INVENTREE_BACKEND_DIR}/InvenTree/web/static/web ${INVENTREE_BACKEND_DIR}/InvenTree/web/static/web
COPY --from=builder_stage /root/.local /root/.local
# Compile Django backend translations during image build
RUN bash -c "cd '${INVENTREE_HOME}' && invoke int.backend-compilemessages"
# Launch the production server
CMD ["sh", "-c", "exec gunicorn -c ./gunicorn.conf.py InvenTree.wsgi -b ${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT} --chdir ${INVENTREE_BACKEND_DIR}/InvenTree"]
+18
View File
@@ -906,6 +906,23 @@ def backend_trans(c, verbose: bool = False):
success('Backend translations compiled successfully')
@task(help={'verbose': 'Print verbose output'})
@state_logger('backend_compilemessages')
def backend_compilemessages(c, verbose: bool = False):
"""Compile backend Django translation files without loading InvenTree settings."""
info('Compiling backend translations...')
cmd = 'python3 -m django compilemessages'
if verbose:
cmd += ' -v 1'
else:
cmd += ' -v 0'
run(c, cmd, manage_py_dir())
success('Backend translations compiled successfully')
@task(
help={
'clean': 'Clean up old backup files',
@@ -2490,6 +2507,7 @@ internal = Collection(
clear_generated,
export_settings_definitions,
export_definitions,
backend_compilemessages,
frontend_build,
frontend_check,
frontend_compile,