-
-
Notifications
You must be signed in to change notification settings - Fork 173
Description
Steps To Reproduce
I have a script that needs to run before 10-init-unit.sh
If I label it 9-init-serverkit.sh, it will run after 10-init-unit.sh.
Outcome
What did you expect?
All scripts would run in natural order
What happened instead?
They ran in the order based on the ls output which internally will use strcmp and ascii order. Where 9 > 1. 10 < 9 etc.
Specifically they ran in this order.
root@c99286afb47a:/etc/entrypoint.d# ls -l
total 28
-rwxr-xr-x 1 root root 1597 Oct 17 15:32 0-container-info.sh
-rwxr-xr-x 1 root root 3032 Oct 17 15:32 1-log-output-level.sh
-rwxr-xr-x 1 root root 7946 Oct 17 15:32 10-init-unit.sh
-rwxr-xr-x 1 root root 2004 Oct 15 04:17 2-init-serverkit.sh
-rwxr-xr-x 1 root root 5210 Oct 17 15:32 50-laravel-automations.sh
I expected 2-init-serverkit to run before 10-init-unit.
I checked the code and there is a sort function being applied.
| find /etc/entrypoint.d/ -type f -name '*.sh' | sort -n -t- -k1 | while IFS= read -r f; do |
But it doesn't work how I expected.
root@c99286afb47a:/etc/entrypoint.d# find /etc/entrypoint.d/ -type f -name '*.sh' | sort -n -t- -k1
/etc/entrypoint.d/0-container-info.sh
/etc/entrypoint.d/1-log-output-level.sh
/etc/entrypoint.d/10-init-unit.sh
/etc/entrypoint.d/2-init-serverkit.sh
/etc/entrypoint.d/50-laravel-automations.sh
Note how 2-init-serverkit comes after 10-init-unit.sh I think sort -n -t- -k1 isn't working quite right.
I'm not entirely sure why. If you change to -V then the sorting works better.
root@c99286afb47a:/etc/entrypoint.d# find /etc/entrypoint.d/ -type f -name '*.sh' | sort -V
/etc/entrypoint.d/0-container-info.sh
/etc/entrypoint.d/1-log-output-level.sh
/etc/entrypoint.d/2-init-serverkit.sh
/etc/entrypoint.d/10-init-unit.sh
/etc/entrypoint.d/50-laravel-automations.sh
Affected Docker Images
All that use this script.
Specifically the unit ones and likely all the others too.
Anything else?
A workaround is to rename my script to ensure it comes before the other after the sort is applied.
But it would be good to get it to work with a true human readable sort.
To be fair, I expected sort -n -t- -k1 to work the same as -V but it's not. I don't know why that is.