blob: 586a612140997330178f29eb5e8f340a0f70905c [file] [log] [blame]
Hyunsun Moon5c2b9f22019-07-29 17:37:29 -06001#
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 ?= omec-cni
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 --build-arg org_label_schema_version="${VERSION}" \
38 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
39 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
40 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
41 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
42 .
43
44docker-push:
45 docker push ${DOCKER_IMAGENAME}
46
47test: docker-build
48
49.PHONY: docker-build docker-push test