blob: ff0448bf5f2fc7e3d730fd30622abeaa0ac02dcd [file] [log] [blame]
Hyunsun Moon03c1e512019-08-25 15:39:51 -05001#
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)
18KUBE_VERSION ?= v1.15.3
19
20DOCKER_TAG ?= ${VERSION}
21DOCKER_REGISTRY ?=
22DOCKER_REPOSITORY ?=
23DOCKER_BUILD_ARGS ?=
24DOCKER_BUILD_TARGET ?= pod-init
25DOCKER_IMAGENAME ?= ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${DOCKER_BUILD_TARGET}:${DOCKER_TAG}
26
27## Docker labels. Only set ref and commit date if committed
28DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
29DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
30DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
31DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
32
33# https://docs.docker.com/engine/reference/commandline/build/#specifying-target-build-stage---target
34docker-build:
35 docker build $(DOCKER_BUILD_ARGS) \
36 --target ${DOCKER_BUILD_TARGET} \
37 --tag ${DOCKER_IMAGENAME} \
38 --build-arg "KUBE_LATEST_VERSION=${KUBE_VERSION}" \
39 --label "org.label-schema.schema-version=1.0" \
40 --label "org.label-schema.name=${DOCKER_BUILD_TARGET}" \
41 --label "org.label-schema.version=${VERSION}" \
42 --label "org.label-schema.vcs-url=${DOCKER_LABEL_VCS_URL}" \
43 --label "org.label-schema.vcs-ref=${DOCKER_LABEL_VCS_REF}" \
44 --label "org.label-schema.build-date=${DOCKER_LABEL_BUILD_DATE}" \
45 --label "org.opencord.vcs-commit-date=${DOCKER_LABEL_COMMIT_DATE}" \
46 .
47
48docker-push:
49 docker push ${DOCKER_IMAGENAME}
50
51test: docker-build
52
53.PHONY: docker-build docker-push test