build(docker): compile backend trasnlations during image build

This commit is contained in:
geekcj12 2026-06-18 14:22:01 +08:00 committed by 开源斗士
parent 6657000d89
commit 99755ac611
2 changed files with 21 additions and 0 deletions

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"]

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,