Skip to content

Commit

Permalink
CI & Docker: Update
Browse files Browse the repository at this point in the history
  • Loading branch information
anishshobithps committed Jan 11, 2025
1 parent 2a2e2fc commit d5e54f7
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 52 deletions.
49 changes: 28 additions & 21 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
# Stage 1: TeX Live Base
FROM alpine:latest AS builder-texlive

RUN apk add --no-cache git bash wget perl # Perl is required by tlmgr

# Install TeX Live and set PATH in one step
RUN apk add --no-cache texlive texlive-full --repository=http://dl-cdn.alpinelinux.org/alpine/v3.18/main \
&& echo "/usr/local/texlive/2024/bin/x86_64-linux:$PATH" > /etc/profile.d/texlive.sh
# Stage 1: Builder with all necessary packages
FROM alpine:latest AS builder

# Install build dependencies
RUN apk add --no-cache \
texlive \
texlive-xetex \
texmf-dist \
texmf-dist-latexextra \
texmf-dist-fontsextra \
perl \
fontconfig \
make

# Stage 2: Final image with only runtime dependencies
FROM alpine:latest

# Stage 2: Fonts and Packages
FROM builder-texlive AS builder-fonts
# Install only runtime dependencies
RUN apk add --no-cache \
texlive-xetex \
texmf-dist \
fontconfig

RUN tlmgr install xcharter enumitem hyperref titlesec xstring geometry fancyhdr etoolbox

# Stage 3: Final Image
FROM alpine:latest
# Copy necessary files from builder
COPY --from=builder /usr/share/texmf-dist /usr/share/texmf-dist
COPY --from=builder /usr/share/texlive /usr/share/texlive
COPY --from=builder /var/lib/texmf /var/lib/texmf

WORKDIR /latex

# Copy necessary files
COPY --from=builder-fonts /usr/local/texlive/2024/texmf-dist /usr/local/texlive/2024/texmf-dist
COPY --from=builder-fonts /usr/local/texlive/2024/bin/x86_64-linux/xelatex /usr/local/texlive/2024/bin/x86_64-linux/xelatex
COPY --from=builder-fonts /usr/local/texlive/2024/bin/x86_64-linux/latexmk /usr/local/texlive/2024/bin/x86_64-linux/latexmk

# No need to set PATH again, it's already set in Stage 1
# Copy your LaTeX files
COPY entrypoint.sh /entrypoint.sh
COPY *.tex *.bib *.cls /latex/
COPY *.tex *.cls *.sty ./

RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
26 changes: 17 additions & 9 deletions .docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#!/bin/bash
#!/bin/sh
set -e

INPUT_FILE="$1"
OUTPUT_NAME="${2:-output.pdf}" # Default to output.pdf if no name specified
# Create output directory
mkdir -p /latex/output

# Compile the LaTeX document
latexmk -pdf "$INPUT_FILE"
# Run XeLaTeX with proper output name
xelatex -interaction=nonstopmode \
-output-directory=/latex/output \
-jobname="Anish_Shobith_P_S_Resume" \
"main.tex"

# Get the base name of the input file without extension
BASE_NAME=$(basename "$INPUT_FILE" .tex)
# Run again if needed for references
if grep -q "Rerun to get" "/latex/output/Anish_Shobith_P_S_Resume.log"; then
xelatex -interaction=nonstopmode \
-output-directory=/latex/output \
-jobname="Anish_Shobith_P_S_Resume" \
"main.tex"
fi

# Rename the output file
mv "${BASE_NAME}.pdf" "$OUTPUT_NAME"
# Copy the final PDF to the mounted volume
cp /latex/output/Anish_Shobith_P_S_Resume.pdf /latex/
60 changes: 38 additions & 22 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ name: Build and Release Resume
on:
push:
branches: [main]
paths:
- '**.tex'
- '**.cls'
- '**.sty'
- '.docker/**'
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
actions: write
packages: write

steps:
Expand All @@ -20,49 +23,62 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64
driver-opts: |
image=moby/buildkit:master
network=host
- name: Login to GitHub Container Registry
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .docker
push: true
tags: ghcr.io/${{ github.repository }}/latex-builder:latest
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/latex-builder:latest
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}/latex-builder:latest,mode=max
cache-from: |
type=local,src=/tmp/.buildx-cache
type=registry,ref=ghcr.io/${{ github.repository }}/latex-builder:latest
cache-to: |
type=local,dest=/tmp/.buildx-cache-new,mode=max
type=registry,ref=ghcr.io/${{ github.repository }}/latex-builder:latest,mode=max
build-args: |
BUILDKIT_INLINE_CACHE=1
- name: Build LaTeX document
- name: Move cache
run: |
docker run --rm -v ${{ github.workspace }}:/latex \
ghcr.io/${{ github.repository }}/latex-builder:latest \
/latex/entrypoint.sh "Anish_Shobith_P_S_Resume.pdf"
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Combine Metadata
id: metadata
- name: Build LaTeX document
run: |
echo "date=$(date +'%d-%m-%Y')" >> $GITHUB_OUTPUT
echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
mkdir -p output
docker run --rm -v ${{ github.workspace }}:/latex \
ghcr.io/${{ github.repository }}/latex-builder:latest
- name: Create Release
if: github.ref == 'refs/heads/main'
uses: softprops/action-gh-release@v2
with:
draft: false
prerelease: false
tag_name: v${{ steps.metadata.outputs.date }}
name: "Resume Update ${{ steps.metadata.outputs.date }}"
tag_name: v$(date +'%Y.%m.%d')
name: "Resume Update $(date +'%Y.%m.%d')"
body: |
📄 Resume update for ${{ steps.metadata.outputs.date }}
📄 Resume update $(date +'%Y.%m.%d')
**Commit**: ${{ steps.metadata.outputs.sha }}
**Commit**: ${{ github.sha }}
**Branch**: main
[View PDF](https://github.com/${{ github.repository }}/releases/download/v${{ steps.metadata.outputs.date }}/Anish_Shobith_P_S_Resume.pdf)
files: Anish_Shobith_P_S_Resume.pdf
token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit d5e54f7

Please sign in to comment.