make-dimage.sh 1.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!  /bin/bash

###
#
# Create a docker image that includes dependencies for building ngraph
#
# Uses CONTEXTDIR as the docker build context directory
#   Default value is '.'
#
# Uses ./Dockerfile.${DOCKER_TAG}
#   DOCKER_TAG is set to 'ngraph' if not set 
#
# Sets the docker image name as ${DOCKER_IMAGE_NAME}
#   DOCKER_IMAGE_NAME is set to the ${DOCKER_TAG} if not set in the environment
#   The datestamp tag is automatically appended to the DOCKER_IMAGE_NAME to create the DIMAGE_ID
#   The ${DIMAGE_ID} docker image is created on the local server
#   The ${DOCKER_IMAGE_NAME}:latest tag is also created by default for reference
#
###

set -e
#set -u
set -o pipefail

25
if [ -z $DOCKER_TAG ]; then
26 27 28
    DOCKER_TAG=build_ngraph
fi

29
if [ -z $DOCKER_IMAGE_NAME ]; then
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    DOCKER_IMAGE_NAME=${DOCKER_TAG}
fi

echo "CONTEXTDIR=${CONTEXTDIR}"

if [ -z ${CONTEXTDIR} ]; then
    CONTEXTDIR='.'  # Docker image build context
fi

echo "CONTEXTDIR=${CONTEXTDIR}"

if [ -n $DFILE ]; then
    DFILE="${CONTEXTDIR}/Dockerfile.${DOCKER_TAG}"
fi

CONTEXT='.'

DIMAGE_NAME="${DOCKER_IMAGE_NAME}"
DIMAGE_VERSION=`date -Iseconds | sed -e 's/:/-/g'`

DIMAGE_ID="${DIMAGE_NAME}:${DIMAGE_VERSION}"

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
# If proxy settings are detected in the environment, make sure they are
# included on the docker-build command-line.  This mirrors a similar system
# in the Makefile.

if [ ! -z "${http_proxy}" ] ; then
    DOCKER_HTTP_PROXY="--build-arg http_proxy=${http_proxy}"
else
    DOCKER_HTTP_PROXY=' '
fi

if [ ! -z "${https_proxy}" ] ; then
    DOCKER_HTTPS_PROXY="--build-arg https_proxy=${https_proxy}"
else
    DOCKER_HTTPS_PROXY=' '
fi

68 69 70 71 72 73 74 75
cd ${CONTEXTDIR}

echo ' '
echo "Building docker image ${DIMAGE_ID} from Dockerfile ${DFILE}, context ${CONTEXT}"
echo ' '

# build the docker base image
docker build  --rm=true \
76
       ${DOCKER_HTTP_PROXY} ${DOCKER_HTTPS_PROXY} \
77 78 79 80 81 82 83 84 85
       -f="${DFILE}" \
       -t="${DIMAGE_ID}" \
       ${CONTEXT}

docker tag  "${DIMAGE_ID}"  "${DIMAGE_NAME}:latest"

echo ' '
echo 'Docker image build completed'
echo ' '