Automated Resume Builds With Docker and Gitlab Devops
February 05, 2023As a certified Hackerman, I write my resume in Markdown. I also maintain an open source version of the template I use on Github.
The template is written in Markdown and I wrote a small build script that uses pandoc and wkhtmltopdf and some CSS to generate PDF and HTML versions of the markdown file.
Since we’ve already established that I’m officially a masochist, I have to mention that I use Arch btwᵀᴹ. So typically, after updating my system, and opening my text editor, it’s totally expected that I might get an error along the lines of:
lib*****.so.42: cannot open shared object file: No such file
Recently, on a rainy night, I ran my build script and got something similar to the dreaded error messages above. I spent some time searching the lovely Arch Linux [SOLVED] forums and going from one error to another. I don’t remember what the problem(s) was exactly but it was something related to a version of Python and a version of some QT5 library that I didn’t bother to solve this time.
Enter Docker
Since nowadays most problems in the world seem to be solved though some form of containerization and Kubernetes and rust, I also decided to build my resume in a Docker container.
As any good Docker user, I started with an Alpine image but then found out that wkhtmltopdf
is not available in Alpine repositories anymore. So I had to use an Ubuntu based image and installed all the necessary packages that I usually install natively on my machine. I also needed to install some Microsoft 😱 proprietary package from Ubuntu repositories for the fonts I use in the CSS which gave me some headache to install in the beginning.
In the end, I run the build script inside the container to build the resume PDF then I use docker cp
command to copy the file from the container to my host machine.
This is how the Dockerfile looks like:
FROM pandoc/core:latest-ubuntu
RUN apt update && \
apt install -y software-properties-common && \
add-apt-repository multiverse && \
apt update && \
echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections && \
apt install --reinstall -y xvfb libfontconfig wkhtmltopdf fontconfig ttf-mscorefonts-installer && \
fc-cache -f -v
ENV SRC /usr/src
WORKDIR $SRC
Add . $SRC
RUN pandoc --version
RUN ./build.sh build
And here’s the build script:
#!/bin/sh
SOURCE=resume.md
TARGET=resume
CSS=resume.css
OPEN_COMMAND=xdg-open # replace with `open` for macos
case "$1" in
build)
pandoc --pdf-engine=wkhtmltopdf -t html5 --css "$CSS" -o "$TARGET".pdf "$SOURCE"
;;
build-docker)
docker build -t resume .
container_id=$(docker run -d resume:latest)
docker cp $container_id:/usr/src/resume.pdf ./resume.pdf
;;
build-html)
pandoc --standalone --css "$CSS" --from markdown --to html -o "$TARGET".html "$SOURCE"
;;
open)
"$OPEN_COMMAND" "$TARGET".pdf &
;;
*)
echo "Usage: $0 {build|build-docker|build-html|open}"
exit 2
esac
exit 0
Now, when I want to build my resume on my machine, I simple run the build command:
./build.sh build-docker
Automated Builds
Finally, I added Gitlab CI/CD to my setup to get automated builds on git push.
Since the build script expects that the docker
command exists, I needed to use a Docker in Docker image, or dind as a service:
image: docker:latest
services:
- "docker:dind"
build:
stage: deploy
script:
- ./build.sh build-docker
artifacts:
paths:
- resume.pdf
only:
- master
With this setup, I can now simply push my changes and go to Gitlab and download the latest version of of my resume through Gitlab’s UI.
You can find the full source code of the template and the setup on Github at hackerman-resume.