Last active
October 7, 2015 07:18
-
-
Save andmoos/7e26c1d9b68bb295a838 to your computer and use it in GitHub Desktop.
Small util to build a bunch of docker hierarchical containers
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 | |
| SCRIPT_ROOT="$( dirname ${0} )" | |
| CONTAINERS_ROOT="${SCRIPT_ROOT}/containers" | |
| DOCKER="${SCRIPT_ROOT}/docker.sh" | |
| function build_leaf() { | |
| ${DOCKER} build -t "${1}" "${CONTAINERS_ROOT}/${1}"; | |
| } | |
| function build_node() { | |
| PARENT_CONTAINER="$( grep -E "FROM\s+" "${1}/Dockerfile" | sed -r "s/^FROM\s+(.+)$/\1/" )"; | |
| if [ "x${PARENT_CONTAINER}" != "x" ] && [ -d "${CONTAINERS_ROOT}/${PARENT_CONTAINER}" ]; | |
| then | |
| build_node "${PARENT_CONTAINER}"; | |
| fi; | |
| build_leaf "${1}"; | |
| } | |
| IFS=$'\n'; | |
| for i in $( find "${CONTAINERS_ROOT}/" -name "Dockerfile" ); | |
| do | |
| CONTAINER="$( sed -e "s:^${CONTAINERS_ROOT}/::" -e "s:/Dockerfile$::" <<< "${i}" )"; | |
| build_node "${CONTAINER}" | |
| done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment