Commit 1b06230f authored by Marian Heil's avatar Marian Heil

Allow setting the base docker for combination

parent cf68baaf
......@@ -9,7 +9,6 @@ FROM base AS builder
WORKDIR TEMPLATE_BASEDIR
# setup environment file
RUN printf "#! /usr/bin/env bash\n" > HEJ_env.sh
#SOURCE
FROM base
......
......@@ -4,14 +4,15 @@ export HEPSW_HOME="/cvmfs/pheno.egi.eu/HEJ"
image_name(){
# created docker image name
echo "maheil/"${1,,}":gcc9_ubuntu"
echo "maheil/"${1,,}":latest"
}
TARGET_NAME="${1}"
SOURCE_IMAGES=(${@:2})
BASE_NAME="${2}"
SOURCE_IMAGES=(${@:3})
if [[ ${#SOURCE_IMAGES[@]} -lt 2 ]]; then
>&2 echo "Usage: ${0} target source1 source2 [...]"
if [[ ${#SOURCE_IMAGES[@]} -lt 1 ]]; then
>&2 echo "Usage: ${0} target base source1 source2 [...]"
exit 1
fi
......@@ -22,7 +23,7 @@ TARGET_IMAGE=$(image_name ${TARGET_NAME})
TARGET_DOCKER=Docker_${TARGET_NAME}
TARGET_PREFIX=${TARGET_NAME^^}_PREFIX
echo "Setting up \"${TARGET}\" from \"${SOURCE_IMAGES[@]}\""
echo "Combining \"${SOURCE_IMAGES[@]}\" in \"${TARGET_NAME}\" based on \"${BASE_NAME}\""
mkdir -p build
cd build
......@@ -34,32 +35,36 @@ sed -i -e "s TEMPLATE_NAME ${TARGET_NAME} g" ${TARGET_DOCKER} | exit 2
sed -i -e "s TEMPLATE_BASEDIR ${HEPSW_HOME} g" ${TARGET_DOCKER} | exit 2
echo "- Installation directory is set to ${HEPSW_HOME}"
# add sources
if [[ ${#SOURCE_IMAGES[@]} -gt 0 ]]; then
base_docker=$(image_name ${SOURCE_IMAGES[0]^^})
else
# set base
if [[ ${BASE_NAME} == "compiler" ]]; then
base_docker=$(image_name "compiler")
sed -i -e "s0#SOURCE0RUN printf \"\#! /usr/bin/env bash\\\n\" > HEJ_env.sh\n#SOURCE0g" \
${TARGET_DOCKER} | exit 2
else
declare -n dep_dir=HEPSW_${BASE_NAME^^}_DIR
declare -n dep_name=HEPSW_${BASE_NAME^^}_NAME
base_docker=$(image_name ${BASE_NAME})
sed -i -e "s#SOURCE#SOURCE\nRUN printf \"source ${dep_dir}/${dep_name}dependencies.sh\\\n\" >> HEJ_env.sh#g" \
${TARGET_DOCKER} | exit 2
sed -i -e "s#SOURCE#SOURCE\nRUN printf \"source ${dep_dir}/${dep_name}env.sh\\\n\" >> HEJ_env.sh#g" \
${TARGET_DOCKER} | exit 2
fi
echo "- Using \"${base_docker}\" as base docker"
sed -i -e "s TEMPLATE_BASE ${base_docker} g" ${TARGET_DOCKER} | exit 2
for dep in ${SOURCE_IMAGES[@]:1}; do
# add sources
# TODO this is a lazy we don't add the "dependencies of dependencies"
for dep in ${SOURCE_IMAGES[@]}; do
declare -n dep_dir=HEPSW_${dep^^}_DIR
declare -n dep_name=HEPSW_${dep^^}_NAME
dep_docker=$(image_name ${dep_name})
echo "- Adding target \"${dep_docker}\""
sed -i -e "s#IMAGES#IMAGES\nCOPY --from=${dep_docker} ${dep_dir} ${dep_dir}#g" \
${TARGET_DOCKER} | exit 2
done
for dep in ${SOURCE_IMAGES[@]}; do
declare -n dep_dir=HEPSW_${dep^^}_DIR
declare -n dep_name=HEPSW_${dep^^}_NAME
echo "- Sourcing target \"${dep_docker}\""
sed -i -e "s#SOURCE#SOURCE\nRUN printf \"source ${dep_dir}/${dep_name}dependencies.sh\\\n\" >> HEJ_env.sh#g" \
${TARGET_DOCKER} | exit 2
sed -i -e "s#SOURCE#SOURCE\nRUN printf \"source ${dep_dir}/${dep_name}env.sh\\\n\" >> HEJ_env.sh#g" \
${TARGET_DOCKER} | exit 2
sed -i -e "s#IMAGES#IMAGES\nCOPY --from=${dep_docker} ${dep_dir} ${dep_dir}#g" \
${TARGET_DOCKER} | exit 2
done
echo "- Success! To build the docker run:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment