blob: 31d91379a90df910060f8650dfdc4960d61a7692 [file] [log] [blame]
Matt Jeanneretbd71d6e2019-10-23 12:02:30 -04001#
2# Copyright 2018 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17# set default shell
18SHELL = bash -e -o pipefail
19
20# Variables
21VERSION ?= $(shell cat VERSION)
22
23## Docker related
24DOCKER_REGISTRY ?=
25DOCKER_REPOSITORY ?=
26DOCKER_BUILD_ARGS ?=
27DOCKER_TAG ?= ${VERSION}
28IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-python-base:${DOCKER_TAG}
29
30## Docker labels. Only set ref and commit date if committed
31DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
32DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
33DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
34
35ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
36 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
37else
38 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
39endif
40
41.PHONY: docker-build
42
43# This should to be the first and default target in this Makefile
44help:
45 @echo "Usage: make [<target>]"
46 @echo "where available targets are:"
47 @echo
48 @echo "docker-build : Build the ubuntu python base docker image"
49 @echo "help : Print this help"
50 @echo "docker-push : Push the docker images to an external repository"
51 @echo
52
53
54## Docker targets
55
56build: docker-build
57
58# only test is that the docker container builds
59test: docker-build
60
61docker-build:
62 docker build $(DOCKER_BUILD_ARGS) \
63 -t ${IMAGENAME} \
64 --build-arg org_label_schema_version="${VERSION}" \
65 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
66 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
67 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
68 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
69 -f Dockerfile .
70
71docker-push:
72 docker push ${IMAGENAME}
73
74# end file