meltwater / drone-cache

A Drone plugin for caching current workspace files between builds to reduce your build times
https://underthehood.meltwater.com/blog/2019/04/10/making-drone-builds-10-times-faster/
Apache License 2.0
338 stars 81 forks source link

Can't cache gradle dependencies with message "no such file or directory" #235

Open KangbingZhao opened 1 year ago

KangbingZhao commented 1 year ago

Describe the bug can't cache gradle dependencies.

I mount host directory /tmp/cache/gradle as cache.

I checked that it's exact gradle depedencies directory.

image

but rebuilding cache failed

image

To Reproduce Steps to reproduce the behavior:

kind: pipeline
type: docker
name: test
steps:
  - name: restore-cache-with-filesystem
    image: meltwater/drone-cache
    pull: if-not-exists
    settings:
      backend: "filesystem"
      restore: true
      cache_key: "volume"
      archive_format: "gzip"
      mount:
        - "/root/.gradle/caches"
    volumes:
      - name: cache
        path: /tmp/cache/gradle
  - name: pre
    image: openjdk:17-jdk-slim
    volumes:
      - name: sock
        path: /var/run/docker.sock
    commands:
      - ./gradlew build -profile -i
      - cd /root/.gradle
      - ls -a
  - name: rebuild-cache-with-filesystem
    image: meltwater/drone-cache
    pull: if-not-exists
    settings:
      backend: "filesystem"
      rebuild: true
      cache_key: "volume"
      archive_format: "gzip"
      # filesystem_cache_root: "/tmp/cache"
      mount:
        - "/root/.gradle/caches"
    volumes:
      - name: cache
        path: /tmp/cache/gradle
volumes:
  - name: sock
    host:
      path: /var/run/docker.sock
  - name: cache
    host:
      path: /tmp/cache/gradle

Specifications

profound7 commented 1 year ago

It seems that caching doesn't work outside of the working directory (/drone/src) as that is the directory that drone retains across steps (correct me if I'm wrong). I'm trying to cache .m2 directory. Here's some additional information.

These mount directories don't work:

This work, but I have to let maven know:

I either have to use maven like so mvn -Dmaven.repo.local=.m2/repository ... or set environment variable MAVEN_OPTS=-Dmaven.repo.local=.m2/repository

So for gradle, or other programs, you have to check and see if there's a way to specify a custom directory. I hope this plugin could support caching outside of the /drone/src directory.