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