111 lines
2.3 KiB
Bash
Executable File
111 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Determine if it is Mac OS and switch to use gxargs instead
|
|
CMD=xargs
|
|
if [ $(which system_profiler) ]; then
|
|
CMD=gxargs
|
|
fi
|
|
|
|
# Bring in the variables from SOLUTION file, supporting
|
|
# nested substitution
|
|
. SOLUTION
|
|
. MANIFEST
|
|
|
|
VARS=($(sed -nE "s,(^[^#][^=]*).*$,\1,pg" SOLUTION))
|
|
VARS+=($(sed -nE "s,(^[^#][^=]*).*$,\1,pg" MANIFEST))
|
|
for var in ${VARS[@]}; do
|
|
export ${var}
|
|
done
|
|
|
|
case "${OS_DISTRO}" in
|
|
rhel)
|
|
SOLUTION_SUFFIX=".rhel-8.0"
|
|
;;
|
|
ubuntu)
|
|
SOLUTION_SUFFIX=""
|
|
;;
|
|
*)
|
|
SOLUTION_SUFFIX=".${OS_DISTRO}-${OS_RELEASE}"
|
|
[[ -d "templates/${OS_DISTRO}" ]] || {
|
|
echo "Unrecognized OS_DISTRO: '${OS_DISTRO}'"
|
|
exit -1
|
|
}
|
|
[[ ! -e "Dockerfile.solution.${SOLUTION_SUFFIX}" ]] && {
|
|
SOLUTION_SUFFIX=""
|
|
}
|
|
;;
|
|
esac
|
|
|
|
export DOCKERFILE="Dockerfile${SOLUTION_SUFFIX}"
|
|
export SOLUTION="Dockerfile.solution${SOLUTION_SUFFIX}"
|
|
VARS+=("DOCKERFILE")
|
|
VARS+=("SOLUTION")
|
|
|
|
echo "Using '${SOLUTION}' to generate '${DOCKERFILE}'."
|
|
|
|
# Build a SHELL-FORMAT value to pass to envsubst.
|
|
# Only those variables matched in SHELL-FORMAT will
|
|
# be escaped by envsubst.
|
|
ENV=''
|
|
for var in ${VARS[@]}; do
|
|
ENV=${ENV}'$'${var}
|
|
done
|
|
|
|
# Remove the Dockerfile if it exists; should check
|
|
# if it is clean first, and abort if not.
|
|
#
|
|
[ -e ${DOCKERFILE} ] && rm ${DOCKERFILE}
|
|
|
|
cat << EOM > ${DOCKERFILE}
|
|
#
|
|
# DO NOT EDIT THIS DOCKERFILE
|
|
#
|
|
# This file is auto-generated via scripts/build-dockerfile
|
|
# by using environment substitution while concatenating the
|
|
# contents of templates/*, and then adding the contents
|
|
# of ${SOLUTION}
|
|
#
|
|
# Most solution specific changes should be isolated in
|
|
# ${SOLUTION}. After making changes, you can then re-run
|
|
# scripts/build-dockerfile
|
|
#
|
|
EOM
|
|
|
|
for snippet in templates/${OS_DISTRO}/??-*.in; do
|
|
cat << EOM >> ${DOCKERFILE}
|
|
|
|
#
|
|
# Template from ${snippet}
|
|
#
|
|
EOM
|
|
envsubst ${ENV} < $snippet >> ${DOCKERFILE}
|
|
done
|
|
|
|
cat << EOM >> ${DOCKERFILE}
|
|
|
|
#
|
|
# Solution begins here (from ${SOLUTION})
|
|
#
|
|
EOM
|
|
|
|
envsubst ${ENV} < ${SOLUTION} >> ${DOCKERFILE}
|
|
|
|
cat << EOM >> ${DOCKERFILE}
|
|
|
|
#
|
|
# Standard ending begins here (from templates/ending.in)
|
|
#
|
|
EOM
|
|
|
|
envsubst ${ENV} < templates/ending.in >> ${DOCKERFILE}
|
|
|
|
cat << EOM
|
|
|
|
${DOCKERFILE} has been updated.
|
|
|
|
To build the image, you can run:
|
|
|
|
OS_DISTRO=${OS_DISTRO} OS_RELEASE=${OS_RELEASE} scripts/build-image.sh
|
|
|
|
EOM
|