Skip to content

Commit f0b98a6

Browse files
committed
Merge branch 'b0ink-refactor/latex-docker-downsize-api' into chore/update-gems
2 parents 77fb1fc + 5ece8cd commit f0b98a6

File tree

15 files changed

+144
-87
lines changed

15 files changed

+144
-87
lines changed

.ci-setup/texlive-install.sh

Lines changed: 0 additions & 57 deletions
This file was deleted.

.ci-setup/texlive.profile

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/push.yml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ env:
2727
DF_ENCRYPTION_DETERMINISTIC_KEY: "anlmuJ6cB3bN3biXRbYvmPsC5ALPFqGG"
2828
DF_ENCRYPTION_KEY_DERIVATION_SALT: "hzPR8D4qpOnAg7VeAhkhWw6JmmzKJB10"
2929
DF_REDIS_SIDEKIQ_URL: "redis://redis:6379/0"
30+
LATEX_CONTAINER_NAME: doubtfire-texlive
31+
LATEX_BUILD_PATH: /texlive/shell/latex_build.sh
3032

3133
jobs:
3234
unit-tests:
@@ -49,21 +51,53 @@ jobs:
4951
uses: actions/checkout@v4
5052
- name: Set up docker buildx
5153
uses: docker/setup-buildx-action@v3
54+
- name: Build TexLive image
55+
uses: docker/build-push-action@v5
56+
with:
57+
context: .
58+
file: texlive.Dockerfile
59+
push: false
60+
load: true
61+
tags: doubtfire-texlive-development:local
62+
cache-from: type=gha,scope=texlive
63+
cache-to: type=gha,mode=max,scope=texlive
5264
- name: Build base doubtfire-api development image
5365
uses: docker/build-push-action@v5
5466
with:
5567
context: .
5668
push: false
5769
load: true
5870
tags: doubtfire-api-development:local
59-
cache-from: type=gha
60-
cache-to: type=gha,mode=max
71+
cache-from: type=gha,scope=doubtfire-api
72+
cache-to: type=gha,mode=max,scope=doubtfire-api
73+
- name: Start TexLive service
74+
uses: addnab/docker-run-action@v3
75+
with:
76+
image: doubtfire-texlive-development:local
77+
options: >
78+
--name ${{ env.LATEX_CONTAINER_NAME }}
79+
-v ${{ github.workspace }}/student-work:/student-work
80+
-v ${{ github.workspace }}/public/assets/images:/doubtfire/public/assets/images
81+
-v ${{ github.workspace }}/test_files:/doubtfire/test_files
82+
-v ${{ github.workspace }}/tmp/rails-latex:/workdir/texlive-latex
83+
--detach
84+
run: sleep infinity
85+
- name: Test TexLive container
86+
uses: addnab/docker-run-action@v3
87+
with:
88+
image: doubtfire-api-development:local
89+
options: >
90+
-v ${{ github.workspace }}:/doubtfire
91+
-v /var/run/docker.sock:/var/run/docker.sock
92+
run: docker exec -t ${{ env.LATEX_CONTAINER_NAME }} lualatex -v
6193
- name: Populate database
6294
uses: addnab/docker-run-action@v3
6395
with:
6496
image: doubtfire-api-development:local
6597
options: >
6698
-v ${{ github.workspace }}:/doubtfire
99+
-v ${{ github.workspace }}/student-work:/student-work
100+
-v /var/run/docker.sock:/var/run/docker.sock
67101
-e RAILS_ENV
68102
-e DF_STUDENT_WORK_DIR
69103
-e DF_INSTITUTION_HOST
@@ -81,13 +115,17 @@ jobs:
81115
-e DF_ENCRYPTION_DETERMINISTIC_KEY
82116
-e DF_ENCRYPTION_KEY_DERIVATION_SALT
83117
-e DF_REDIS_SIDEKIQ_URL
118+
-e LATEX_CONTAINER_NAME
119+
-e LATEX_BUILD_PATH
84120
run: bundle exec rake db:populate
85121
- name: Run unit tests
86122
uses: addnab/docker-run-action@v3
87123
with:
88124
image: doubtfire-api-development:local
89125
options: >
90126
-v ${{ github.workspace }}:/doubtfire
127+
-v ${{ github.workspace }}/student-work:/student-work
128+
-v /var/run/docker.sock:/var/run/docker.sock
91129
-e RAILS_ENV
92130
-e DF_STUDENT_WORK_DIR
93131
-e DF_INSTITUTION_HOST
@@ -105,4 +143,8 @@ jobs:
105143
-e DF_ENCRYPTION_DETERMINISTIC_KEY
106144
-e DF_ENCRYPTION_KEY_DERIVATION_SALT
107145
-e DF_REDIS_SIDEKIQ_URL
146+
-e LATEX_CONTAINER_NAME
147+
-e LATEX_BUILD_PATH
108148
run: TERM=xterm bundle exec rails test
149+
- name: Stop TexLive service
150+
run: docker rm -f ${{ env.LATEX_CONTAINER_NAME }}

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ RUN apt-get update \
2626
wget \
2727
redis \
2828
libc6-dev \
29-
librsvg2-bin \
3029
docker-ce \
3130
docker-ce-cli \
3231
containerd.io \
@@ -36,8 +35,9 @@ RUN apt-get update \
3635
WORKDIR /doubtfire
3736

