Daniele Moro | c3aa653 | 2019-11-18 16:24:31 -0800 | [diff] [blame] | 1 | # Copyright 2019-present Open Networking Foundation |
| 2 | # |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | |
| 5 | # Configure shell |
| 6 | SHELL = bash -e -o pipefail |
| 7 | |
| 8 | # Variables |
| 9 | VERSION ?= $(shell cat ./VERSION) |
| 10 | CONTAINER_NAME ?= $(notdir $(abspath .)) |
| 11 | |
| 12 | ## Docker related |
| 13 | DOCKER_REGISTRY ?= |
| 14 | DOCKER_REPOSITORY ?= |
| 15 | DOCKER_BUILD_ARGS ?= |
| 16 | DOCKER_TAG ?= ${VERSION} |
| 17 | DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CONTAINER_NAME}:${DOCKER_TAG} |
| 18 | |
| 19 | ## Docker labels. Only set ref and commit date if committed |
| 20 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 21 | DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown") |
| 22 | DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" ) |
| 23 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 24 | |
| 25 | docker-build: |
| 26 | docker build $(DOCKER_BUILD_ARGS) \ |
| 27 | -t ${DOCKER_IMAGENAME} \ |
| 28 | --build-arg org_label_schema_version="${VERSION}" \ |
| 29 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 30 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 31 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 32 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 33 | -f Dockerfile . |
| 34 | |
| 35 | docker-push: |
| 36 | docker push ${DOCKER_IMAGENAME} |
| 37 | |
| 38 | test: docker-build |
| 39 | |
| 40 | clean: |
| 41 | @echo "No cleanup available" |