Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZEA-4316: Disable caching dependencies by default in Node.js #388

Merged
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
24 changes: 12 additions & 12 deletions devenv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1727457166,
"lastModified": 1732121232,
"owner": "cachix",
"repo": "devenv",
"rev": "6090da46bfb53e358b818cee491df1a25daa85e0",
"rev": "6ff1e5f92c0d74bbb12f7454a239ca2f02e05ea1",
"type": "github"
},
"original": {
Expand Down Expand Up @@ -36,10 +36,10 @@
"systems": "systems"
},
"locked": {
"lastModified": 1726560853,
"lastModified": 1731533236,
"owner": "numtide",
"repo": "flake-utils",
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
Expand Down Expand Up @@ -76,10 +76,10 @@
]
},
"locked": {
"lastModified": 1727478263,
"lastModified": 1729448365,
"owner": "nix-community",
"repo": "gomod2nix",
"rev": "ba932692e249374e91bcbfe2e3a25ed3342a72eb",
"rev": "5d387097aa716f35dd99d848dc26d8d5b62a104c",
"type": "github"
},
"original": {
Expand All @@ -90,10 +90,10 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1727524699,
"lastModified": 1731890469,
"owner": "nixos",
"repo": "nixpkgs",
"rev": "b5b2fecd0cadd82ef107c9583018f381ae70f222",
"rev": "5083ec887760adfe12af64830a66807423a859a7",
"type": "github"
},
"original": {
Expand All @@ -105,10 +105,10 @@
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1727540905,
"lastModified": 1731797254,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "fbca5e745367ae7632731639de5c21f29c8744ed",
"rev": "e8c38b73aeb218e27163376a2d617e61a2ad9b59",
"type": "github"
},
"original": {
Expand All @@ -128,10 +128,10 @@
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1727514110,
"lastModified": 1732021966,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "85f7a7177c678de68224af3402ab8ee1bcee25c8",
"rev": "3308484d1a443fc5bc92012435d79e80458fe43c",
"type": "github"
},
"original": {
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ schema = 3
version = "v0.5.7"
hash = "sha256-DCfko42wd7W9NadYPPX9c9H2HNH9DQHZTrfI9CTZqXQ="
[mod."github.com/goccy/go-yaml"]
version = "v1.13.7"
hash = "sha256-d9W2+Ywo6WHV4C6JvkfU/DfO0KPxu7lYlR4PLHv94c8="
version = "v1.14.3"
hash = "sha256-rdQctQ0723s4WRfhW960dJz545lG4oDMf2K/foiNPZA="
[mod."github.com/gogo/protobuf"]
version = "v1.3.2"
hash = "sha256-pogILFrrk+cAtb0ulqn9+gRZJ7sGnnLLdtqITvxvG6c="
Expand Down
16 changes: 13 additions & 3 deletions internal/nodejs/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,17 @@ func GetInstallCmd(ctx *nodePlanContext) string {
}

pkgManager := DeterminePackageManager(ctx)
shouldCacheDependencies := plan.Cast(ctx.Config.Get(ConfigCacheDependencies), plan.ToWeakBoolE).TakeOr(true)

// Disable cache_dependencies by default now due to some known cases:
//
// * Monorepos: the critical dependencies are usually in the subdirectories.
// * Some postinstall scripts may require some files (other than package.json and
// lockfiles in the root)
// * Customized installation command
// * app root != project root (which means, there is more than 1 apps in this project)
//
// Considering we do not cache the Docker layer, let's disable it by default.
shouldCacheDependencies := plan.Cast(ctx.Config.Get(ConfigCacheDependencies), plan.ToWeakBoolE).TakeOr(false)

// disable cache_dependencies for monorepos
if shouldCacheDependencies && utils.HasFile(src, "pnpm-workspace.yaml", "pnpm-workspace.yml", "packages") {
Expand Down Expand Up @@ -574,14 +584,14 @@ func GetInstallCmd(ctx *nodePlanContext) string {
needPlaywright := DetermineNeedPlaywright(ctx)
if needPlaywright {
cmds = append([]string{
"RUN apt-get update && apt-get install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdbus-1-3 libdrm2 libxkbcommon-x11-0 libxcomposite-dev libxdamage1 libxfixes-dev libxrandr2 libgbm-dev libasound2",
"RUN apt-get update && apt-get install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdbus-1-3 libdrm2 libxkbcommon-x11-0 libxcomposite-dev libxdamage1 libxfixes-dev libxrandr2 libgbm-dev libasound2 && rm -rf /var/lib/apt/lists/*",
}, cmds...)
}

needPuppeteer := DetermineNeedPuppeteer(ctx)
if needPuppeteer {
cmds = append([]string{
"RUN apt-get update && apt-get install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgbm1 libasound2 libpangocairo-1.0-0 libxss1 libgtk-3-0 libxshmfence1 libglu1",
"RUN apt-get update && apt-get install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgbm1 libasound2 libpangocairo-1.0-0 libxss1 libgtk-3-0 libxshmfence1 libglu1 && rm -rf /var/lib/apt/lists/*",
"ENV PUPPETEER_CACHE_DIR=/src/.cache/puppeteer",
}, cmds...)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/nodejs/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func TestGetInstallCmd_DefaultInstallCmd(t *testing.T) {
// RUN should be provided in planMeta
assert.Contains(t, installlCmd, "RUN ")

// for default installation command, cache are allowed.
assert.Contains(t, installlCmd, "COPY yarn.lock* .")
// for default installation command, cache is disabled.
assert.NotContains(t, installlCmd, "COPY yarn.lock* .")

// the installation command should be contained
assert.Contains(t, installlCmd, "yarn install")
Expand Down Expand Up @@ -360,7 +360,7 @@ func TestInstallCommand(t *testing.T) {
assert.Contains(t, installCmd, "WORKDIR /src/packages/service1")
})

t.Run("normal", func(t *testing.T) {
t.Run("normal (cache is disabled)", func(t *testing.T) {
t.Parallel()

fs := afero.NewMemMapFs()
Expand All @@ -373,7 +373,7 @@ func TestInstallCommand(t *testing.T) {
}

installCmd := GetInstallCmd(ctx)
assert.NotContains(t, installCmd, "COPY . .")
assert.Contains(t, installCmd, "COPY . .")
assert.NotContains(t, installCmd, "WORKDIR")
})

Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/bun-bagel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "true"
bunVersion: "latest"
framework: "bagel"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY bun.lockb* .\nRUN bun install"
installCmd: "COPY . .\nRUN bun install"
nodeVersion: "20"
packageManager: "bun"
startCmd: "bun run start"
2 changes: 1 addition & 1 deletion tests/snapshots/bun-baojs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "true"
bunVersion: "latest"
framework: "baojs"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY bun.lockb* .\nRUN bun install"
installCmd: "COPY . .\nRUN bun install"
nodeVersion: "20"
packageManager: "bun"
startCmd: "bun run start"
2 changes: 1 addition & 1 deletion tests/snapshots/bun-elysia.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "true"
bunVersion: "latest"
framework: "none"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY bun.lockb* .\nRUN bun install"
installCmd: "COPY . .\nRUN bun install"
nodeVersion: "20"
packageManager: "bun"
startCmd: "bun run src/index.ts"
2 changes: 1 addition & 1 deletion tests/snapshots/bun-nextjs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "next.js"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY bun.lockb* .\nRUN bun install"
installCmd: "COPY . .\nRUN bun install"
nodeVersion: "20"
packageManager: "bun"
serverless: "true"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/bun-nuxtjs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "true"
bunVersion: "latest"
framework: "nuxt.js"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY bun.lockb* .\nRUN bun install"
installCmd: "COPY . .\nRUN bun install"
nodeVersion: "20"
packageManager: "bun"
serverless: "true"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/bun-plain.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "true"
bunVersion: "latest"
framework: "none"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY bun.lockb* .\nRUN bun install"
installCmd: "COPY . .\nRUN bun install"
nodeVersion: "20"
packageManager: "bun"
startCmd: "bun run start"
2 changes: 1 addition & 1 deletion tests/snapshots/bun-without-lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "true"
bunVersion: "latest"
framework: "none"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY bun.lockb* .\nRUN bun install"
installCmd: "COPY . .\nRUN bun install"
nodeVersion: "20"
packageManager: "bun"
startCmd: "bun run src/index.ts"
2 changes: 1 addition & 1 deletion tests/snapshots/bun-yarn-lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "true"
bunVersion: "latest"
framework: "none"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY bun.lockb* .\nRUN bun install"
installCmd: "COPY . .\nRUN bun install"
nodeVersion: "20"
packageManager: "bun"
startCmd: "bun run start"
2 changes: 1 addition & 1 deletion tests/snapshots/node-astro.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "astro"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
packageManager: "pnpm"
serverless: "true"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/node-sveltekit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "svelte"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
packageManager: "pnpm"
serverless: "true"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-a-lot-of-dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "next.js"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY yarn.lock* .\nRUN yarn install"
installCmd: "COPY . .\nRUN yarn install"
nodeVersion: "20"
packageManager: "yarn"
serverless: "true"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-angular.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "angular"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY package-lock.json* .\nRUN npm install"
installCmd: "COPY . .\nRUN npm install"
nodeVersion: "20"
outputDir: "dist/angular-template/browser"
packageManager: "npm"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-docusaurus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "docusaurus"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "16"
outputDir: "build"
packageManager: "pnpm"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-expressjs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "none"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
packageManager: "pnpm"
startCmd: "pnpm start"
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-foal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "none"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "18"
packageManager: "pnpm"
startCmd: "pnpm start"
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-nestjs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "nest.js"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
packageManager: "pnpm"
startCmd: "pnpm start"
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-nextjs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "next.js"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
packageManager: "pnpm"
serverless: "true"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-nuejs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "nuejs"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
packageManager: "pnpm"
startCmd: "pnpm start"
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-nuxtjs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "nuxt.js"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
packageManager: "pnpm"
serverless: "true"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-payload.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "next.js"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY yarn.lock* .\nRUN yarn install"
installCmd: "COPY . .\nRUN yarn install"
nodeVersion: "20"
packageManager: "yarn"
serverless: "true"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-qwik-city.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "qwik"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY package-lock.json* .\nRUN npm install"
installCmd: "COPY . .\nRUN npm install"
nodeVersion: "15"
packageManager: "npm"
startCmd: "npm run deploy"
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-remix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "remix"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "18"
packageManager: "pnpm"
serverless: "true"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-rspress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "rspress"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
outputDir: "doc_build"
packageManager: "pnpm"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-slidev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "sli.dev"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
outputDir: "dist"
packageManager: "pnpm"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-starlight.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "astro-starlight"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
outputDir: "dist"
packageManager: "pnpm"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-umi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "umi"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nCOPY pnpm-lock.yaml* .\nRUN pnpm install"
installCmd: "COPY . .\nRUN pnpm install"
nodeVersion: "20"
outputDir: "dist"
packageManager: "pnpm"
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/nodejs-vite-vanilla.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Meta:
bun: "false"
bunVersion: "latest"
framework: "vite"
installCmd: "COPY package.json* tsconfig.json* .npmrc* .\nRUN yarn install"
installCmd: "COPY . .\nRUN yarn install"
nodeVersion: "20"
outputDir: "dist"
packageManager: "unknown"
Expand Down
Loading
Loading