GoogleContainerTools / skaffold

Easy and Repeatable Kubernetes Development
https://skaffold.dev/
Apache License 2.0
15.02k stars 1.62k forks source link

Custom builder should provide input for hash calculation for caching #4737

Open blaggacao opened 4 years ago

blaggacao commented 4 years ago
Workaround: pass dummy args to the build script that serve to differntiate cache calculation inputs on an otherwise equal custom build config (gotcha: the image name is not taken into account). Or — better — split build instructions into separate files and watch them separatly (with the added benefit that only one image cache is invalidated -as oposed to all images of this file)

That means skaffold retags an image to the other. Consequently the other images gets pulled into the deployment and boom.

blaggacao commented 4 years ago

Clearly the part that's wrong here is:

Checking cache...
...
 - ae-dir/web-server: Found. Tagging
...

After the first build only three cache entries are construed for four images:

       │ File: /home/blaggacao/.skaffold/cache
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ 5af0136c849475289159f6f370b20ed5a51ee65a31ee8406d2229a12810bc1a7:
   2   │   id: sha256:20d02c5b6af09e79f92857c49aa2cef8b7015c78a6520f1bb9da1bd74bf3a1f4
   3   │ 60a43dba56e2ed8b8d3294fbb23601ba50eb070364324f36859983a21da50198:
   4   │   id: sha256:19553c75108c03ec178835cf4edf464193af58453fe01435ecbd48cbcc6ba285
   5   │ 85d39cdf191fd3e9eebb616b0cc485a3e3aff2920fb637e16be165c0043805c5:
   6   │   id: sha256:b3b2a891f7bab54c5c41dd8dd6b1f6fdeff55af67081bc342c0b7acba12a48be

Hence, the problem seems building the cache references, probably calculating the hashes.


Looks like the artifact config is relevant

    - image: ae-dir/web-server
      context: images/aedir-ui
      custom:
        buildCommand: skaffold-nix-builder
        dependencies:
          paths:
            - ./*.nix
    - image: ae-dir/web2ldap
      context: images/aedir-ui
      custom:
        buildCommand: skaffold-nix-builder
        dependencies:
          paths:
            - ./*.nix

So it looks like the input missed out by the hashing function is -A "images.$repo" - which is a nix equivalent for buildkit's --target. Somewhere around here: https://github.com/GoogleContainerTools/skaffold/blob/46529503e1e8e754644895ccd06bd6aea8cbc128/pkg/skaffold/build/cache/hash.go#L115-L117 and here https://github.com/GoogleContainerTools/skaffold/blob/dd9fbdbdb559db67c7dc66bf33b781d22b5bae46/pkg/skaffold/schema/v2alpha2/config.go#L711-L716


Workarorund: pass a dummy argument to the build command

      context: images/aedir-ui
      custom:
        buildCommand: skaffold-nix-builder web-server
        dependencies:
          paths:
            - ./*.nix
    - image: ae-dir/web2ldap
      context: images/aedir-ui
      custom:
        buildCommand: skaffold-nix-builder web2ldap
        dependencies:
          paths:
            - ./*.nix

Then we get four hashes:

       │ File: /home/blaggacao/.skaffold/cache
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ 5af0136c849475289159f6f370b20ed5a51ee65a31ee8406d2229a12810bc1a7:
   2   │   id: sha256:20d02c5b6af09e79f92857c49aa2cef8b7015c78a6520f1bb9da1bd74bf3a1f4
   3   │ 79ec48e778c1d97942f86a5cbfb649991dacb716c411749e8d686879cc045b8f:
   4   │   id: sha256:19553c75108c03ec178835cf4edf464193af58453fe01435ecbd48cbcc6ba285
   5   │ 85d39cdf191fd3e9eebb616b0cc485a3e3aff2920fb637e16be165c0043805c5:
   6   │   id: sha256:b3b2a891f7bab54c5c41dd8dd6b1f6fdeff55af67081bc342c0b7acba12a48be
   7   │ 935b594a23db76ba2a93a2e1dcd646b708667452aafce4d98b2fe08b280411a8:
   8   │   id: sha256:c4bbb592d9ec914977a6e85995fc83fcad8b0123decf0affe7b409730a5f4d5c

QED

briandealwis commented 4 years ago

This is another need for custom builders, similar to #4624.