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,13 +55,16 @@ dagger.#Plan & {
// install yarn dependencies // install yarn dependencies
bash.#Run & { bash.#Run & {
workdir: "/src" workdir: "/src"
mounts: "/cache/yarn": dagger.#Mount & { mounts: {
"/cache/yarn": dagger.#Mount & {
dest: "/cache/yarn" dest: "/cache/yarn"
type: "cache" type: "cache"
contents: dagger.#CacheDir & { contents: dagger.#CacheDir & {
id: "todoapp-yarn-cache" id: "todoapp-yarn-cache"
} }
} }
nodeModulesMount
}
script: contents: #""" script: contents: #"""
yarn config set cache-folder /cache/yarn yarn config set cache-folder /cache/yarn
yarn install yarn install
@ -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