diff --git a/Dockerfile b/Dockerfile index f56568c2..91e9fc92 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ FROM base AS ci-cd HEALTHCHECK CMD curl --fail http://localhost:3000 || exit 1 ENTRYPOINT ["mdbook"] -# Release image ---- +# Release image FROM base AS release RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -31,11 +31,47 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ fonts-noto \ fonts-noto-color-emoji \ librsvg2-bin \ + npm \ + libnss3 \ + libnspr4 \ + libdbus-1-3 \ + libatk1.0-0 \ + libatk-bridge2.0-0 \ + libcups2 \ + libdrm2 \ + libxkbcommon0 \ + libxcomposite1 \ + libxdamage1 \ + libxfixes3 \ + libxrandr2 \ + libgbm1 \ + libasound2 \ + libxshmfence1 \ && rm -rf /var/lib/apt/lists/* \ && fc-cache -fv +# Set a shared cache directory for Puppeteer's browser download +ENV PUPPETEER_CACHE_DIR /usr/local/share/puppeteer_cache + +RUN npm install --global mermaid-filter RUN cargo install mdbook-pandoc +COPY puppeteer-config.json /etc/puppeteer-config.json + +# Define the path to the mmdc executable +ARG MMD_PATH="/usr/local/lib/node_modules/mermaid-filter/node_modules/.bin" + +# Wrap the real mmdc executable to inject the config file option +RUN mv "${MMD_PATH}/mmdc" "${MMD_PATH}/mmdc-original" && \ + echo "#!/bin/sh" > "${MMD_PATH}/mmdc" && \ + echo "exec \"${MMD_PATH}/mmdc-original\" --puppeteerConfigFile /etc/puppeteer-config.json \"\$@\"" >> "${MMD_PATH}/mmdc" && \ + chmod +x "${MMD_PATH}/mmdc" + +RUN useradd --create-home --shell /bin/bash appuser +RUN chown -R appuser:appuser /book +RUN chmod 644 /etc/puppeteer-config.json +USER appuser + HEALTHCHECK CMD curl --fail http://localhost:3000 || exit 1 ENTRYPOINT ["mdbook"] \ No newline at end of file diff --git a/book.toml b/book.toml index 0fbb7361..9854da32 100644 --- a/book.toml +++ b/book.toml @@ -32,6 +32,7 @@ optional = true [output.pandoc.profile.pdf] output-file = "algorand-specs.pdf" pdf-engine = "lualatex" +filters = ["mermaid-filter"] [output.pandoc.profile.pdf.variables] mainfont = "Noto Serif" diff --git a/docker-compose.yaml b/docker-compose.yaml index ce22b23b..eae086ad 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -17,6 +17,7 @@ services: build: context: . target: release # build the release stage + platform: linux/amd64 ports: - 3000:3000 - 3001:3001 diff --git a/puppeteer-config.json b/puppeteer-config.json new file mode 100644 index 00000000..411c0e79 --- /dev/null +++ b/puppeteer-config.json @@ -0,0 +1,3 @@ +{ + "args": ["--no-sandbox", "--disable-setuid-sandbox"] +} \ No newline at end of file