Skip to content

Commit da706b7

Browse files
author
Susan Vanderplas
committed
Updates via chatgpt
1 parent 6cd1e31 commit da706b7

File tree

2 files changed

+86
-78
lines changed

2 files changed

+86
-78
lines changed

.github/workflows/main.yml

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Render and deploy Quarto files
2+
23
on:
34
push:
45
pull_request:
56

6-
77
jobs:
88
build:
99
runs-on: ubuntu-latest
@@ -16,40 +16,77 @@ jobs:
1616
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1717
GH_PAT: ${{ secrets.GH_PAT }}
1818
GITHUB_PAT: ${{ secrets.GH_PAT }}
19-
RENV_CACHE: ~/.cache/renv
20-
PIP_CACHE: ~/.cache/pip
19+
2120
steps:
2221
- name: Checkout repository
2322
uses: actions/checkout@v4
2423

25-
# Prepare cache directories so they always exist
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
# Make sure caches exist even on first run
2628
- name: Prepare cache dirs
2729
run: |
2830
mkdir -p ~/.cache/pip
29-
mkdir -p ~/.cache/renv
31+
mkdir -p ~/.local/share/renv
3032
31-
# Cache Python packages
32-
- name: Cache pip packages
33+
- name: Cache pip (downloads/wheels)
3334
uses: actions/cache@v4
3435
with:
3536
path: ~/.cache/pip
3637
key: ${{ runner.os }}-pip-${{ hashFiles('setup/requirements.txt') }}
3738
restore-keys: |
3839
${{ runner.os }}-pip-
3940
40-
# Cache R packages from renv
41-
- name: Cache R packages
41+
- name: Cache renv (global cache, not project folder)
4242
uses: actions/cache@v4
4343
with:
44-
path: renv
45-
key: ${{ runner.os }}-renv-${{ hashFiles('renv.lock') }}
44+
path: ~/.local/share/renv
45+
key: ${{ runner.os }}-renv-${{ hashFiles('setup/renv.lock') }}
4646
restore-keys: |
4747
${{ runner.os }}-renv-
4848
49-
# Build Docker image
50-
- name: Build Docker image
51-
run: docker build -t local/quarto-reticulate:latest .
49+
- name: Build Docker image with layer cache
50+
uses: docker/build-push-action@v6
51+
with:
52+
context: .
53+
file: ./Dockerfile
54+
push: false
55+
tags: local/quarto-reticulate:latest
56+
cache-from: type=gha
57+
cache-to: type=gha,mode=max
5258

53-
# Run Docker container (optional test)
54-
- name: Test build inside container
55-
run: docker run --rm local/quarto-reticulate:latest
59+
# Run inside the container against the mounted repo
60+
- name: Render & publish with cached renv/pip
61+
run: |
62+
docker run --rm \
63+
-v "${{ github.workspace }}:/project" \
64+
-v "${HOME}/.local/share/renv:/root/.local/share/renv" \
65+
-v "${HOME}/.cache/pip:/root/.cache/pip" \
66+
-e RENV_PATHS_CACHE=/root/.local/share/renv \
67+
-e PIP_CACHE_DIR=/root/.cache/pip \
68+
-e NEWSAPI_KEY="${{ secrets.NEWSAPI_KEY }}" \
69+
-e GH_APP_ID="${{ secrets.GH_APP_ID }}" \
70+
-e GH_APP_SECRET="${{ secrets.GH_APP_SECRET }}" \
71+
-e GH_PAT_DEMO="${{ secrets.GH_PAT_DEMO }}" \
72+
-e GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
73+
-e GH_PAT="${{ secrets.GH_PAT }}" \
74+
-e GITHUB_PAT="${{ secrets.GH_PAT }}" \
75+
local/quarto-reticulate:latest \
76+
/bin/sh -c '
77+
set -e
78+
# R deps from renv in setup/
79+
if [ -f "/project/renv.lock" ]; then
80+
Rscript -e "renv::restore(project = '/project', prompt = FALSE)"
81+
fi
82+
# Python deps
83+
if [ -f "/project/setup/requirements.txt" ]; then
84+
python3 -m venv /root/.virtualenvs/venv
85+
/root/.virtualenvs/venv/bin/pip install --upgrade pip
86+
/root/.virtualenvs/venv/bin/pip install --cache-dir ${PIP_CACHE_DIR} -r /project/setup/requirements.txt
87+
export PATH=/root/.virtualenvs/venv/bin:$PATH
88+
fi
89+
# Quarto
90+
cd /project
91+
quarto render && quarto publish
92+
'

Dockerfile

Lines changed: 32 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,48 @@
1-
# Base image
2-
FROM rocker/verse:latest
1+
# Fast, sane base with R + tools
2+
FROM rocker/verse:4.5
33

