[solved] help caching node_modules when using docker plugin

I don’t want to re-download docker images on every build

The docker plugin is ephemeral and does have access to the host machine docker cache, for isolation and security reasons. If you need access to the host machine docker cache (for image caching, layer caching, etc) this particular plugin is not going to be a good fit. The docker plugin is not mandatory; you can use other plugins or even shell scripting. See this previous thread for further explanation:

http://discuss.harness.io/t/docker-build-does-not-use-cache-drone-cli-exec/2359/2

I don’t want npm -i in my Dockerfile to re-download all my deps for every build.

I think I see the disconnect. Docker builds your image in a temporary directory (note that this is a bit of an oversimplification). This means that under the hood, the COPY directive in your Dockerfile is copying /drone/src into the temporary directory. Therefore running npm install inside the Dockerfile is going to download your node_modules to the temporary directory, not to /drone/src/node_modules.

If you want to cache node_modules, you need to download your dependencies outside of your Dockerfile. Then you can use the ADD or COPY directive to add the node_modules folder to your Dockerfile. This eliminates the need for RUN npm i.

For example:

- name: restore
  image: drillster/drone-volume-cache
  settings:
    restore: true
    mount:
    - ./node_modules
  volumes:
  - name: cache
    path: /cache

- name: deps
  image: node
  commands:
  - npm install

- name: build
  image: plugins/docker
  settings:
    ...