Add node_modules mount to improve caching times

This commit adds `node_modules` to dagger run commands so cached builds have
similar speed times as running commands locally directly through yarn
<script>

Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>
This commit is contained in:
Marcos Lilljedahl 2022-03-22 16:01:32 -03:00
parent 69b4845d2e
commit 6344bb020b

View File

@ -8,6 +8,15 @@ import (
"universe.dagger.io/netlify" "universe.dagger.io/netlify"
) )
nodeModulesMount: "/src/node_modules": dagger.#Mount & {
dest: "/src/node_modules"
type: "cache"
contents: dagger.#CacheDir & {
id: "todoapp-modules-cache"
}
}
dagger.#Plan & { dagger.#Plan & {
client: { client: {
filesystem: { filesystem: {
@ -46,12 +55,15 @@ dagger.#Plan & {
// install yarn dependencies // install yarn dependencies
bash.#Run & { bash.#Run & {
workdir: "/src" workdir: "/src"
mounts: "/cache/yarn": dagger.#Mount & { mounts: {
dest: "/cache/yarn" "/cache/yarn": dagger.#Mount & {
type: "cache" dest: "/cache/yarn"
contents: dagger.#CacheDir & { type: "cache"
id: "todoapp-yarn-cache" contents: dagger.#CacheDir & {
id: "todoapp-yarn-cache"
}
} }
nodeModulesMount
} }
script: contents: #""" script: contents: #"""
yarn config set cache-folder /cache/yarn yarn config set cache-folder /cache/yarn
@ -64,6 +76,7 @@ dagger.#Plan & {
test: bash.#Run & { test: bash.#Run & {
input: deps.output input: deps.output
workdir: "/src" workdir: "/src"
mounts: nodeModulesMount
script: contents: #""" script: contents: #"""
yarn run test yarn run test
"""# """#
@ -72,6 +85,7 @@ dagger.#Plan & {
build: { build: {
run: bash.#Run & { run: bash.#Run & {
input: test.output input: test.output
mounts: nodeModulesMount
workdir: "/src" workdir: "/src"
script: contents: #""" script: contents: #"""
yarn run build yarn run build