Push docker image

Change-Id: Ib62fb5220153074b6ade8391b6cf5bcadc931ca0
diff --git a/Makefile b/Makefile
index 3ce37b2..2aca763 100644
--- a/Makefile
+++ b/Makefile
@@ -18,12 +18,28 @@
 endef
 export PROJECT_HELP_MSG
 
-SHELL = /bin/bash
+SHELL = bash -eu -o pipefail
+
+VERSION ?= $(shell cat ./VERSION)
+#CONTAINER_NAME ?= person-detection-app
+CONTAINER_NAME ?= $(notdir $(abspath .))
+
+DOCKER_REGISTRY          ?=
+DOCKER_REPOSITORY        ?=
+DOCKER_BUILD_ARGS        ?= --rm --force-rm
+DOCKER_TAG               ?= ${VERSION}
+DOCKER_IMAGENAME         := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CONTAINER_NAME}:${DOCKER_TAG}
+
+DOCKER_LABEL_VCS_URL     ?= $(shell git remote get-url $(shell git remote))
+DOCKER_LABEL_VCS_REF     ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
+DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
+DOCKER_LABEL_BUILD_DATE  ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
+
 VENV = .venv
 PYTHON = $(VENV)/bin/python3
 PIP = $(VENV)/bin/pip
-IMAGE = person-detection-app
 
+all: test
 
 help:
 	echo "$$PROJECT_HELP_MSG" | less
@@ -39,11 +55,27 @@
 	python3 -m venv $(VENV)
 	$(PIP) install -r requirements.txt
 
-build: $(VENV)
-	docker build -f docker/Dockerfile -t $(IMAGE) .
+docker-build: $(VENV)
+	docker build $(DOCKER_BUILD_ARGS) \
+		-t $(DOCKER_IMAGENAME) \
+		--build-arg org_label_schema_version="${VERSION}" \
+    	--build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
+    	--build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
+    	--build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
+    	--build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
+		-f docker/Dockerfile .
 
-run:
-	docker run -itu root:root --privileged --network host --name $(IMAGE) --rm $(IMAGE)
+docker-push:
+	docker push $(DOCKER_IMAGENAME)
+
+docker-run:
+	docker run \
+		-itu root:root \
+		--privileged \
+		--network host \
+		--name $(CONTAINER_NAME) \
+		--rm \
+		$(DOCKER_IMAGENAME)
 
 run-native-file: $(VENV)
 	. ./bin/person_detection.sh -i ./resources/run.mp4
@@ -57,7 +89,7 @@
 lint:
 	flake8 --exclude=.tox person_detection
 
-test:
+test: docker-build
 
 
 CLEANUP = *.pyc $(VENV)