Created
September 30, 2023 10:34
-
-
Save hogelog/6bf24a373c9aaaaed1f7e342e62b857d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e -o pipefail | |
container_ids=$(docker ps --format "{{.ID}}") | |
for container_id in $container_ids; do | |
volumes=$(docker inspect $container_id | jq -c '.[0].Mounts[] | select(.Type=="bind") | {Source: .Source, Destination: .Destination}') | |
for volume in $volumes; do | |
echo "Watch $container_id $volume" | |
src_dir=$(echo $volume | jq -r '.Source') | |
if [ ! -d "$src_dir" ]; then | |
continue | |
fi | |
src_dir=$(readlink -f "$src_dir") | |
dst_dir=$(echo $volume | jq -r '.Destination') | |
fswatch "$src_dir" --event Updated --event Created --latency=10 | while read src_path; do | |
dst_path="${src_path/$src_dir/$dst_dir}" | |
docker exec $container_id touch -c "$dst_path" | |
echo "touch $dst_path" | |
done & | |
done | |
done | |
trap "kill $(jobs -p)" TERM | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment