seL4 / seL4-CAmkES-L4v-dockerfiles

Dockerfiles defining the dependencies required to build seL4, CAmkES, and L4v.
13 stars 40 forks source link

Recent docker on MacOS does not allow mounting of /etc/localtime #16

Closed micheloosterhof closed 3 years ago

micheloosterhof commented 4 years ago

Instead of mounting the localtime file, pass the TZ variable to Docker. This may work on Linux as well.

                --hostname in-container \
                --rm \
                $(EXTRA_DOCKER_RUN_ARGS) \
                -v $(HOST_DIR):/host:z \
                -v $(DOCKER_VOLUME_HOME):/home/$(shell whoami) \
-               -v /etc/localtime:/etc/localtime:ro \
+                -e TZ=`ls -la /etc/localtime | cut -d/ -f8-9` \
                $(USER_IMG) $(EXEC)

The cut works on my system, but 8-9 is arbitrary, maybe better written in awk as ls -la /etc/localtime | awk -F '/' '{ printf "%s/%s\n", $(NF - 1), $NF }'

LukeMondy commented 4 years ago

Hey, thanks for reporting this! We don't have a lot of OSX computers to test on, so it's nice to get reports.

This is a tough one, since not all Linuxes will follow OSX's behavior with /etc/localtime. For example, while my Debian box shows similar behavior (where /etc/localtime is symlinked to somewhere more descriptive), it is common (I believe) with RedHat to simply copy a timezone in the the /etc/localtime, which would break the awk/cat system. However, I think you're right that using the env TZ variable is better.

I have come up with a very janky solution:

-e TZ="$$( printf Etc/GMT%+d\\n "$$(( -1* $$(echo 0 $$(date +%z) | bc) / 100 ))" )" \

which I believe may work..?

I'd be good to try it on your commandline first:

printf Etc/GMT%+d\\n "$(( -1* $(echo 0 $(date +%z) | bc) / 100 ))"

it should print something like Etc/GMT-10.

I have put it into the Makefile, and it seems to work on my Debian machine.

It's a bit of a hack, relying on the older, but still compatible, versions of timezones. More info here: https://github.com/eggert/tz/blob/master/etcetera The script uses the date program to get the relative difference to GMT (I believe), then parses it through bc to get it to a usable int, then reverses the sign, and divides by 100 :sweat_smile:

Anyway, can you give it a try, and tell me if it works, and if not, what the commandline outputs?

micheloosterhof commented 4 years ago
$ printf Etc/GMT%+d\\n "$(( -1* $(echo 0 $(date +%z) | bc) / 100 ))"
Etc/GMT-8
micheloosterhof commented 4 years ago

This is good, but on changing to or from daylight savings time the docker container will not automatically migrate to this. The impact of this will probably be small.

LukeMondy commented 4 years ago

Sorry for the mega-delay - we have a PR up now, which should fix this issue. Much simpler than the other options I mentioned, so that's a bonus too. Should be merged soon.