4-
# Set environment variables so renv/pip use them
5-
ENV R_CACHE=/root/.cache/R/
6-
ENV RENV_CACHE=/root/.cache/R/renv/
7-
ENV PIP_CACHE=/root/.cache/pip
8-
9-
# Install Python
10-
RUN apt-get update && apt-get install -y \
11-
python3 python3-pip python3-venv python3-dev\
12-
&& rm -rf /var/lib/apt/lists/*
13-
14-
# Install system dependencies
15-
RUN apt-get update && apt-get upgrade -y && \
16-
apt-get install -y --no-install-recommends \
17-
make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev \
18-
libsqlite3-dev curl libncursesw5-dev xz-utils tk-dev libxml2-dev \
19-
libxmlsec1-dev libffi-dev liblzma-dev \
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
# Default cache locations (can be overridden at runtime)
6+
ENV RENV_PATHS_CACHE=/root/.local/share/renv \
7+
PIP_CACHE_DIR=/root/.cache/pip
8+
9+
# --- Layer 1: OS deps (cacheable)
10+
RUN --mount=type=cache,target=/var/cache/apt \
11+
--mount=type=cache,target=/var/lib/apt \
12+
apt-get update && apt-get install -y --no-install-recommends \
13+
python3 python3-pip python3-venv python3-dev \
14+
libcurl4-openssl-dev libssl-dev libxml2-dev \
2015
libtesseract-dev libpoppler-cpp-dev tesseract-ocr \
21-
libleptonica-dev libpng-dev libjpeg-dev libtiff-dev imagemagick \
22-
gdal-bin libgdal-dev libsecret-1-dev \
23-
default-jdk openjdk-11-jdk \
16+
libleptonica-dev libpng-dev libjpeg-dev libtiff-dev \
17+
imagemagick gdal-bin libgdal-dev libsecret-1-dev \
2418
libglpk-dev libudunits2-dev \
25-
gnupg software-properties-common
19+
curl gnupg ca-certificates \
20+
&& rm -rf /var/lib/apt/lists/*
2621

27-
# Install GitHub CLI
28-
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | \
29-
dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && \
22+
# --- Layer 2: GitHub CLI (optional)
23+
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
24+
| dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && \
3025
chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && \
3126
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
3227
> /etc/apt/sources.list.d/github-cli.list && \
3328
apt-get update && apt-get install -y gh && \
3429
rm -rf /var/lib/apt/lists/*
3530

36-
# Install Quarto CLI separately
37-
RUN curl -fsSL https://quarto.org/download/latest/quarto-linux-amd64.deb -o quarto.deb && \
38-
apt-get update && apt-get install -y ./quarto.deb && \
39-
rm quarto.deb
40-
41-
# Environment variables
42-
ENV JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64/"
43-
ENV PATH=/root/.pyenv/bin:$PATH
44-
ENV VENV_PATH="/root/.virtualenvs/venv"
45-
ENV REQ_FILE="/project/setup/requirements.txt"
46-
ENV DEBIAN_FRONTEND=noninteractive
47-
48-
# Make sure these exist
49-
# RUN mkdir -p ${RENV_CACHE} ${PIP_CACHE}
50-
51-
# Install tinytex system-wide (for LaTeX support)
52-
RUN --mount=type=cache,target=${R_CACHE} Rscript -e "install.packages('tinytex'); tinytex::install_tinytex(force=T)"
53-
54-
# Install minimal R packages for system-level support
55-
RUN --mount=type=cache,target=${R_CACHE} Rscript -e "install.packages(c('digest','devtools','renv','reticulate','yaml'))"
31+
# --- Layer 3: Quarto
32+
RUN curl -fsSL https://quarto.org/download/latest/quarto-linux-amd64.deb -o /tmp/quarto.deb && \
33+
apt-get update && apt-get install -y /tmp/quarto.deb && rm -f /tmp/quarto.deb && \
34+
rm -rf /var/lib/apt/lists/*
5635

57-
# Copy renv.lock and renv directory for layer caching, install R dependencies via renv
58-
COPY renv.lock /project/renv.lock
59-
COPY renv /project/renv
36+
# --- Layer 4: TinyTeX (LaTeX)
37+
RUN Rscript -e "install.packages('tinytex', repos='https://cloud.r-project.org'); tinytex::install_tinytex()"
6038

61-
# Restore R deps from renv.lock using persistent cache
62-
RUN --mount=type=cache,target=${R_CACHE} Rscript -e 'renv::restore(lockfile = "/project/renv.lock", prompt = FALSE)'
39+
# Optional: a couple of helper R packages used during checks
40+
RUN Rscript -e "install.packages(c('digest'), repos='https://cloud.r-project.org')"
6341

64-
# Copy Python requirements file if exists (cached separately)
65-
COPY setup/requirements.txt ${REQ_FILE}
66-
RUN --mount=type=cache,target=${PIP_CACHE} python3 -m venv /root/.virtualenvs/venv && \
67-
"${VENV_PATH}/bin/pip" install --cache-dir "${PIP_CACHE}" -r "${REQ_FILE}"
42+
# Ensure cache dirs always exist (first-run safe)
43+
RUN mkdir -p ${RENV_PATHS_CACHE} ${PIP_CACHE_DIR} /root/.virtualenvs
6844

69-
# Copy the rest of the project
70-
COPY . /project
7145
WORKDIR /project
7246

73-
# Verify Environment
74-
RUN Rscript -e "renv::status();renv::diagnostics();devtools::session_info();reticulate::py_config()"
75-
76-
# Default command
77-
CMD ["/bin/sh", "-c", "quarto render && quarto publish"]
47+
# Default command: render then publish
48+
CMD ["/bin/sh","-c","quarto render && quarto publish"]

0 commit comments

Comments
 (0)