#This really opens up the convo of should

1 messages · Page 1 of 1 (latest)

torpid moth
#

it feels to me (at least for a case like this) that volumes should be a copy-on-read per session or something

#

But there are 100% other cases that depend on sharing volumes

severe dawn
#

imo they should at least have a configurable name so a user can just specify a new name to bust the cache

#

or just have the cache volume itself be passed as an arg

#

cache true/false isn't versatile enough

#

it's not even really a 'bust cache' hack, you can just think of them like volume names

dire bough
#

Great to know, I saw this break myself yesterday too but didnt expect it to be in front of the whole world today haah

severe dawn
#

(in fact we should probably introduce a 'named non-cache volumes' concept, if only in name, to distinguish from actual caches, which should not affect the result of a function)

bold yoke
#

This is a pretty neat pattern I just saw in a Dockerfile as I was translating it into Dagger TypeScript:

@object()
class NodeDepsExample {
  /**
   * base node Container
   */
  @func()
  base(): Container {
    return dag.container().from("node:20-alpine");
  }
  /**
   * fronted node deps - provide frontend/ in proj repo as dir
   */
  @func()
  frontendDeps(dir: Directory): Container {
    return this.base()
      .withWorkdir("/app")
      .withFiles(".", [
        dir.file("package.json"),
        dir.file("package-lock.json"),
      ])
      .withExec(["npm", "ci", "--only-production", "--ignore-scripts"]);
  }
  /**
   * fronted builder - provide frontend/ in proj repo as dir
   */
  @func()
  frontendBuilder(dir: Directory): Container {
    return this.base()
      .withWorkdir("/app")
      .withDirectory(
        "./node_modules",
        this.frontendDeps(dir).directory("/app/node_modules")
      )
      .withExec(["npm", "run", "build"]);
  }
}

So if the frontend/package.json hasn't changed in the code repo, then you can use the cachednode_modules/ from fontendDeps()in several other functions and across dagger call invocations.

#

In the project I'm working on, here's the frontend/ directory:

$ tree frontend -L 1

frontend/
├── Dockerfile
├── Dockerfile.dev
├── README.md
├── cypress/
├── cypress.config.js
├── next-env.d.ts
├── next.config.js
├── package-lock.json
├── package.json
├── postcss.config.js
├── public/
├── scripts/
├── src/
├── tailwind.config.js
├── tsconfig.json
└── tsconfig.tsbuildinfo