diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4bb0491470..07236bf0d3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,6 +29,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: "22" + cache: "yarn" - run: yarn - run: yarn build - run: yarn test diff --git a/.github/workflows/npm.yml b/.github/workflows/npm.yml index 52ed09e4cb..5abdb72597 100644 --- a/.github/workflows/npm.yml +++ b/.github/workflows/npm.yml @@ -39,6 +39,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: "22" + cache: "yarn" registry-url: "https://registry.npmjs.org" - name: Install dependencies and build diff --git a/Dockerfile b/Dockerfile index d7a3c4fa2e..d15373a996 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,20 +9,34 @@ COPY .git dappnode_package.json docker/getGitData.js ./ RUN apk add --no-cache git RUN node getGitData /usr/src/app/.git-data.json +# Extract only package.json files to preserve dependency layer cache +FROM ${BASE_IMAGE} AS manifests +WORKDIR /app +COPY packages packages +RUN find packages -mindepth 2 ! -name "package.json" -delete 2>/dev/null; \ + find packages -empty -delete 2>/dev/null; true + # Build stage FROM ${BASE_IMAGE} AS build-src ENV VITE_APP_API_URL / WORKDIR /app -# Copy and build packages -COPY package.json yarn.lock .yarnrc.yml tsconfig.json ./ -COPY packages packages +# Copy dependency manifests only (changes less often, preserves layer cache) +COPY package.json yarn.lock .yarnrc.yml ./ +COPY --from=manifests /app/packages ./packages # Install necessary packages required by vite RUN apk add --no-cache python3 py3-pip build-base # Install corepack to be able to use modern yarn berry RUN corepack enable + +# Since we copied dependency manifests only, if there are changes in source code, +# that don't change dependencies, we can reuse the cached layer with installed dependencies. RUN yarn install --immutable + +# Copy source code and build +COPY tsconfig.json ./ +COPY packages packages # Build and install production dependencies RUN yarn build && \ yarn workspaces focus --all --production