3837
COPY ./.ci-setup/ /doubtfire/.ci-setup/
39-
RUN ./.ci-setup/texlive-install.sh
40-
ENV PATH=/tmp/texlive/bin/x86_64-linux:/tmp/texlive/bin/aarch64-linux:$PATH
38+
39+
# RUN ./.ci-setup/texlive-install.sh
40+
# ENV PATH=/tmp/texlive/bin/x86_64-linux:/tmp/texlive/bin/aarch64-linux:$PATH
4141

4242
RUN gem install bundler -v '2.6.6'
4343

app/helpers/latex_helper.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module LatexHelper
2+
def generate_pdf(template:)
3+
raise 'LATEX_CONTAINER_NAME is not set' if ENV['LATEX_CONTAINER_NAME'].nil?
4+
raise 'LATEX_BUILD_PATH is not set' if ENV['LATEX_BUILD_PATH'].nil?
5+
render_to_string(template: template, layout: true)
6+
end
7+
end

app/models/pdf_generation/project_compile_portfolio_module.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def compress_portfolio
3535

3636
# This class scaffolds the creation of the portfolio - mapping the required data into the erb template
3737
class ProjectAppController < ApplicationController
38+
include LatexHelper
39+
3840
attr_accessor :student,
3941
:project,
4042
:base_path,
@@ -66,7 +68,8 @@ def init(project, is_retry)
6668
end
6769

6870
def make_pdf
69-
render_to_string(template: '/portfolio/portfolio_pdf', layout: true)
71+
logger.debug 'Running make_pdf: (portfolio)'
72+
generate_pdf(template: '/portfolio/portfolio_pdf')
7073
end
7174
end
7275

app/models/task.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,8 @@ def in_process_files_for_task(is_retry)
10751075
end
10761076

10771077
class TaskAppController < ApplicationController
1078+
include LatexHelper
1079+
10781080
attr_accessor :task
10791081
attr_accessor :files
10801082
attr_accessor :base_path
@@ -1099,8 +1101,8 @@ def make_pdf
10991101
FileHelper.qpdf(f[:path])
11001102
end
11011103
end
1102-
logger.debug "Preprocessing complete, rendering file."
1103-
render_to_string(template: '/task/task_pdf', layout: true)
1104+
logger.debug 'Preprocessing complete, rendering file.'
1105+
generate_pdf(template: '/task/task_pdf')
11041106
end
11051107
end
11061108

app/views/layouts/application.pdf.erbtex

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
<% @latex_config={ :recipe => [ {:command => "lualatex",:runs => 2} ], :supporting => Rails.root.join('app', 'views', 'layouts', 'jupynotex.py') } %>
1+
<%
2+
@latex_config = {
3+
:supporting => [
4+
Rails.root.join('app', 'views', 'layouts', 'jupynotex.py'),
5+
Rails.root.join('lib', 'shell', 'latex_run.sh')
6+
],
7+
:recipe => [
8+
{ :command => './latex_run.sh', :runs => 1 }
9+
],
10+
:preservework => false,
11+
:workdir => -> { "#{Process.pid}-#{Thread.current.object_id}-#{Time.now.to_i}" }
12+
}
13+
%>
14+
215
\DocumentMetadata{uncompress}
316
\documentclass[11pt,a4paper]{article}
417
\usepackage[T1]{fontenc}

deployAppSvr.Dockerfile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,11 @@ RUN apt-get update \
3232
docker-ce \
3333
docker-ce-cli \
3434
containerd.io \
35-
librsvg2-bin \
3635
&& apt-get clean
3736

3837
# Setup the folder where we will deploy the code
3938
WORKDIR /doubtfire
4039

41-
# Install LaTex
42-
COPY ./.ci-setup /doubtfire/.ci-setup
43-
RUN /doubtfire/.ci-setup/texlive-install.sh
44-
4540
# Install bundler
4641
RUN gem install bundler -v '2.6.6'
4742
RUN bundle config set --global without development test staging
@@ -50,9 +45,6 @@ RUN bundle config set --global without development test staging
5045
COPY ./Gemfile ./Gemfile.lock /doubtfire/
5146
RUN bundle install
5247

53-
# Setup path
54-
ENV PATH /tmp/texlive/bin/x86_64-linux:/tmp/texlive/bin/aarch64-linux:$PATH
55-
5648
# Copy doubtfire-api source
5749
COPY . /doubtfire/
5850

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ services:
99
- ./:/doubtfire
1010
- ../data/tmp:/doubtfire/tmp
1111
- ../data/student-work:/student-work
12+
- /var/run/docker.sock:/var/run/docker.sock
1213
depends_on:
1314
- dev-db
1415
environment:
@@ -61,6 +62,10 @@ services:
6162
# RABBITMQ_USERNAME: secure_credentials
6263
# RABBITMQ_PASSWORD: secure_credentials
6364

65+
# Latex details
66+
LATEX_CONTAINER_NAME: doubtfire-texlive
67+
LATEX_BUILD_PATH: /texlive/shell/latex_build.sh
68+
6469
dev-db:
6570
container_name: doubtfire-dev-db
6671
image: mariadb
@@ -71,3 +76,17 @@ services:
7176
MYSQL_PASSWORD: pwd
7277
volumes:
7378
- ../data/database:/var/lib/mysql
79+
80+
texlive:
81+
container_name: doubtfire-texlive
82+
build:
83+
context: .
84+
dockerfile: texlive.Dockerfile
85+
volumes:
86+
- ../data/student-work:/student-work
87+
- ./public/assets/images:/doubtfire/public/assets/images
88+
- ./test_files:/doubtfire/test_files
89+
- ./tmp/rails-latex:/workdir/texlive-latex
90+
depends_on:
91+
- df-api
92+
command: sleep infinity

0 commit comments

Comments
 (0)