Created
September 6, 2021 16:41
-
-
Save webartoli/3fe6a4bb7eccb981720fc5dc6921478d to your computer and use it in GitHub Desktop.
Generate deps graph from multistage Dockerfile
This file contains 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
#!/usr/bin/env bash | |
function extract_key_value() { | |
egrep -o "$1[:=]['\"[:alnum:]\-]+" | egrep -o "['\"[:alnum:]\-]+$" | egrep -o "[[:alnum:]\-]+" | |
} | |
function docker_multistage_deps() { | |
cat Dockerfile \ | |
| grep -i 'FROM ' \ | |
| grep -i ' AS ' \ | |
| awk '{print $2 " --> " $4}' | |
} | |
function docker_copy_between_images_deps() { | |
cat Dockerfile \ | |
| grep -i 'from' \ | |
| while read line | |
do | |
if [[ $line == COPY* ]] | |
then | |
source=`echo $line | extract_key_value from` | |
target=`echo $context | awk '{print $4}'` | |
echo "$source -.- $target " | |
fi | |
if [[ $line == FROM* ]] | |
then | |
context=$line | |
fi | |
done | |
} | |
echo '``` mermaid' | |
echo "graph LR" | |
echo "" | |
docker_multistage_deps | |
echo "" | |
docker_copy_between_images_deps | |
echo '```' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment