GoogleContainerTools / skaffold

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

`inputDigest()` build tagging policy doesn't take `Dockerfile` into account #8226

Open danielgafni opened 1 year ago

danielgafni commented 1 year ago

Expected behavior

Dockerfile should be taken into account when calculating the hash (even when outside the build context).

Actual behavior

The Dockerfile changes don't trigger a rebuild. In my case the Dockerfile is placed outside of the build context and is not included into the image.

Information

apiVersion: skaffold/v3
kind: Config
metadata:
  name: my-name

build:
  tagPolicy:
    inputDigest: {}
  artifacts:
    - image: myImage
      context: context-dir
      docker:
        dockerfile: Dockerfile
  local:
    useBuildkit: true

Steps to reproduce the behavior

Make the following project structure:

.
├── Dockerfile
├── skaffold.yaml
└── context-dir
    └── file.txt
ericzzzzzzz commented 1 year ago

Hi @danielgafni thank you for the feedback, I think it make sense to take Dockerfile into account when computing hash even if the file is not in the build context

nicknovitski commented 1 year ago

It should also include changes to the buildArgs, even if those do not affect the file source dependencies. For example:

# Dockerfile
ARG node_version

FROM node:${node_version}

# ...
# skaffold.yaml
apiVersion: skaffold/v4beta1
kind: Config
metadata:
  name: example
build:
  artifacts:
  - image: example
    docker:
      buildArgs:
        node_version: "18.x.x"
earlybard commented 1 year ago

I've hit this same issue and have resorted to COPYing the Dockerfile to /tmp as the last stage of all of my images to force it to be part of the digest.

I am using inputDigest alongside tryImportMissing: true to remote cache skaffold images from my Docker registry. This has been a lot more reliable than any other method of remote caching for me.