Darkfoe's Blog

File modification times and docker

2024-05-14 1:13am ADT

Interesting little find while working on this blog (that is, the software that runs it to be specific): docker does not preserve the file modification times when copying data over.

So since I wrote each of these posts as markdown files and use the modification time as the date of the post, I had to get creative.

Inside my dockerfile instead of a COPY . .

COPY app.tar.gz .
RUN tar -xzf app.tar.gz && rm app.tar.gz

Then I had to add this into my github workflow

- name: Create tarball to preserve file modification times
    run: tar -czf app.tar.gz *.js dir1 dir2

This still didn't work, so I had to look further. So next thing I tried was adjusting the fetch depth of my checkout action to hopefully preserve the file modification times.

- uses: actions/checkout@v4
    with:
    fetch-depth: 0

And this still does not work. So, I had to backtrack a bit and instead switch to using a line of the markdown to define the time. This so far is working fine, but I'm not sure if I like it. I'll have to see how it goes. Timezones are my current concern since I'll be manually typing them in so it's a little clunky, but at least it's a start.