Dockerfile - need to preserve timestamps of files (COPY, ADD)

I’m running into a problem and didn’t find a solution - searching this forums and google didn’t even showed up my problem - so maybe I’m just not seeing the obvious or this is really an edge case no one else ran into. but first let me explain the root cause:

I’m trying to get SAP hybris running in kubernetes. the hybris build process is quite complex and one part of starting up the actual container is running an ant task to apply the database migrations (ant updatesystem). running ant locally is not problem as it keeps track of build dependencies with the help of file timestamps (Apache Ant - Frequently Asked Questions). however these timestamps get lost/are reset during the image building. I tested COPY and also ADD, both with the same outcome.

that means running the updatesystem task in the container deployed to kubernetes makes ant check for build dependencies and will retrigger a full build run because the timestamps of the files were changed. This is of cause something I need to avoid - the actual build is done in my CI pipeline.

is there an easy way to preserve the timestamps? the actual workaround is done by removing the build dependencies in the build.xml via sed during container startup - but this is somehow hacky and could break with the next hybris release.

just as an info for everyone who stumbles over this problem:
solved this by just removing the intermediate build steps in different containers and just building straight in the final one - this way the files don’t have to be copied into the container.