Hyunsun Moon | 03c1e51 | 2019-08-25 15:39:51 -0500 | [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 | KUBE_VERSION ?= v1.15.3 |
| 19 | |
| 20 | DOCKER_TAG ?= ${VERSION} |
| 21 | DOCKER_REGISTRY ?= |
| 22 | DOCKER_REPOSITORY ?= |
| 23 | DOCKER_BUILD_ARGS ?= |
| 24 | DOCKER_BUILD_TARGET ?= pod-init |
| 25 | DOCKER_IMAGENAME ?= ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${DOCKER_BUILD_TARGET}:${DOCKER_TAG} |
| 26 | |
| 27 | ## Docker labels. Only set ref and commit date if committed |
| 28 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 29 | DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown") |
| 30 | DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" ) |
| 31 | DOCKER_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 |
| 34 | docker-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 | |
| 48 | docker-push: |
| 49 | docker push ${DOCKER_IMAGENAME} |
| 50 | |
| 51 | test: docker-build |
| 52 | |
| 53 | .PHONY: docker-build docker-push test |