Skip to content

Commit 5f25b9b

Browse files
authored
Container Build Caching (#509)
## Summary <!-- Include a short paragraph of the changes introduced in this PR. If this PR requires additional context or rationale, explain why the changes are necessary. --> Store `dnf` and `uv` caches in a GitHub Action cache. ## Details <!-- Provide a detailed list of all changes introduced in this pull request. --> Adds mount caches for `dnf` and `uv` to container image and stores their output into a action cache. Layer caching would probably be more efficient but requires a container repository for storing the intermediate layers. ## Test Plan <!-- List the steps needed to test this PR. --> Rerun the container build job and observe that build takes less time and skips download steps. --- - [x] "I certify that all code in this PR is my own, except as noted below." ## Use of AI - [ ] Includes AI-assisted code completion - [ ] Includes code generated by an AI application - [ ] Includes AI-generated tests (NOTE: AI written tests should have a docstring that includes `## WRITTEN BY AI ##`)
2 parents e2b34c1 + 4c0e2da commit 5f25b9b

File tree

4 files changed

+52
-14
lines changed

4 files changed

+52
-14
lines changed

.github/workflows/development.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ jobs:
142142
uses: actions/checkout@v4
143143
with:
144144
fetch-depth: 0
145+
- name: Store/retrieve build caches
146+
id: cache-buildah
147+
uses: actions/cache@v4
148+
with:
149+
path: /var/tmp/buildah-cache-*
150+
key: buildah-mount-cache-${{ runner.os }}-${{ runner.arch }}
145151
- name: Buildah build
146152
id: build-image
147153
uses: redhat-actions/buildah-build@v2
@@ -150,6 +156,7 @@ jobs:
150156
build-args: |
151157
GUIDELLM_BUILD_TYPE=dev
152158
tags: "pr-${{ github.event.number }}"
159+
layers: true
153160
containerfiles: |
154161
./Containerfile
155162
- name: Push To ghcr.io

.github/workflows/release-candidate.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,20 @@ jobs:
185185
if: ${{ env.package_version == '' }}
186186
run: |
187187
exit 1
188+
- name: Store/retrieve build caches
189+
id: cache-buildah
190+
uses: actions/cache@v4
191+
with:
192+
path: /var/tmp/buildah-cache-*
193+
key: buildah-mount-cache-${{ runner.os }}-${{ runner.arch }}
188194
- name: Buildah build
189195
id: build-image
190196
uses: redhat-actions/buildah-build@v2
191197
with:
192198
image: ${{ github.event.repository.name }}
193199
build-args: |
194200
GUIDELLM_BUILD_TYPE=candidate
195-
tags: ${{ env.package_version }}~rc
201+
tags: ${{ env.package_version }}-rc
196202
containerfiles: |
197203
./Containerfile
198204
- name: Push To ghcr.io

.github/workflows/release.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ jobs:
184184
if: ${{ env.package_version == '' }}
185185
run: |
186186
exit 1
187+
- name: Store/retrieve build caches
188+
id: cache-buildah
189+
uses: actions/cache@v4
190+
with:
191+
path: /var/tmp/buildah-cache-*
192+
key: buildah-mount-cache-${{ runner.os }}-${{ runner.arch }}
187193
- name: Buildah build
188194
id: build-image
189195
uses: redhat-actions/buildah-build@v2

Containerfile

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,47 @@ FROM $BASE_IMAGE as builder
1010
# dev: increment to next minor, add 'dev' with build iteration
1111
ARG GUIDELLM_BUILD_TYPE=dev
1212

13+
# Extra dependencies to install
14+
# all: install all extras
15+
# recommended: install recommended extras
16+
ARG GUIDELLM_BUILD_EXTRAS=all
17+
1318
# Switch to root for installing packages
1419
USER root
1520

16-
# Install build tooling
17-
RUN dnf install -y git \
18-
&& /usr/bin/python3 -m venv /tmp/uv \
21+
# Install uv in a temporary venv
22+
RUN /usr/bin/python3 -m venv /tmp/uv \
1923
&& /tmp/uv/bin/pip install --no-cache-dir -U uv \
2024
&& ln -s /tmp/uv/bin/uv /usr/local/bin/uv
2125

22-
# Set the default venv for uv
23-
# Copy instead of link files with uv
26+
# Install build dependencies
27+
RUN --mount=type=cache,sharing=locked,target=/var/cache/dnf \
28+
dnf install -y git
29+
2430
# Set correct build type for versioning
25-
ENV VIRTUAL_ENV=/opt/app-root \
31+
# Configure uv for building guidellm
32+
ENV GUIDELLM_BUILD_TYPE=$GUIDELLM_BUILD_TYPE \
33+
VIRTUAL_ENV=/opt/app-root \
34+
UV_PROJECT="/src" \
2635
UV_LINK_MODE="copy" \
27-
GUIDELLM_BUILD_TYPE=$GUIDELLM_BUILD_TYPE
36+
UV_NO_DEV="1" \
37+
UV_NO_EDITABLE="1" \
38+
UV_FROZEN="1" \
39+
UV_CACHE_DIR="/tmp/uv_cache"
40+
41+
# Sync initial environment
42+
RUN --mount=type=cache,target=$UV_CACHE_DIR \
43+
--mount=type=bind,source=uv.lock,target=$UV_PROJECT/uv.lock,relabel=shared \
44+
--mount=type=bind,source=pyproject.toml,target=$UV_PROJECT/pyproject.toml,relabel=shared \
45+
uv sync --active --no-install-project --extra $GUIDELLM_BUILD_EXTRAS
2846

2947
# Copy repository files
3048
# Do this as late as possible to leverage layer caching
31-
COPY / /src
49+
COPY / $UV_PROJECT
3250

33-
# Install guidellm and locked dependencies
34-
RUN uv sync --active --project /src --frozen --no-dev --extra all --no-editable
51+
# Install guidellm
52+
RUN --mount=type=cache,target=$UV_CACHE_DIR \
53+
uv sync --active --extra $GUIDELLM_BUILD_EXTRAS
3554

3655
# Prod image
3756
FROM $BASE_IMAGE
@@ -40,9 +59,9 @@ FROM $BASE_IMAGE
4059
USER root
4160

4261
# Install some helpful utilities and deps
43-
RUN dnf install -y --setopt=install_weak_deps=False \
44-
vi tar rsync ffmpeg-free \
45-
&& dnf clean all
62+
RUN --mount=type=cache,sharing=locked,target=/var/cache/dnf \
63+
dnf install -y --setopt=install_weak_deps=False \
64+
vi tar rsync ffmpeg-free
4665

4766
# Switch back to unpriv user
4867
# Root group for k8s

0 commit comments

Comments
 (0)