Hung-Wei Chiu | fadfe8b | 2021-07-22 13:41:28 -0700 | [diff] [blame^] | 1 | # |
| 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 | |
| 17 | VERSION ?= $(shell cat ./VERSION) |
| 18 | |
| 19 | DOCKER_TAG ?= ${VERSION} |
| 20 | DOCKER_REGISTRY ?= |
| 21 | DOCKER_REPOSITORY ?= |
| 22 | DOCKER_BUILD_ARGS ?= |
| 23 | DOCKER_BUILD_TARGET ?= onos-classic-helm-utils |
| 24 | DOCKER_IMAGENAME ?= ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${DOCKER_BUILD_TARGET}:${DOCKER_TAG} |
| 25 | |
| 26 | ## Docker labels. Only set ref and commit date if committed |
| 27 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 28 | DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown") |
| 29 | DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" ) |
| 30 | DOCKER_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 |
| 33 | docker-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 | |
| 46 | docker-push: |
| 47 | docker push ${DOCKER_IMAGENAME} |
| 48 | |
| 49 | test: docker-build |
| 50 | |
| 51 | .PHONY: docker-build docker-push test |