Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: LaTeX processing in external Docker container #446

Closed

Conversation

b0ink
Copy link

@b0ink b0ink commented Sep 10, 2024

Depends on doubtfire-lms/doubtfire-deploy#29

Description

This update moves LaTeX processing into a dedicated TeX Live container. Instead of running lualatex from the latex_config, the latex_run.sh script is executed after being copied into the working directory (along with other input files such as input.tex and jupynotex.py).

latex_run.sh then runs docker exec ... into the TeX Live container and executes latex_build.sh, which is in charge of running the lualatex commands.

latex_run.sh relies on two environment variables to be set:

LATEX_CONTAINER_NAME=formatif-texlive-container # Name of the TeX Live container
LATEX_BUILD_PATH=/texlive/shell/latex_build.sh # Path on the TeX Live container

The render_to_string() method that renders the PDFs is now wrapped in a generate_pdf() method defined in latex_helper.rb, ensuring the environment variables are set before executing latex_run.sh via render_to_string.

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Use the modified docker-compose from Refactor: External TeX Live docker container doubtfire-deploy#29
  • If you encounter issues with the setup, remove any previous Docker devcontainer builds and volumes.
  • Run rake test in doubtfire-api to validate PDF generation.
  • Optionally, run rake db:simulate_signoff which will create several tasks and render them with lualatex.
  • You can also manually create a portfolio when logged in as a student, upload different test files, click "Create my portfolio", then run doubtfire-api/lib/shell/generate_pdfs.sh

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation if appropriate
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have created or extended unit tests to address my new additions
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@macite macite changed the base branch from 8.0.x to new/scorm September 10, 2024 10:23
@macite macite changed the base branch from new/scorm to 8.0.x September 10, 2024 10:34
@macite macite changed the base branch from 8.0.x to new/scorm September 10, 2024 10:34
@macite macite changed the base branch from new/scorm to 8.0.x September 10, 2024 10:40
@macite macite changed the base branch from 8.0.x to new/scorm September 10, 2024 10:40
@macite
Copy link
Member

macite commented Sep 12, 2024

Hi @b0ink, it looks like the merge commit fb0bc26 has not merged the change log well. Can you recreate the PR and merge into the new/scorm branch? You could just revert the last two merge commits, and then force push to your branch. That may update this PR...

@macite
Copy link
Member

macite commented Sep 12, 2024

We also probably need to make sure to update the GitHub actions so that it tests using the separate containers

@b0ink b0ink force-pushed the refactor/latex-docker-downsize-api branch from eddd49b to 2e0c0a5 Compare September 17, 2024 00:58
@b0ink b0ink marked this pull request as ready for review September 21, 2024 17:18
Copy link
Member

@macite macite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty close now - just a few minor things to look at.

docker-compose.yml Outdated Show resolved Hide resolved
app/models/task.rb Outdated Show resolved Hide resolved
app/helpers/latex_helper.rb Outdated Show resolved Hide resolved
app/helpers/latex_helper.rb Outdated Show resolved Hide resolved
texlive.Dockerfile Show resolved Hide resolved
texlive.Dockerfile Outdated Show resolved Hide resolved
# This script is copied into tmp/rails-latex/$WORK_DIR/ and executed by rails-latex

WORK_DIR=$(basename "$PWD")
docker exec -t $LATEX_CONTAINER_NAME $LATEX_BUILD_PATH $WORK_DIR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check that these environment variables exist - either here or in the application.rb file. Then report an error so that the config can be checked.
$LATEX_CONTAINER_NAME
$LATEX_BUILD_PATH

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we default LATEX_BUILD_PATH to /texlive/shell/latex_build.sh if it is not set?

@macite macite deleted the branch doubtfire-lms:new/scorm October 25, 2024 10:00
@macite macite closed this Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants