Drillster / drone-volume-cache

Drone plugin for caching to a locally mounted volume
MIT License
109 stars 42 forks source link

Cache misses when mounted directory exist #28

Closed dwick closed 3 years ago

dwick commented 3 years ago

drone.yaml:

kind: pipeline
name: Lint and Test

platform:
  os: linux
  arch: amd64

trigger:
  event:
    - push
    - pull_request
  branch:
    - master

volumes:
  - name: node_cache
    host:
      path: /tmp/cache

steps:
  - name: generate-cache-key
    image: ubuntu:14.04
    pull: if-not-exists
    volumes:
      - name: node_cache
        path: /cache
    commands:
      - md5sum yarn.lock | awk '{print "my-service-"$1;}' > .cache_key
      - cat .cache_key
      - ls /cache
      - ls /cache/$(cat .cache_key) || exit 0
    depends_on:
      - clone

  - name: restore-yarn-cache
    image: drillster/drone-volume-cache
    pull: if-not-exists
    settings:
      restore: true
      mount:
        - ./node_modules
    volumes:
      - name: node_cache
        path: /cache
    depends_on:
      - generate-cache-key

  - name: install
    image: node:12.20.0
    pull: if-not-exists
    commands:
      - yarn --offline
    environment:
      DEBIAN_FRONTEND: noninteractive
    depends_on:
      - restore-yarn-cache

  - name: rebuild-yarn-cache
    image: drillster/drone-volume-cache
    pull: if-not-exists
    settings:
      rebuild: true
      mount:
        - ./node_modules
    environment:
      PLUGIN_CACHE_KEY_DISABLE_SANITIZE: true
    volumes:
      - name: node_cache
        path: /cache
    depends_on:
      - install

Relevant output:

# Lint and Test — generate-cache-key

+ md5sum yarn.lock | awk '{print "my-service-"$1;}' > .cache_key
+ cat .cache_key
my-service-3915dae472a35a3dbba39b10e3ef37c1
+ ls /cache
my-service-3915dae472a35a3dbba39b10e3ef37c1
+ ls /cache/$(cat .cache_key) || exit 0
node_modules

# Lint and Test — restore-yarn-cache

Found a .cache_key file to be used as the cache path!
No cache for ./node_modules

# Lint and Test — install

+ yarn --offline
yarn install v1.19.1
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
[4/5] Linking dependencies...
[5/5] Building fresh packages...
Done in 88.63s.

# Lint and Test — rebuild-yarn-cache

Found a .cache_key file to be used as the cache path!
Warning! .cache_key will be used as-is. Sanitization is your responsibility to make it filename friendly!
Rebuilding cache for folder ./node_modules...

node_modules exists in the cache directory for the cache key generated so I'm a little confused why this isn't a hit.

dwick commented 3 years ago

Was missing PLUGIN_CACHE_KEY_DISABLE_SANITIZE on restore 🤦