Matt Jeanneret | c7b437c | 2019-05-13 12:33:08 -0400 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2016 the original author or authors. |
| 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 | # set default shell |
| 18 | SHELL = bash -e -o pipefail |
| 19 | |
| 20 | # Variables |
| 21 | VERSION ?= $(shell cat ./VERSION) |
| 22 | |
| 23 | ## Docker related |
| 24 | DOCKER_REGISTRY ?= |
| 25 | DOCKER_REPOSITORY ?= |
| 26 | DOCKER_BUILD_ARGS ?= |
| 27 | DOCKER_TAG ?= ${VERSION} |
| 28 | ONOS_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-onos:${DOCKER_TAG} |
| 29 | |
| 30 | ## Docker labels. Only set ref and commit date if committed |
| 31 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
Matt Jeanneret | c7b437c | 2019-05-13 12:33:08 -0400 | [diff] [blame] | 32 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
Matt Jeanneret | 805f76e | 2019-05-16 16:18:26 -0400 | [diff] [blame] | 33 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
| 34 | |
| 35 | ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 36 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
| 37 | else |
| 38 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty |
| 39 | endif |
Matt Jeanneret | c7b437c | 2019-05-13 12:33:08 -0400 | [diff] [blame] | 40 | |
| 41 | .PHONY: docker-build |
| 42 | |
| 43 | # This should to be the first and default target in this Makefile |
| 44 | help: |
| 45 | @echo "Usage: make [<target>]" |
| 46 | @echo "where available targets are:" |
| 47 | @echo |
| 48 | @echo "build : Build the onos docker image with olt apps built-in" |
| 49 | @echo "help : Print this help" |
| 50 | @echo "docker-push : Push the docker images to an external repository" |
| 51 | @echo "clean : Delete any locally copied oar files in local_imports" |
| 52 | @echo |
| 53 | |
| 54 | |
| 55 | ## Docker targets |
| 56 | |
| 57 | build: docker-build |
| 58 | |
| 59 | local-onosapps: |
| 60 | mkdir -p local_imports/oar |
| 61 | ifdef LOCAL_ONOSAPPS |
| 62 | ./get-local-oars.sh |
| 63 | endif |
| 64 | |
| 65 | docker-build: local-onosapps |
| 66 | docker build $(DOCKER_BUILD_ARGS) \ |
| 67 | -t ${ONOS_IMAGENAME} \ |
| 68 | --build-arg LOCAL_ONOSAPPS=$(LOCAL_ONOSAPPS) \ |
| 69 | --build-arg org_label_schema_version="${VERSION}" \ |
| 70 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 71 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 72 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 73 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 74 | -f Dockerfile.voltha-onos . |
| 75 | |
| 76 | docker-push: |
| 77 | docker push ${ONOS_IMAGENAME} |
| 78 | |
| 79 | clean: |
| 80 | rm -rf local_imports |
| 81 | |
| 82 | # end file |