Today I decided to update my resume. And by update, I mean make easy to update at any point in the future in a controlled, over-engineered, repeatable way. I’ve decided that I’d like to be able to modify the LaTex source, commit and push to GitLab, kick off a build on a GitLab runner, use a Docker image to manage dependencies, then store the binary (PDF) output alongside the repo.
Luckily, I already had a LaTeX version of my resume from a couple of months ago in GitHub. Step one is moving to GitLab. Easy as pulling, updating my SSH key, updating the remote, then pushing.
Next step is adding a Dockerfile
. I forked this LaTeX base for my resume repository a couple months ago, so I can steal and adapt the Dockerfile from that same repository.
FROM ubuntu:xenial
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -q && apt-get install -qy \
--no-install-recommends \
curl jq \
texlive-full \
python-pygments gnuplot \
make git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /data
VOLUME ["/data"]
Just a few changes to this so that I’m sure that the Ubuntu image doesn’t change from build to build,
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND noninteractive
...
In an attempt to update the dependencies based on this StackOverflow post by someone who is much better versed in the LaTeX-Ubuntu landscape than I am,
# from https://tex.stackexchange.com/a/132305
RUN apt-get --no-install-recommends install \
texlive-{base,bibtex-extra,extra-utils,generic-recommended,fonts-recommended,font-utils,latex-base,latex-recommended,latex-extra,math-extra,pictures,pstricks,science} \
perl-tk purifyeps chktex latexmk dvipng xindy dvidvi fragmaster lacheck latexdiff libfile-which-perl dot2tex tipa latex-xcolor latex-beamer prosper pgf
I found that simpler is generally better,
RUN apt-get update -qy
RUN apt-get --no-install-recommends install -qy \
texlive \
texlive-latex-extra
And finally, adding multi-stage builds made this much quicker to test changes to the LaTeX document,
FROM ubuntu:20.04 AS texlive_base
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -qy
RUN apt-get --no-install-recommends install -qy \
texlive \
texlive-latex-extra
FROM texlive_base
WORKDIR /data
VOLUME [ "/data" ]
After testing the build on this Ubuntu image, it’s time to set up CI/CD on a GitLab Runner.
# use `dind` or docker-in-docker for building the image
default:
image: docker:19.03.12
services:
- docker:19.03.12-dind
# use a single stage since I don't want to bounce the image off a registry
stages:
- build
# set up some variables for dating the pdf and exposing the working dir as a volume
before_script:
- export CI_JOB_TIMESTAMP=$(date -I)
- export CI_BUILD_WORKDIR=$(pwd)
build-job:
stage: build
# copy in some commands from the makefile since I couldn't figure out how
# to get a docker image with make installed :) maybe next time.
script:
- echo "Building Docker container for rendering"
- docker build -t latex .
- echo "Successfully built container"
- echo "Rendering PDF in container"
- docker run --rm -i -v $CI_BUILD_WORKDIR:/data latex pdflatex --jobname=resume-$CI_JOB_TIMESTAMP resume.tex
- echo "Successfully rendered PDF"
# attach the pdf to the job and pipeline
artifacts:
paths:
- ./*.pdf
And boom, now I can just change my *.tex
files, commit and push, then let GitLab make and host the PDF. All while having a history of what my resume looks like!