GoogleContainerTools / kaniko

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

Multi stage build: timestamp of artifacts is not preserved #1894

Open yilas opened 2 years ago

yilas commented 2 years ago

Actual behavior I would like to build an image with the multi stage mechanism.

Expected behavior It fails with kaniko but works with docker build.

Suggestion Keep the same timestamp (at least mtime) during the copy of artifacts.

To Reproduce Steps to reproduce the behavior:

  1. Create the following Dockerfile
FROM debian:bullseye-slim as builder

RUN apt update && \
    apt install -yq wget gcc make libpcre3-dev libssl-dev zlib1g-dev
RUN cd /tmp/ && \
    wget https://nginx.org/download/nginx-1.14.2.tar.gz && \
    tar xfz nginx-1.14.2.tar.gz && \
    mv nginx-1.14.2 nginx
RUN cd /tmp/nginx && \
    bash ./configure && \
    make -j $(nproc)

RUN stat $(find /tmp/nginx|grep ngx_http_postpone_filter_module)

FROM debian:bullseye-slim

COPY --from=builder /tmp/nginx /tmp/nginx
RUN apt update && \
    apt install -yq make
RUN stat $(find /tmp/nginx|grep ngx_http_postpone_filter_module)
RUN cd /tmp/nginx && \
    make install
  1. Build the image with docker build : docker build -t test-docker:01 .. The image is built. The timestamp of the files before and after the copy.

* Timestamp after copy

```bash
 ---> Running in ad3a8648e938
  File: /tmp/nginx/src/http/ngx_http_postpone_filter_module.c
  Size: 6662        Blocks: 16         IO Block: 4096   regular file
Device: 62h/98d Inode: 10622334    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1001/ UNKNOWN)   Gid: ( 1001/ UNKNOWN)
Access: 2018-12-04 14:52:24.000000000 +0000
Modify: 2018-12-04 14:52:24.000000000 +0000
Change: 2022-01-26 08:27:04.970331897 +0000
 Birth: 2022-01-26 08:27:04.970331897 +0000

  File: /tmp/nginx/objs/src/http/ngx_http_postpone_filter_module.o
  Size: 84096       Blocks: 168        IO Block: 4096   regular file
Device: 62h/98d Inode: 10622120    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-01-26 08:27:02.000000000 +0000
Modify: 2022-01-26 08:27:02.000000000 +0000
Change: 2022-01-26 08:27:04.934331641 +0000
 Birth: 2022-01-26 08:27:04.934331641 +0000
(...)
         Prerequisite 'src/os/unix/ngx_linux.h' is older than target 'objs/src/core/nginx.o'.
         Prerequisite 'src/core/ngx_regex.h' is older than target 'objs/src/core/nginx.o'.
         Prerequisite 'objs/ngx_auto_config.h' is older than target 'objs/src/core/nginx.o'.
         Prerequisite 'src/core/nginx.c' is older than target 'objs/src/core/nginx.o'.
        No need to remake target 'objs/src/core/nginx.o'
  1. Build the image with kaniko : docker run -v $PWD:/workspace -v ~/.docker/config.json:/kaniko/.docker/config.json:ro gcr.io/kaniko-project/executor:latest --no-push --destination nginx-test-kaniko:01 --context nginx --dockerfile ./Dockerfile
Birth: 2022-01-26 08:27:32.722525622 +0000
INFO[2022-01-26T08:27:41Z] Taking snapshot of full filesystem...        
INFO[2022-01-26T08:27:41Z] No files were changed, appending empty layer to config. No layer added to image. 
INFO[2022-01-26T08:27:41Z] RUN cd /tmp/nginx &&     make install        
INFO[2022-01-26T08:27:41Z] cmd: /bin/sh                                 
INFO[2022-01-26T08:27:41Z] args: [-c cd /tmp/nginx &&     make install] 
INFO[2022-01-26T08:27:41Z] Running: [/bin/sh -c cd /tmp/nginx &&     make install] 
make -f objs/Makefile install
make[1]: Entering directory '/tmp/nginx'
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
    -o objs/src/core/nginx.o \
    src/core/nginx.c
make[1]: Leaving directory '/tmp/nginx'
make[1]: cc: No such file or directory
make[1]: *** [objs/Makefile:361: objs/src/core/nginx.o] Error 127
make: *** [Makefile:11: install] Error 2
error building image: error building stage: failed to execute command: waiting for process to exit: exit status 2
  File: /tmp/nginx/src/http/ngx_http_postpone_filter_module.c
  Size: 6662            Blocks: 16         IO Block: 4096   regular file
Device: 47h/71d Inode: 10880080    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1001/ UNKNOWN)   Gid: ( 1001/ UNKNOWN)
Access: 2022-01-26 08:53:46.388510256 +0000
Modify: 2018-12-04 14:52:24.000000000 +0000
Change: 2022-01-26 08:53:46.100509498 +0000
 Birth: 2022-01-26 08:53:46.100509498 +0000

  File: /tmp/nginx/objs/src/http/ngx_http_postpone_filter_module.o
  Size: 84096           Blocks: 168        IO Block: 4096   regular file
Device: 47h/71d Inode: 10880469    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-01-26 08:53:55.044533043 +0000
Modify: 2022-01-26 08:53:53.648529370 +0000
Change: 2022-01-26 08:53:53.648529370 +0000
 Birth: 2022-01-26 08:53:53.484528939 +0000
  File: /tmp/nginx/src/http/ngx_http_postpone_filter_module.c
  Size: 6662            Blocks: 16         IO Block: 4096   regular file
Device: 47h/71d Inode: 10754492    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-01-26 08:54:22.740605761 +0000
Modify: 2022-01-26 08:54:22.712605687 +0000
Change: 2022-01-26 08:54:22.712605687 +0000
 Birth: 2022-01-26 08:54:22.712605687 +0000

  File: /tmp/nginx/objs/src/http/ngx_http_postpone_filter_module.o
  Size: 84096           Blocks: 168        IO Block: 4096   regular file
Device: 47h/71d Inode: 10754278    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-01-26 08:54:22.736605751 +0000
Modify: 2022-01-26 08:54:22.696605645 +0000
Change: 2022-01-26 08:54:22.696605645 +0000
 Birth: 2022-01-26 08:54:22.696605645 +0000
(...)
         Prerequisite 'src/os/unix/ngx_linux.h' is newer than target 'objs/src/core/nginx.o'.
         Prerequisite 'src/core/ngx_regex.h' is newer than target 'objs/src/core/nginx.o'.
         Prerequisite 'objs/ngx_auto_config.h' is older than target 'objs/src/core/nginx.o'.
         Prerequisite 'src/core/nginx.c' is newer than target 'objs/src/core/nginx.o'.
        Must remake target 'objs/src/core/nginx.o'.

Triage Notes for the Maintainers

Description Yes/No
Please check if this a new feature you are proposing
  • - [X]
Please check if the build works in docker but not in kaniko
  • - [X]
Please check if this error is seen when you use --cache flag
  • - [ ]
Please check if your dockerfile is a multistage dockerfile
  • - [X]
lsunsi commented 1 year ago

I'm getting similar behavior of this on a rust project I'm working on. It rebuilds some stuff unnecessarily due to changing timestamps