Commit 9a28c4bb authored by Marian Heil's avatar Marian Heil

Script to combine different dockers together

parent daa7bf27
FROM TEMPLATE_BASE AS base
LABEL name "TEMPLATE_NAME"
# Add other images
#IMAGES
# Build docker
FROM base AS builder
WORKDIR TEMPLATE_BASEDIR
# setup environment file
RUN printf "#! /usr/bin/env bash\n" > HEJ_env.sh
#SOURCE
FROM base
COPY --from=builder TEMPLATE_BASEDIR/HEJ_env.sh TEMPLATE_BASEDIR/HEJ_env.sh
#! /usr/bin/env bash
export HEPSW_HOME="/cvmfs/pheno.egi.eu/HEJ"
image_name(){
# created docker image name
echo "maheil/"${1,,}":gcc9_ubuntu"
}
TARGET_NAME="${1}"
SOURCE_IMAGES=(${@:2})
if [[ ${#SOURCE_IMAGES[@]} -lt 2 ]]; then
>&2 echo "Usage: ${0} target source1 source2 [...]"
exit 1
fi
# setting up variables
source ../install/config
TARGET_IMAGE=$(image_name ${TARGET_NAME})
TARGET_DOCKER=Docker_${TARGET_NAME}
TARGET_PREFIX=${TARGET_NAME^^}_PREFIX
echo "Setting up \"${TARGET}\" from \"${SOURCE_IMAGES[@]}\""
mkdir -p build
cd build
cp ../Docker_template ${TARGET_DOCKER}
# setup target
sed -i -e "s TEMPLATE_PREFIX ${TARGET_PREFIX} g" ${TARGET_DOCKER} | exit 2
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
base_docker=$(image_name "compiler")
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
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
done
echo "- Success! To build the docker run:
docker build -t ${TARGET_IMAGE} -f build/${TARGET_DOCKER} ."
exit 0
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