denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.7k stars 5.26k forks source link

Caching dependencies without source file, only `deno.lock` #21152

Open felipecrs opened 11 months ago

felipecrs commented 11 months ago

It is a recommended practice in docker to create layers with only the required files so that docker can properly calculate whether that layer can be skipped (through the build cache) in case the files have not changed.

With Node.js, this is how we can do it:

FROM node:18

WORKDIR /workspace

COPY package.json package-lock.json .

RUN npm ci

COPY . .

RUN npm run build

However, with Deno, I could not find a equivalent way of doing that without having to copy all my source files.

FROM deno:1.38

WORKDIR /workspace

COPY deno.jsonc deno.lock .

RUN deno cache <a source file is needed>

If I add the source file, it defeats the original recommendation.

Some notes:

  1. All my imports are defined in the deno.jsonc:
{
  "imports": {
    "chalk": "npm:chalk@^5.3.0",
    "common-tags": "npm:common-tags@^1.8.2",
    "execa": "npm:execa@^8.0.1",
    "glob": "npm:glob@^10.2.2",
    "js-yaml": "npm:js-yaml@^4.1.0",
    "jsonpath-plus": "npm:jsonpath-plus@^7.2.0",
    "listr2": "npm:listr2@^7.0.2",
    "lodash": "npm:lodash@^4.17.21",
    "semver": "npm:semver@^7.5.0"
  }
}
  1. My deno.lock is up to date.

I believe there should be a way to cache dependencies just taking the lockfile as input. Something like:

deno cache --from-lock

What do you guys think?

felipecrs commented 6 months ago

Now with deno add, this feature makes even more sense.

eikooc commented 2 months ago

It would be awesome if deno compile had the same option

felipecrs commented 2 months ago

Is DENO_FUTURE=1 deno install the solution for this?

Flexicon commented 2 months ago

Well, would DENO_FUTURE=1 deno install require switching to a package.json setup? Or would it work with deno.json as well - I think that would be the real make it or break it scenario here.

marvinhagemeister commented 2 months ago

The DENO_FUTURE=1 deno install command works with deno.json.