Skip to content

Instantly share code, notes, and snippets.

@andmoos
Last active October 7, 2015 07:18
Show Gist options
  • Select an option

  • Save andmoos/7e26c1d9b68bb295a838 to your computer and use it in GitHub Desktop.

Select an option

Save andmoos/7e26c1d9b68bb295a838 to your computer and use it in GitHub Desktop.
Small util to build a bunch of docker hierarchical containers
#!/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