GoogleContainerTools / kaniko

Build Container Images In Kubernetes
Apache License 2.0
14.85k stars 1.44k forks source link

docker history missing LABELs #1137

Open ewah opened 4 years ago

ewah commented 4 years ago

Actual behavior building a simple Dockerfile

FROM alpine:latest

COPY a /a
LABEL testLabel="testLabel"
COPY b /b
COPY c /c

/kaniko/executor --dockerfile=./Dockerfile --destination=mydockerhub/ed/ed-test:200316-a

INFO[0000] Resolved base name alpine:latest to alpine:latest
INFO[0000] Resolved base name alpine:latest to alpine:latest
INFO[0000] Retrieving image manifest alpine:latest
INFO[0000] Retrieving image manifest alpine:latest
INFO[0000] Built cross stage deps: map[]
INFO[0000] Retrieving image manifest alpine:latest
INFO[0001] Retrieving image manifest alpine:latest
INFO[0001] Unpacking rootfs as cmd COPY a /a requires it.
INFO[0001] Taking snapshot of full filesystem...
INFO[0002] Resolving paths
INFO[0002] COPY a /a
INFO[0002] Resolving paths
INFO[0002] Taking snapshot of files...
INFO[0002] LABEL testLabel="testLabel"
INFO[0002] Applying label testLabel=testLabel
INFO[0002] COPY b /b
INFO[0002] Resolving paths
INFO[0002] Taking snapshot of files...
INFO[0002] COPY c /c
INFO[0002] Resolving paths
INFO[0002] Taking snapshot of files...

After pulling the image. It does show up in docker inspect mydockerhub/ed/ed-test:200316-a

...
            "Labels": {
                "testLabel": "testLabel"
            }
...

but missing in docker history --no-trunc mydockerhub/ed/ed-test:200316-a

IMAGE                                                                     CREATED             CREATED BY                                                                                          SIZE                COMMENT
sha256:e27663c026af13a6a71c79c383488136ab0f598c4d1fa5e409ea31be159a2a8f   292 years ago       COPY c /c                                                                                           9B
<missing>                                                                 292 years ago       COPY b /b                                                                                           9B
<missing>                                                                 292 years ago       COPY a /a                                                                                           8B
<missing>                                                                 8 weeks ago         /bin/sh -c #(nop)  CMD ["/bin/sh"]                                                                  0B
<missing>                                                                 8 weeks ago         /bin/sh -c #(nop) ADD file:e69d441d729412d24675dcd33e04580885df99981cec43de8c9b24015313ff8e in /    5.59MB

Expected behavior

sha256:d7fcb3531dab3234e81045c6dd2b525a50d5a63164a2b9010c7810ab65294cfb   4 weeks ago         /bin/sh -c #(nop)  LABEL testLabel=testLabel

To Reproduce see actual

Additional Information

tejal29 commented 4 years ago

Thanks @ewah for your issue. I compared what docker build does for the similar docker file.

FROM alpine:latest

COPY foo /foo
LABEL testLabel="testLabel"
COPY bar /bar

I do see a difference. Kaniko produces

tejaldesai@tejaldesai-macbookpro2 skaffold (prototype)docker history --no-trunc gcr.io/tejal-test/test-labels-16
IMAGE                                                                     CREATED             CREATED BY                                                                                          SIZE                COMMENT
sha256:681fad1585ab9d7a69e6f88cf551c6d13e9022dfe9fd47e389a9b43afeba3cbc   292 years ago       COPY bar /bar                                                                                       0B                  
<missing>                                                                 292 years ago       COPY foo /foo                                                                                       0B                  
<missing>                                                                 2 months ago        /bin/sh -c #(nop)  CMD ["/bin/sh"]                                                                  0B                  
<missing>                                                                 2 months ago        /bin/sh -c #(nop) ADD file:e69d441d729412d24675dcd33e04580885df99981cec43de8c9b24015313ff8e in /    5.59MB          

while docker produces the following

tejaldesai@@integration (master)$ docker history --no-trunc e08ae701ae06
IMAGE                                                                     CREATED             CREATED BY                                                                                              SIZE                COMMENT
sha256:e08ae701ae06988b0564cc50fef6e87abd0da76d7fc2b9b63aff4a9411dec37f   59 seconds ago      /bin/sh -c #(nop) COPY file:6b373114d678c9051faa1bf642bf298f63a7730b31bb3001016ebb86d8db8285 in /bar    0B                  
sha256:ed62b3bea3f5265db49c1e2609671dae5c882c8c28412be80248778d04ee2816   59 seconds ago      /bin/sh -c #(nop)  LABEL testLabel=testLabel                                                            0B                  
sha256:e16e4d5b10ca92a6c99dbca7952e466eb5143c56930cb51881fef79788e9840b   59 seconds ago      /bin/sh -c #(nop) COPY file:b72edb7d498ddd91e5c5116e4ce7a1eade15cdce38ca4f75b01ddff7c55f7e79 in /foo    0B                  
sha256:e7d92cdc71feacf90708cb59182d0df1b911f8ae022d29e8e95d75ca6a99776a   2 months ago        /bin/sh -c #(nop)  CMD ["/bin/sh"]                                                                      0B                  
<missing>                                                                 2 months ago        /bin/sh -c #(nop) ADD file:e69d441d729412d24675dcd33e04580885df99981cec43de8c9b24015313ff8e in /        5.59MB         
bitsofinfo commented 4 years ago

experiencing the same issue (0.18.0)

martint17r commented 4 years ago

I looked into this issue and I think this is a WONTFIX because the OCI spec applies labels only for the image as a whole and not for the individual history steps.

The only thing to be fixed is the missing created property with the individual steps, but that has to be applied at the go-containerregistry as far as I understand the source correctly.

If I misunderstood the issue I would be happy to fix this here - please provide pointers.

mrsrvman commented 1 year ago

I looked into this issue and I think this is a WONTFIX because the OCI spec applies labels only for the image as a whole and not for the individual history steps.

The only thing to be fixed is the missing created property with the individual steps, but that has to be applied at the go-containerregistry as far as I understand the source correctly.

If I misunderstood the issue I would be happy to fix this here - please provide pointers.

Judging by the specification, kaniko violates the definition of the "history" array with the field "empty_layer" . https://github.com/opencontainers/image-spec/blob/main/config.md#example