From e338dd8fb3974f7ed92d9ee7ba8099e544a145d1 Mon Sep 17 00:00:00 2001 From: John Muchovej Date: Sun, 18 Aug 2024 21:34:35 -0400 Subject: [PATCH] feat(latex): revamp LaTeX devcontainer, setup docker bake Signed-off-by: John Muchovej --- .../workflows/build-latex-devcontainer.yaml | 55 ----- .github/workflows/containers-latex.yaml | 40 ++++ latex/.devcontainer.json | 99 --------- latex/Dockerfile | 160 --------------- latex/devcontainer-template.json | 19 -- templates/src/latex/Dockerfile | 193 +++++++++--------- templates/src/latex/docker-bake.hcl | 66 ++++++ 7 files changed, 204 insertions(+), 428 deletions(-) delete mode 100644 .github/workflows/build-latex-devcontainer.yaml create mode 100644 .github/workflows/containers-latex.yaml delete mode 100644 latex/.devcontainer.json delete mode 100644 latex/Dockerfile delete mode 100644 latex/devcontainer-template.json create mode 100644 templates/src/latex/docker-bake.hcl diff --git a/.github/workflows/build-latex-devcontainer.yaml b/.github/workflows/build-latex-devcontainer.yaml deleted file mode 100644 index 1a4ca23..0000000 --- a/.github/workflows/build-latex-devcontainer.yaml +++ /dev/null @@ -1,55 +0,0 @@ -name: "Build and publish LaTeX devcontainer to ghcr.io" - -on: - push: - paths: - - "templates/src/latex/Dockerfile" - - ".github/workflows/build-latex-devcontainer.yaml" - workflow_dispatch: - -jobs: - build-push-image: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - name: "Checkout repository" - uses: "actions/checkout@v3" - - - name: "Setup QEMU" - uses: "docker/setup-qemu-action@v2" - - - name: "Setup Docker `buildx`" - uses: "docker/setup-buildx-action@v2" - - - name: "Login to `ghcr.io`" - uses: "docker/login-action@v2" - with: - registry: "ghcr.io" - username: "${{ github.actor }}" - password: "${{ secrets.GITHUB_TOKEN }}" - - - name: "Login to `docker.io`" - uses: "docker/login-action@v2" - with: - registry: "docker.io" - username: "${{ secrets.DOCKERHUB_USERNAME }}" - password: "${{ secrets.DOCKERHUB_TOKEN }}" - - - name: "Extract Metadata for Docker" - id: "meta" - uses: "docker/metadata-action@v4" - with: - images: | - ghcr.io/${{ github.actor }}/latex-devcontainer - docker.io/${{ secrets.DOCKERHUB_USERNAME }}/latex-devcontainer - - - name: "Build and Push Docker image" - uses: "docker/build-push-action@v3" - with: - context: "latex" - platforms: "linux/amd64,linux/arm64" - push: true - tags: "${{ steps.meta.outputs.tags }}" - labels: "${{ steps.meta.outputs.labels }}" \ No newline at end of file diff --git a/.github/workflows/containers-latex.yaml b/.github/workflows/containers-latex.yaml new file mode 100644 index 0000000..38dcb37 --- /dev/null +++ b/.github/workflows/containers-latex.yaml @@ -0,0 +1,40 @@ +name: "Build and publish LaTeX devcontainer to ghcr.io" + +on: + push: + paths: + - "templates/src/latex/Dockerfile" + - "templates/src/latex/docker-bake.hcl" + - ".github/workflows/build-latex-devcontainer.yaml" + workflow_dispatch: + schedule: + - cron: "0 2 1 4 *" # historically, TeXLive has been published around March + +jobs: + build-push-latex: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: "Checkout repository" + uses: "actions/checkout@v4" + + - name: "Setup QEMU" + uses: "docker/setup-qemu-action@v3" + + - name: "Setup Docker `buildx`" + uses: "docker/setup-buildx-action@v3" + + - name: "Login to `ghcr.io`" + uses: "docker/login-action@v3" + with: + registry: "ghcr.io" + username: "${{ github.actor }}" + password: "${{ secrets.GITHUB_TOKEN }}" + + - id: bake + uses: docker/bake-action@v5 + with: + workdir: "./templates/src/latex" + push: true diff --git a/latex/.devcontainer.json b/latex/.devcontainer.json deleted file mode 100644 index 52f336a..0000000 --- a/latex/.devcontainer.json +++ /dev/null @@ -1,99 +0,0 @@ -{ - "image": "ghcr.io/jmuchovej/latex-devcontainer:main", - "name": "LaTeX devcontainer", - "workspaceFolder": "/workspace", - "customizations": { - "vscode": { - "extensions": [ - // LaTeX Workshop, goes without saying. - "james-yu.latex-workshop", - // Colorful comments based ensuring character - "aaron-bond.better-comments", - // vim keybindings for VSCode - "vscodevim.vim", - // Useful extensions for dev experience - "shardulm94.trailing-spaces", // Highlights straight whitespace - "stkb.rewrap" // Enables word-wrap on comments - ], - "settings": { - "files.eol": "\n", - "editor.formatOnSave": true, - "files.associations": { - "*.tex": "latex" - }, - "latex-workshop.latex.autoClean.run": "onBuilt", - "latex-workshop.latex.clean.subfolder.enabled": true, - "latex-workshop.latex.recipes": [ - { - "name": "${{ templateOption.latexEngine }} -> biber -> ${{ templateOption.latexEngine }}* 2", - "tools": [ - "${{ templateOption.latexEngine }}", - "biber", - "${{ templateOption.latexEngine }}", - "${{ templateOption.latexEngine }}", - ] - }, - { - "name": "latexmk", - "tools": ["latexmk"] - } - ], - "latex-workshop.latex.tools": [ - { - "name": "${{ templateOption.latexEngine }}", - "command": "latexmk", - "args": [ - "--shell-escape", - "-synctex=1", - "-interaction=nonstopmode", - "-file-line-error", - "-${{ templateOption.latexEngine }}", - "%DOC%" - ] - }, - { - "name": "biber", - "command": "biber", - "args": [ "%DOCFILE%" ] - }, - { - "name": "latexmk", - "command": "latexmk", - "args": [ - "-synctex=1", - "-interaction=nonstopmode", - "-file-line-error", - "-pdf", - "-outdir=%OUTDIR%", - "%DOC%" - ] - } - ], - // region chktex - "latex-workshop.linting.chktex.enabled": true, - "latex-workshop.linting.chktex.exec.path": "/usr/local/bin/chktex", - // endregion - // region latexindent - "latex-workshop.latexindent.enabled": true, - //* This needs to be left as the command because the installation - //* location varies across architecture builds - "latex-workshop.latexindent.exec.path": "latexindent", - "latex-workshop.latexindent.args": [ - "-c", "%DIR%/", "%TMPFILE%", "-y=defaultIndent: '%INDENT%'" - ], - // endregion - // region syntex - "latex-workshop.synctex.afterBuild.enabled": true - // endregion - } - } - }, - "features": { - "ghcr.io/devcontainers/features/common-utils": { - "installZsh": true, - "username": "vscode", - "upgradePackages": true - } - }, - "postStartCommand": "tlmgr install ${{ templateOption.latexEngine }}" -} \ No newline at end of file diff --git a/latex/Dockerfile b/latex/Dockerfile deleted file mode 100644 index 9836dbb..0000000 --- a/latex/Dockerfile +++ /dev/null @@ -1,160 +0,0 @@ -# syntax=docker/dockerfile:1.5 -#! Dockerfile syntax can be retrieved from https://hub.docker.com/r/docker/dockerfile - -ARG VARIANT="jammy" -FROM --platform=${TARGETARCH} docker.io/library/buildpack-deps:${VARIANT}-scm as chktex-builder -ARG TARGETPLATFORM -ARG TARGETOS -ARG TARGETARCH -ARG CHKTEX_VERSION=1.7.8 -ARG CHKTEX_MIRROR="http://download.savannah.gnu.org/releases/chktex" - -WORKDIR /tmp/chktex-builder -ENV DEBIANT_FRONTEND noninteractive - -RUN <<-EOF -apt update -y -apt install -y --no-install-recommends \ - g++ \ - make -EOF - -RUN curl -fL -o- ${CHKTEX_MIRROR}/chktex-${CHKTEX_VERSION}.tar.gz | tar xz --strip-components 1 - -RUN <" -LABEL org.opencontainers.image.url \ - "https://github.com/jmuchovej/containers/" -LABEL org.opencontainers.image.documentation \ - "https://github.com/jmuchovej/containers/blob/main/latex/README.md" -LABEL org.opencontainers.image.source \ - "https://github.com/jmuchovej/containers/tree/main/latex" - -ARG SCHEME="scheme-basic" -ARG DOCFILES=0 -ARG SRCFILES=0 -ARG TEXLIVE_VERSION=2023 -ARG TEXLIVE_MIRROR="https://mirror.ctan.org/systems/texlive/tlnet" -ARG DEBIAN_FRONTEND="noninteractive" - -#! Set environment variables -ENV LANG="en_US.UTF-8" -ENV LANGUAGE="en_US.UTF-8" -ENV TERM="xterm" -ENV TEXDIR="/usr/local/texlive" -ENV TEXUSERDIR="/texlive-user" - -#* Running the following _should_ work, in principal, but Docker doesn't currently -#* support this form of execution. -# ENV PATH ${TEXDIR}/bin/$(arch)-linux:${PATH} -#! c.f. https://github.com/docker/docker/issues/29110 -ENV PATH ${TEXDIR}/bin/aarch64-linux:${TEXDIR}/bin/x86_64-linux:${PATH} - -#! Install base packages that users might need later on -RUN <", - "licenseURL": "https://github.com/jmuchovej/containers/tree/main/LICENSE", - "platforms": ["Any"], - "keywords": ["latex", "xelatex", "lualatex", "pdftex"], - "options": { - "latexEngine": { - "type": "string", - "description": "Which LaTeX Engine to use", - "enum": ["xetex", "luatex", "pdftex"], - "default": "xetex" - } - } -} \ No newline at end of file diff --git a/templates/src/latex/Dockerfile b/templates/src/latex/Dockerfile index 8c016f8..f04eb83 100644 --- a/templates/src/latex/Dockerfile +++ b/templates/src/latex/Dockerfile @@ -1,93 +1,64 @@ # syntax=docker/dockerfile:1.5 #! Dockerfile syntax can be retrieved from https://hub.docker.com/r/docker/dockerfile +#* Use a variant of `buildpack-deps` which includes commont tools, libraries, and +#* programming languages like `git`, `gcc`, `openssl`, `python`, `node`, and `julia`. +ARG VARIANT="noble" +ARG CHKTEX_VERSION="1.7.9" +ARG TEXLIVE_VERSION="2024" + +ARG TEXDIR="/usr/local/texlive" +ARG TEXUSERDIR="/texlive-user" -FROM --platform=${TARGETARCH} docker.io/library/buildpack-deps:kinetic-scm as chktex-builder -ARG VARIANT="kinetic" -ARG TARGETPLATFORM -ARG TARGETOS -ARG TARGETARCH -ARG CHKTEX_VERSION=1.7.6 ARG CHKTEX_MIRROR="http://download.savannah.gnu.org/releases/chktex" +ARG TEXLIVE_MIRROR="https://mirror.ctan.org/systems/texlive/tlnet" -WORKDIR /tmp/chktex-builder -ENV DEBIANT_FRONTEND noninteractive +ARG SCHEME="scheme-basic" +ARG DOCFILES=0 +ARG SRCFILES=0 -RUN <<-EOF -apt update -y -apt install -y --no-install-recommends \ - g++ \ - make -EOF +#region chktex Builder Stage ############################################################ +FROM mcr.microsoft.com/devcontainers/base:${VARIANT} as chktex-builder +ARG CHKTEX_MIRROR +ARG CHKTEX_VERSION +ENV DEBIAN_FRONTEND="noninteractive" -RUN curl -fL -o- ${CHKTEX_MIRROR}/chktex-${CHKTEX_VERSION}.tar.gz | tar xz --strip-components 1 +WORKDIR /tmp/chktex-builder -RUN <" -LABEL org.opencontainers.image.url \ - "https://github.com/jmuchovej/containers/" -LABEL org.opencontainers.image.documentation \ - "https://github.com/jmuchovej/containers/blob/main/latex/README.md" -LABEL org.opencontainers.image.source \ - "https://github.com/jmuchovej/containers/tree/main/latex" +RUN ./configure +RUN make +#endregion ############################################################################## -ARG SCHEME="scheme-basic" -ARG DOCFILES=0 -ARG SRCFILES=0 -ARG TEXLIVE_VERSION=2022 -ARG TEXLIVE_MIRROR="https://mirror.ctan.org/systems/texlive/tlnet" -ARG DEBIAN_FRONTEND="noninteractive" +#region TeXLive Builder Stage ########################################################### +FROM mcr.microsoft.com/devcontainers/base:${VARIANT} as texlive-builder +ARG TEXLIVE_VERSION +ARG TEXLIVE_MIRROR +ARG TEXDIR +ARG TEXUSERDIR +ARG SCHEME +ARG DOCFILES +ARG SRCFILES #! Set environment variables +ENV DEBIAN_FRONTEND="noninteractive" ENV LANG="en_US.UTF-8" ENV LANGUAGE="en_US.UTF-8" ENV TERM="xterm" -ENV TEXDIR="/usr/local/texlive" -ENV TEXUSERDIR="/texlive-user" #* Running the following _should_ work, in principal, but Docker doesn't currently #* support this form of execution. # ENV PATH ${TEXDIR}/bin/$(arch)-linux:${PATH} #! c.f. https://github.com/docker/docker/issues/29110 -ENV PATH ${TEXDIR}/bin/aarch64-linux:${TEXDIR}/bin/x86_64-linux:${PATH} - -#! Install base packages that users might need later on -RUN <" +LABEL org.opencontainers.image.url "https://github.com/jmuchovej/devcontainers" +LABEL org.opencontainers.image.documentation \ + "https://github.com/jmuchovej/devcontainers/blob/main/src/templates/latex/README.md" +LABEL org.opencontainers.image.source \ + "https://github.com/jmuchovej/containers/tree/main/src/templates/latex" + +#! Set environment variables +ENV LANG="en_US.UTF-8" +ENV LANGUAGE="en_US.UTF-8" +ENV TERM="xterm" + +#* Running the following _should_ work, in principal, but Docker doesn't currently +#* support this form of execution. +# ENV PATH ${TEXDIR}/bin/$(arch)-linux:${PATH} +#! c.f. https://github.com/docker/docker/issues/29110 +ENV PATH ${TEXDIR}/bin/aarch64-linux:${TEXDIR}/bin/x86_64-linux:${PATH} + +COPY --from=chktex-builder /tmp/chktex-builder/chktex /usr/local/bin/chktex +COPY --from=texlive-builder "${TEXDIR}" "${TEXDIR}" +COPY --from=texlive-builder "${TEXUSERDIR}" "${TEXUSERDIR}" + +#! Install base packages that users might need later on RUN <