blob: c7b540635490223c7f6a15bf68c8ebe2fb86dc2e [file] [log] [blame]
pierventre2c7a4db2020-06-26 21:24:00 +02001#
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
18SHELL := /bin/bash -e -o pipefail
19
20# Variables
21VERSION ?= $(shell cat ./VERSION)
22
23# Docker related
24DOCKER_REGISTRY ?=
25DOCKER_REPOSITORY ?=
26DOCKER_BUILD_ARGS ?=
27DOCKER_TAG ?= ${VERSION}
28
29# Docker labels. Only set ref and commit date if committed
30DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
31DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
32DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
33
34ifeq ($(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)
36else
37 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
38endif
39
40# TOST related
41ONOS_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}tost-onos:${DOCKER_TAG}
42ONOS_BRANCH ?=
43ONOS_REVIEW ?=
44ONOS_ROOT := $(shell pwd)/onos
45ONOS_PROFILE := "tost"
46
47.PHONY: docker-build
48
49# This should to be the first and default target in this Makefile
50help: ## : 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
67onos: ## : 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
73ifdef ONOS_BRANCH
74ifdef ONOS_REVIEW
75 @echo "Too many parameters. You cannot specify branch and review."
76 exit 1
77else
78 cd ${ONOS_ROOT} && git checkout ${ONOS_BRANCH}
79endif
80else
81ifdef ONOS_REVIEW
82 cd ${ONOS_ROOT} && git review -d ${ONOS_REVIEW}
83endif
84endif
85
86onos-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
93onos-push: ## : Push the tost-onos docker image to an external repository
94 docker push ${ONOS_IMAGENAME}
95
96tost-build: ## : Build the tost docker image
97 # TBD
98
99tost-push: ## : Push the tost-onos docker image to an external repository
100 # TBD
101
102# Used for jenkins verification
103docker-build: onos-build tost-build ## : Builds the tost-onos and tost images
104
105clean: ## : Delete any locally copied files or artificats
106 rm -rf onos
107
108# end file