blob: a7e8a7be793344d56bca66d61a394210db0e478c [file] [log] [blame]
Hung-Wei Chiufadfe8b2021-07-22 13:41:28 -07001#
2# Copyright 2019-present Open Networking Foundation
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
17VERSION ?= $(shell cat ./VERSION)
18
19DOCKER_TAG ?= ${VERSION}
20DOCKER_REGISTRY ?=
21DOCKER_REPOSITORY ?=
22DOCKER_BUILD_ARGS ?=
23DOCKER_BUILD_TARGET ?= onos-classic-helm-utils
24DOCKER_IMAGENAME ?= ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${DOCKER_BUILD_TARGET}:${DOCKER_TAG}
25
26## Docker labels. Only set ref and commit date if committed
27DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
28DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
29DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
30DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
31
32# https://docs.docker.com/engine/reference/commandline/build/#specifying-target-build-stage---target
33docker-build:
34 docker build $(DOCKER_BUILD_ARGS) \
35 --target ${DOCKER_BUILD_TARGET} \
36 --tag ${DOCKER_IMAGENAME} \
37 --label "org.label-schema.schema-version=1.0" \
38 --label "org.label-schema.name=${DOCKER_BUILD_TARGET}" \
39 --label "org.label-schema.version=${VERSION}" \
40 --label "org.label-schema.vcs-url=${DOCKER_LABEL_VCS_URL}" \
41 --label "org.label-schema.vcs-ref=${DOCKER_LABEL_VCS_REF}" \
42 --label "org.label-schema.build-date=${DOCKER_LABEL_BUILD_DATE}" \
43 --label "org.opencord.vcs-commit-date=${DOCKER_LABEL_COMMIT_DATE}" \
44 .
45
46docker-push:
47 docker push ${DOCKER_IMAGENAME}
48
49test: docker-build
50
51.PHONY: docker-build docker-push test