SECTION 04 · 30 MIN READ & EXPLORE
Generate a CV as a build artifact
Turn structured YAML and a Jinja template into a reproducible document build.
Automate the CV
Generate two player CVs from one template, then inspect the pipeline artifact flow.
Your mission
- Generate two player CVs from one template, then inspect the pipeline artifact flow.
Download and extract the archive. Work inside 03-demo-auto-cv; upload its contents to the root of a GitLab project when a pipeline is involved.
Demo: auto CV
# Using uv to run the script
uv run --with-requirements requirements.txt main.py -t template.tex.j2 -d ziyech.yaml -o out
# Using docker to run the script
docker build -t auto-cv:v1 .
docker run -it -v $PWD:/cv auto-cv:v1 -t /cv/template.tex.j2 -d /cv/hakimi.yaml -o /cv/out
docker run -it -v $PWD:/cv auto-cv:v1 -t /cv/template.tex.j2 -d /cv/ziyech.yaml -o /cv/out
# Generating the CV
docker run -v $PWD:/cv -it --rm dxjoke/tectonic-docker:0.14.1-alpine-biber tectonic /cv/out/resume.texHow to know it worked
- Changing YAML changes the generated document without editing the template.
- You can explain how the TeX artifact reaches the PDF job.
Explore the files
main.py
import yaml
import argparse
import os
from jinja2 import Environment, FileSystemLoader
def render_cv(template_path, data_path, output_dir):
# 1. Load the YAML data
with open(data_path, 'r') as f:
data = yaml.safe_load(f)
def escape_latex_special_chars(text):
if not isinstance(text, str):
return text
special_chars = {
'&': r'\&',
'%': r'\%',
'$': r'\$',
'#': r'\#',
'_': r'\_',
'{': r'\{',
'}': r'\}',
'~': r'\textasciitilde{}',
'^': r'\textasciicircum{}',
'\\': r'\textbackslash{}',
}
for char, replacement in special_chars.items():
text = text.replace(char, replacement)
return text
def escape_data(data):
if isinstance(data, dict):
return {k: escape_data(v) for k, v in data.items()}
elif isinstance(data, list):
return [escape_data(v) for v in data]
elif isinstance(data, str):
return escape_latex_special_chars(data)
else:
return data
data = escape_data(data)
# 2. Setup Jinja2 Environment
# We get the directory of the template file to set up the loader
template_dir = os.path.dirname(os.path.abspath(template_path))
template_file = os.path.basename(template_path)
env = Environment(loader=FileSystemLoader(template_dir))
template = env.get_template(template_file)
# 3. Render the content
rendered_tex = template.render(data)
# 4. Write output
os.makedirs(output_dir, exist_ok=True)
output_path = os.path.join(output_dir, "resume.tex")
with open(output_path, 'w') as f:
f.write(rendered_tex)
print(f"✅ Success! Generated Latex file at: {output_path}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate a Latex CV from YAML")
parser.add_argument("--template", "-t", required=True, help="Path to jinja2 template")
parser.add_argument("--data", "-d", required=True, help="Path to yaml data file")
parser.add_argument("--out", "-o", required=True, help="Path to write result")
args = parser.parse_args()
render_cv(args.template, args.data, args.out)hakimi.yaml
personal:
name: "Achraf Hakimi"
title: "High-Availability Wing-Back and Systems Architect"
email: "a.hakimi@psg.fr"
phone: "+33 6 12 34 56 78"
github: "github.com/hakimi-turbo"
summary: "World-class right-back specializing in rapid deployment (sprints), defensive security (tackles), and high-availability assists. Proven track record in top-tier European leagues and international tournaments (CAN, World Cup)."
experience:
- role: "Senior Wing-Back"
company: "Paris Saint-Germain (PSG)"
location: "Paris, FR"
dates: "2021 -- Present"
details:
- "Architected right-flank attacks resulting in 15+ assists per season."
- "Maintained 99.9% uptime during Ligue 1 matches."
- "Collaborated with Mbappe-Microservices for rapid counter-attacks."
- role: "Defensive Engineer (Loan)"
company: "Inter Milan"
location: "Milan, IT"
dates: "2020 -- 2021"
details:
- "Deployed the 'Scudetto' release, winning the Serie A title."
- "Optimized defensive transitions under Antonio Conte's 3-5-2 framework."
- role: "Full-Stack Defender"
company: "Borussia Dortmund"
location: "Dortmund, DE"
dates: "2018 -- 2020"
details:
- "Developed speed protocols reaching 36.48 km/h (top speed record)."
- "Implemented cross-functional overlaps in the Bundesliga."
education:
- degree: "PhD in Pace and Precision"
institution: "Real Madrid Academy (La Fábrica)"
dates: "2006 -- 2017"
skills:
languages: "Arabic, Spanish, French, English, German"
tools: "Nike Mercurial, GPS Tracker, VAR Analysis"
infrastructure: "Right Wing, Right Midfield, Left Back (Legacy Support)"template.tex.j2
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry}
\usepackage{titlesec}
\usepackage{enumitem}
% Disable page numbers
\pagenumbering{gobble}
% Custom Section Format
\titleformat{\section}{\Large\bfseries\uppercase}{}{0em}{}[\titlerule]
\begin{document}
% --- HEADER ---
\begin{center}
{\Huge \textbf{ {{ personal.name }} }} \\ \vspace{5pt}
{{ personal.title }} \\ \vspace{5pt}
{{ personal.email }} | {{ personal.phone }} | {{ personal.github }}
\end{center}
% --- SUMMARY ---
\section{Professional Summary}
{{ personal.summary }}
% --- EXPERIENCE ---
\section{Experience}
{% for job in experience %}
\noindent \textbf{ {{ job.role }} } \hfill {{ job.dates }} \\
\textit{ {{ job.company }} } -- {{ job.location }}
\begin{itemize}[noitemsep]
{% for detail in job.details %}
\item {{ detail }}
{% endfor %}
\end{itemize}
\vspace{10pt}
{% endfor %}
% --- EDUCATION ---
\section{Education}
{% for edu in education %}
\noindent \textbf{ {{ edu.degree }} } \hfill {{ edu.dates }} \\
{{ edu.institution }} \\
{% endfor %}
% --- SKILLS ---
\section{Technical Skills}
\begin{itemize}[noitemsep]
\item \textbf{Languages:} {{ skills.languages }}
\item \textbf{DevOps Tools:} {{ skills.tools }}
\item \textbf{Infrastructure:} {{ skills.infrastructure }}
\end{itemize}
\end{document}Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
ENTRYPOINT ["python", "main.py"].gitlab-ci.yml
stages:
- build
- deploy
variables:
PROFILE_NAME: "hakimi"
build-cv:
stage: build
image: python:3.11-slim
script:
- cd $CI_PROJECT_DIR
- pip install -r requirements.txt
- python main.py --template template.tex.j2 --data ${PROFILE_NAME}.yaml --out out
artifacts:
paths:
- $CI_PROJECT_DIR/out/resume.tex
deploy-cv:
stage: deploy
image: dxjoke/tectonic-docker
script:
- cd $CI_PROJECT_DIR
- tectonic out/resume.tex
artifacts:
paths:
- $CI_PROJECT_DIR/out/resume.pdfPause and predict
Will a downstream job automatically see a previous job’s local filesystem?
Try your own explanation first. These notes stay on this page and are not saved or graded.
Show explanation
Jobs run in separate environments. The TeX output must be published and downloaded as an artifact; inspect the artifacts paths in the pipeline.
The PDF step requires a TeX engine. Use the supplied container workflow or run tectonic out/resume.tex with a local installation. Stop and remove any containers you started interactively.
Take a moment to explain the idea in your own words.