Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,24 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ github.token }}

# Persist the Dockerfile builder's yarn cache mount across runs. The mount
# (holding downloaded + compiled git deps) is not part of the image layer
# cache, so buildkit-cache-dance saves/restores it via actions/cache.
- name: Restore Docker yarn cache
id: docker-yarn-cache
uses: actions/cache@v4
with:
path: docker-yarn-cache
key: ${{ runner.os }}-docker-yarn-cache-${{ hashFiles('yarn.lock') }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache key is hashFiles('yarn.lock') with no restore-keys, so when yarn.lock changes — the exact scenario the PR targets — the cache misses completely and yarn starts from scratch. Add a restore-keys prefix so a stale cache is reused on lockfile changes:

Suggested change
key: ${{ runner.os }}-docker-yarn-cache-${{ hashFiles('yarn.lock') }}
key: ${{ runner.os }}-docker-yarn-cache-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-docker-yarn-cache-

- name: Inject yarn cache into buildx
uses: reproducible-containers/buildkit-cache-dance@v3.1.2
with:
cache-map: |
{
"docker-yarn-cache": "/root/.yarn-cache"
}
skip-extraction: ${{ steps.docker-yarn-cache.outputs.cache-hit }}

- name: Build and push cloudserver image
uses: docker/build-push-action@v5
with:
Expand Down
12 changes: 11 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# syntax=docker/dockerfile:1.7

ARG NODE_VERSION=22.14.0-bookworm-slim

FROM node:${NODE_VERSION} AS builder
Expand All @@ -22,12 +24,20 @@ RUN apt-get update \
&& ssh-keyscan -H github.com > /root/ssh/known_hosts

ENV PYTHON=python3
# Persist yarn's cache in a fixed location so it can be mounted as a BuildKit
# cache below; this cache also holds the compiled git dependencies (e.g.
# arsenal's tsc output), so a warm cache skips the re-clone and re-compile.
ENV YARN_CACHE_FOLDER=/root/.yarn-cache
RUN npm install -g \
node-gyp \
typescript@4.9.5
COPY package.json yarn.lock /usr/src/app/

RUN yarn install --production --ignore-optional --frozen-lockfile --ignore-engines --network-concurrency 1
# BuildKit cache mount: even when this layer misses (e.g. yarn.lock changed),
# yarn reuses already-downloaded and already-built packages from the mount
# instead of re-cloning and re-running tsc for the git dependencies.
RUN --mount=type=cache,target=/root/.yarn-cache,sharing=locked \
yarn install --production --ignore-optional --frozen-lockfile --ignore-engines --network-concurrency 1

################################################################################
FROM node:${NODE_VERSION} AS production
Expand Down
Loading