Skip to content

Delete/clear task caches #1817

Closed
Closed

Description

@ipsi

Feature Request

What challenge are you facing?

We're running into an issue where our node_modules cache has become corrupted somehow, giving us errors like:

Error: node_modules/@angular/flex-layout/media-query/breakpoints/break-points.d.ts(8,10): error TS2305: Module '"/tmp/build/faf44d05/ui/node_modules/@angular/core/core"' has no exported member 'OpaqueToken'.

on doing an ng build.

Our task configuration is like so:

---
platform: linux
inputs:
- name: ui
run:
  path: ui/ci/tasks/build-ui.sh
caches:
- path: ui/node_modules
outputs:
- name: artifacts

The easiest solution for this is to nuke the node_modules directory and recreate it. As it stands, the only options for that are (a) remove the caches block from the task, (b) re-create the worker(s), (c) rename the task, or (d) modify the script to execute rm -Rf ui/node_modules/*.

As we don't have BOSH access to Concourse (only Fly), (b) is out. Since we do want caching (a) isn't really on the table. This leaves (c) and (d), both of which feel like somewhat hacky work-arounds to the issue.

A Modest Proposal

I'd like to be able to do something along the lines of fly -t target clear-cache -j pipeline/job -a task_name -c path/to/cache, which would remove all data in the cache, and present a fresh, squeaky-clean directory the next time the task runs.

Some edge cases:

  • What happens if task is running when we clear the cache?
  • Will this become horrifically slow if I have a large number of workers?

Activity

  1. codesuki commented on Nov 22, 2017

    @codesuki

    Agreed, this is something I wanted, too. Additionally it would be cool define a key for the cache by ourselves. My use case for this is, I am building and testing with bazel. My first step runs bazel test and of course builds things, and my second step does bazel build, but cannot re-use the cache from bazel test.

  2. vito commented on Jan 24, 2018

    @vito
    Contributor

    Just ran into this today. Go's pretty bad a noticing pkg has outdated bits, and the only recourse is to disable the task cache.

  3. changed the title [-]Unable to delete/clear task caches[/-] [+]Delete/clear task caches[/+] on Jan 24, 2018
  4. alvaropinot commented on Mar 2, 2018

    @alvaropinot

    I think it could also be great to have a "clean cache when build fails" feature that could be setup as part of the yml key, something like:

    caches:
    - path: project-src/node_modules
    - clean_on_error: true # defaults to false

    or even go into a failsafe strategy when a build has failed and clean the cache and retry.

    Any thoughts?

  5. ghostsquad commented on Mar 4, 2018

    @ghostsquad

    CircleCI has actually a really nice way of handling this. They let you name the cache, and thus you can create more and more specific caches.

    https://circleci.com/docs/2.0/caching/

  6. added a commit that references this issue on Apr 11, 2018
  7. vito commented on Jul 24, 2018

    @vito
    Contributor

    Some guidance on this, in case someone wants to submit a PR: I think this just comes down to deleting from the worker_task_caches table.

    fly -t ci clear-task-cache -j my-pipeline/my-job -s step-name [-c path/to/cache]
    

    This could hit an API endpoint like so:

    DELETE /api/v1/teams/my-team/pipelines/my-pipeline/jobs/my-job/tasks/step-name/caches[/path/to/cache]
    

    This would simply translate to:

    DELETE FROM worker_task_caches
    WHERE job_id = $1 -- just get the id corresponding to the name/pipeline, the API will do this for you
    AND step_name = 'step-name'
    AND path = 'path/to/cache'

    The path could be optional, since it could be annoying to have to type that out.

    The net effect of this: existing cache volumes will eventually be garbage collected, as their "owner" (the task cache) will have gone away, leaving them orphaned (all owner references will be NULL). No volumes will be killed while their build is running; there should be other safeguards for that. So I think this is actually really straightforward - just need an API endpoint and fly command!

  8. vito commented on Sep 17, 2018

    @vito
    Contributor

    This was PR'ed in to v4.1.0. Thanks @edtan!

  9. modified the milestones: v4.2.0, v4.1.0 on Sep 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions