pierventre | 2c7a4db | 2020-06-26 21:24:00 +0200 | [diff] [blame^] | 1 | # |
| 2 | # Copyright 2020-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 | # set default shell |
| 18 | SHELL := /bin/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 | |
| 29 | # Docker labels. Only set ref and commit date if committed |
| 30 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 31 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 32 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
| 33 | |
| 34 | ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 35 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
| 36 | else |
| 37 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty |
| 38 | endif |
| 39 | |
| 40 | # TOST related |
| 41 | ONOS_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}tost-onos:${DOCKER_TAG} |
| 42 | ONOS_BRANCH ?= |
| 43 | ONOS_REVIEW ?= |
| 44 | ONOS_ROOT := $(shell pwd)/onos |
| 45 | ONOS_PROFILE := "tost" |
| 46 | |
| 47 | .PHONY: docker-build |
| 48 | |
| 49 | # This should to be the first and default target in this Makefile |
| 50 | help: ## : Print this help |
| 51 | @echo "Usage: make [<target>]" |
| 52 | @echo "where available targets are:" |
| 53 | @echo |
| 54 | @grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \ |
| 55 | | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};' |
| 56 | @echo |
| 57 | @echo "Environment variables:" |
| 58 | @echo "ONOS_BRANCH : Use the following branch to build the image" |
| 59 | @echo "ONOS_REVIEW : Use the following review to build the image" |
| 60 | @echo "" |
| 61 | @echo "'onos' clones onos if does not exist in the workspace." |
| 62 | @echo "Uses current workspace unless above vars are defined." |
| 63 | @echo "" |
| 64 | |
| 65 | ## Make targets |
| 66 | |
| 67 | onos: ## : Checkout onos code |
| 68 | # Clone onos if it does not exist |
| 69 | if [ ! -d "onos" ]; then \ |
| 70 | git clone https://gerrit.onosproject.org/onos; \ |
| 71 | fi |
| 72 | # Both are not supported |
| 73 | ifdef ONOS_BRANCH |
| 74 | ifdef ONOS_REVIEW |
| 75 | @echo "Too many parameters. You cannot specify branch and review." |
| 76 | exit 1 |
| 77 | else |
| 78 | cd ${ONOS_ROOT} && git checkout ${ONOS_BRANCH} |
| 79 | endif |
| 80 | else |
| 81 | ifdef ONOS_REVIEW |
| 82 | cd ${ONOS_ROOT} && git review -d ${ONOS_REVIEW} |
| 83 | endif |
| 84 | endif |
| 85 | |
| 86 | onos-build: onos ## : Build the tost-onos docker image |
| 87 | # Set some env variables |
| 88 | cd ${ONOS_ROOT} && \ |
| 89 | . tools/build/envDefaults && \ |
| 90 | docker build . -t ${ONOS_IMAGENAME} \ |
| 91 | --build-arg PROFILE=${ONOS_PROFILE} |
| 92 | |
| 93 | onos-push: ## : Push the tost-onos docker image to an external repository |
| 94 | docker push ${ONOS_IMAGENAME} |
| 95 | |
| 96 | tost-build: ## : Build the tost docker image |
| 97 | # TBD |
| 98 | |
| 99 | tost-push: ## : Push the tost-onos docker image to an external repository |
| 100 | # TBD |
| 101 | |
| 102 | # Used for jenkins verification |
| 103 | docker-build: onos-build tost-build ## : Builds the tost-onos and tost images |
| 104 | |
| 105 | clean: ## : Delete any locally copied files or artificats |
| 106 | rm -rf onos |
| 107 | |
| 108 | # end file |