Makefile 2.69 KB
Newer Older
1 2 3 4
# Basic Makefile for contrib/docker. This can be expanded later as more targets
# are added.

DIR = $(realpath ../..)
5 6 7
# Use /tmp/ngraph-cpp-test, because we run as the user (and not root)
# /root/ngraph-cpp-test is not used, because /root is not accessible to user
VOLUME = -v ${DIR}:/tmp/ngraph-cpp-test
8 9 10 11 12 13 14
GIT_COMMIT = $(shell git rev-parse HEAD)
BUILD_VERSION = ${GIT_COMMIT}_${PYTHON_VERSION}
BUILD_DIR = ${DIR}/contrib/docker/.build-${BUILD_VERSION}

CALLER_UID := $(shell id -u)
CALLER_GID := $(shell id -g)

15
# Default version is python 2, but can be switched to 3 from command
16 17 18
# line
PYTHON_VERSION = 2

19
.PHONY: clean build_ngraph_cpp_cpu check_cpu shell build_all
20 21 22 23 24

DOCKER_BUILD=docker build --rm=true

ifdef http_proxy
DOCKER_BUILD+=--build-arg http_proxy=$(http_proxy)
25
DOCKER_RUN_ENV+=--env http_proxy=$(http_proxy)
26 27
endif

28
ifdef https_proxy
29
DOCKER_BUILD+=--build-arg https_proxy=$(https_proxy)
30
DOCKER_RUN_ENV+=--env https_proxy=$(https_proxy)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
endif

expand_dockerfile_templates:
	cd ${DIR}/contrib/docker
	mkdir ${BUILD_DIR} || true
	sed -e 's/\(FROM ngraph.*\)/\1:${BUILD_VERSION}/' Dockerfile.ngraph_cpp_cpu > ${BUILD_DIR}/Dockerfile.ngraph_cpp_cpu

clean:
	rm -f ${DIR}/contrib/docker/.build-*/Dockerfile.* || echo "keep going if files are not present"
	rmdir ${DIR}/contrib/docker/.build-* || echo "keep going if directory is not present"

build_ngraph_cpp_cpu: expand_dockerfile_templates
	$(DOCKER_BUILD) -f=${BUILD_DIR}/Dockerfile.ngraph_cpp_cpu --build-arg python_version=${PYTHON_VERSION} -t=ngraph_cpp_cpu:${BUILD_VERSION} ${DIR}
	# remove the tag for the previous latest image
	docker rmi ngraph_cpp_cpu:latest || echo "keep going if docker rmi command fails"
	docker tag `docker images -q ngraph_cpp_cpu:${BUILD_VERSION}` ngraph_cpp_cpu:latest

build_all: build_ngraph_cpp_cpu

50
check_cpu: build_ngraph_cpp_cpu
51 52 53 54 55
	# Make BUILD directory as user
	mkdir -p ${DIR}/BUILD
	chmod ug+rwx ${DIR}/BUILD
	# Need to use /tmp/ngraph-cpp-test/BUILD, because running as user
	# Can't use /root/ngraph-cpp-test/BUILD, because /root not accessible to user
56 57 58 59
	docker run \
	    --rm --user ${CALLER_UID}:${CALLER_GID} \
	    ${DOCKER_RUN_ENV} ${VOLUME} -w /tmp/ngraph-cpp-test/BUILD -t ngraph_cpp_cpu:${BUILD_VERSION} \
	    sh -c "cmake -DCMAKE_CXX_COMPILER=clang++-3.9 -DCMAKE_C_COMPILER=clang-3.9 .. ; env VERBOSE=1 make check"
60 61 62 63 64 65 66 67
	# update the files to be owned by the calling user instead of root, to avoid docker mount problems with file ownership
	docker run --rm ${VOLUME} \
	--env MY_UID=${CALLER_UID} \
	--env MY_GID=${CALLER_GID} \
	--env MY_ROOT_DIR=/root/ngraph-cpp-test \
	-t ngraph_cpp_cpu \
	/tmp/chown_files.sh

68 69 70 71
shell: build_ngraph_cpp_cpu
	docker run --rm ${VOLUME} -it ngraph_cpp_cpu:${BUILD_VERSION} /bin/bash

all: build_ngraph_cpp_cpu