blob: b08f826d6d1bb2f67ecf4a038fcb2fc18a419d4e [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
pierventre83611422020-08-14 22:53:15 +020018SHELL := /bin/bash -e -o pipefail
pierventre2c7a4db2020-06-26 21:24:00 +020019
pierventre83611422020-08-14 22:53:15 +020020# General variables
21VERSION ?= $(shell cat ./VERSION)
22THIS_MAKE := $(lastword $(MAKEFILE_LIST))
pierventre2c7a4db2020-06-26 21:24:00 +020023
24# Docker related
pierventre83611422020-08-14 22:53:15 +020025DOCKER_REGISTRY ?=
26DOCKER_REPOSITORY ?=
27DOCKER_BUILD_ARGS ?=
28DOCKER_TAG ?= ${VERSION}
pierventre2c7a4db2020-06-26 21:24:00 +020029
30# Docker labels. Only set ref and commit date if committed
pierventre83611422020-08-14 22:53:15 +020031DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
32DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
33DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
pierventre2c7a4db2020-06-26 21:24:00 +020034
35ifeq ($(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)
37else
38 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
39endif
40
pierventre83611422020-08-14 22:53:15 +020041# Includes the default ("working") versions of each component
42include ./Makefile.vars
43
44# Shellcheck related
45SHELLCHECK_TAG=v0.7.1
46SHELLCHECK_IMAGE=koalaman/shellcheck:${SHELLCHECK_TAG}
47
pierventre16709162020-07-16 20:48:24 +020048# ONOS related
pierventred9cb7292020-07-31 00:01:47 +020049ONOS_IMAGENAME := tost-onos
pierventre16709162020-07-16 20:48:24 +020050export ONOS_ROOT := $(shell pwd)/onos
pierventre83611422020-08-14 22:53:15 +020051ONOS_REPO := https://gerrit.onosproject.org/onos
pierventre16709162020-07-16 20:48:24 +020052ONOS_PROFILE := "tost"
53KARAF_VERSION := 4.2.9
pierventre2c7a4db2020-06-26 21:24:00 +020054
pierventre16709162020-07-16 20:48:24 +020055# TOST related
56TOST_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}tost:${DOCKER_TAG}
pierventre83611422020-08-14 22:53:15 +020057export LOCAL_APPS := local-apps
pierventre16709162020-07-16 20:48:24 +020058
59# Trellis-Control related
pierventre83611422020-08-14 22:53:15 +020060export TRELLIS_CONTROL_ROOT := $(shell pwd)/trellis-control
61export TRELLIS_CONTROL_REPO := https://gerrit.onosproject.org/trellis-control
pierventre16709162020-07-16 20:48:24 +020062
63# Trellis-T3 related
pierventre83611422020-08-14 22:53:15 +020064export TRELLIS_T3_ROOT := $(shell pwd)/trellis-t3
65export TRELLIS_T3_REPO := https://gerrit.onosproject.org/trellis-t3
pierventre16709162020-07-16 20:48:24 +020066
67# Fabric-Tofino related
pierventre83611422020-08-14 22:53:15 +020068export FABRIC_TOFINO_ROOT := $(shell pwd)/fabric-tofino
69export FABRIC_TOFINO_REPO := https://gerrit.opencord.org/fabric-tofino
pierventre16709162020-07-16 20:48:24 +020070
71# Up4 related
pierventre16709162020-07-16 20:48:24 +020072OMECPROJECT_API ?=
pierventre83611422020-08-14 22:53:15 +020073export UP4_ROOT := $(shell pwd)/up4
74
pierventre16709162020-07-16 20:48:24 +020075ifeq ($(OMECPROJECT_API),)
pierventre83611422020-08-14 22:53:15 +020076 export UP4_REPO = https://github.com/omec-project/up4.git
pierventre16709162020-07-16 20:48:24 +020077else
pierventre83611422020-08-14 22:53:15 +020078 export UP4_REPO = https://omecproject:${OMECPROJECT_API}@github.com/omec-project/up4.git
pierventre16709162020-07-16 20:48:24 +020079endif
80
81# Kafka-onos related
pierventre83611422020-08-14 22:53:15 +020082export KAFKA_ONOS_ROOT := $(shell pwd)/kafka-onos
83export KAFKA_ONOS_REPO := https://gerrit.opencord.org/kafka-onos
pierventre16709162020-07-16 20:48:24 +020084
pierventref33fc112020-07-30 12:55:54 +020085# Fabric-TNA related
pierventref33fc112020-07-30 12:55:54 +020086ONOS_BUILDER_API ?=
pierventre83611422020-08-14 22:53:15 +020087export FABRIC_TNA_ROOT := $(shell pwd)/fabric-tna
pierventref33fc112020-07-30 12:55:54 +020088
89ifeq ($(ONOS_BUILDER_API),)
pierventre83611422020-08-14 22:53:15 +020090 export FABRIC_TNA_REPO = https://github.com/stratum/fabric-tna.git
pierventref33fc112020-07-30 12:55:54 +020091else
pierventre83611422020-08-14 22:53:15 +020092 export FABRIC_TNA_REPO = https://onos-builder:${ONOS_BUILDER_API}@github.com/stratum/fabric-tna.git
pierventref33fc112020-07-30 12:55:54 +020093endif
94
Jon Hall49981fd2020-08-13 17:24:22 -070095.PHONY: onos trellis-control trellis-t3 fabric-tofino up4 kafka-onos fabric-tna
pierventre16709162020-07-16 20:48:24 +020096
pierventref33fc112020-07-30 12:55:54 +020097.SILENT: up4 fabric-tna
pierventre2c7a4db2020-06-26 21:24:00 +020098
99# This should to be the first and default target in this Makefile
100help: ## : Print this help
101 @echo "Usage: make [<target>]"
102 @echo "where available targets are:"
103 @echo
pierventre83611422020-08-14 22:53:15 +0200104 @grep '^[[:alnum:]_-]*:.* ##' $(THIS_MAKE) \
pierventre2c7a4db2020-06-26 21:24:00 +0200105 | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'
106 @echo
107 @echo "Environment variables:"
pierventre83611422020-08-14 22:53:15 +0200108 @echo "ONOS_VERSION : Override to use a specific branch/commit/tag/release to build the image"
109 @echo "TRELLIS_CONTROL_VERSION : Override to use a specific branch/commit/tag/release to build the image"
110 @echo "TRELLIS_T3_VERSION : Override to use a specific branch/commit/tag/release to build the image"
111 @echo "FABRIC_TOFINO_VERSION : Override to use a specific branch/commit/tag/release to build the image"
112 @echo "UP4_VERSION : Override to use a specific branch/commit/tag/release to build the image"
113 @echo "KAFKA_ONOS_VERSION : Override to use a specific branch/commit/tag/release to build the image"
114 @echo "FABRIC_TNA_VERSION : Override to use a specific branch/commit/tag/release to build the image"
pierventre2c7a4db2020-06-26 21:24:00 +0200115 @echo ""
pierventre83611422020-08-14 22:53:15 +0200116 @echo "'Makefile.vars' defines default values for '*_VERSION' variables".
pierventref33fc112020-07-30 12:55:54 +0200117 @echo ""
pierventre2c7a4db2020-06-26 21:24:00 +0200118
119## Make targets
120
pierventre83611422020-08-14 22:53:15 +0200121check-scripts: ## : Provides warnings and suggestions for bash/sh shell scripts
122 # Fail if any of these files have warnings, exclude sed replacement warnings
123 docker run --rm -v "${PWD}:/mnt" ${SHELLCHECK_IMAGE} *.sh -e SC2001
124
pierventre16709162020-07-16 20:48:24 +0200125mvn_settings.xml: mvn_settings.sh ## : Builds mvn_settings file for proxy
126 @./$<
127
128local-apps: ## : Creates the folder that will host the oar file
129 mkdir -p ${LOCAL_APPS}/
130
131trellis-control: ## : Checkout trellis-control code
132 # Clones trellis-control if it does not exist
133 if [ ! -d "trellis-control" ]; then \
pierventre83611422020-08-14 22:53:15 +0200134 git clone ${TRELLIS_CONTROL_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200135 fi
pierventre83611422020-08-14 22:53:15 +0200136
137 # Pending changes - do not proceed
138 @modified=$$(cd ${TRELLIS_CONTROL_ROOT} && git status --porcelain); \
139 if [ ! -z "$${modified}" ]; then \
140 echo "Unable to checkout, you have pending changes in trellis-control repository"; \
141 exit 1; \
142 fi
143
144 # Try the git checkout first otherwise git review
145 if ! (cd ${TRELLIS_CONTROL_ROOT} && git checkout ${TRELLIS_CONTROL_VERSION}); then \
146 if ! (cd ${TRELLIS_CONTROL_ROOT} && git fetch ${TRELLIS_CONTROL_REPO} ${TRELLIS_CONTROL_VERSION} && git checkout FETCH_HEAD); then \
147 echo "Unable to fetch the changes from the trellis-control repository"; \
148 fi \
149 fi
pierventre16709162020-07-16 20:48:24 +0200150
151trellis-control-build: mvn_settings.xml local-apps trellis-control ## : Builds trellis-control using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200152 @./app-build.sh $@
153
154trellis-control-fetch: ## : downloads commits, files, and refs from remote trellis-control
155 cd ${TRELLIS_CONTROL_ROOT} && git fetch
pierventre16709162020-07-16 20:48:24 +0200156
157trellis-t3: ## : Checkout trellis-t3 code
158 if [ ! -d "trellis-t3" ]; then \
pierventre83611422020-08-14 22:53:15 +0200159 git clone ${TRELLIS_T3_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200160 fi
pierventre83611422020-08-14 22:53:15 +0200161
162 @modified=$$(cd ${TRELLIS_T3_ROOT} && git status --porcelain); \
163 if [ ! -z "$${modified}" ]; then \
164 echo "Unable to checkout, you have pending changes in trellis-t3 repository"; \
165 exit 1; \
166 fi
167
168 if ! (cd ${TRELLIS_T3_ROOT} && git checkout ${TRELLIS_T3_VERSION}); then \
169 if ! (cd ${TRELLIS_T3_ROOT} && git fetch ${TRELLIS_T3_REPO} ${TRELLIS_T3_VERSION} && git checkout FETCH_HEAD); then \
170 echo "Unable to fetch the changes from the trellis-t3 repository"; \
171 fi \
172 fi
pierventre16709162020-07-16 20:48:24 +0200173
174trellis-t3-build: mvn_settings.xml local-apps trellis-t3 ## : Builds trellis-t3 using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200175 @./app-build.sh $@
176
177trellis-t3-fetch: ## : downloads commits, files, and refs from remote trellis-t3
178 cd ${TRELLIS_T3_ROOT} && git fetch
pierventre16709162020-07-16 20:48:24 +0200179
180fabric-tofino: ## : Checkout fabric-tofino code
181 if [ ! -d "fabric-tofino" ]; then \
pierventre83611422020-08-14 22:53:15 +0200182 git clone ${FABRIC_TOFINO_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200183 fi
pierventre83611422020-08-14 22:53:15 +0200184
185 @modified=$$(cd ${FABRIC_TOFINO_ROOT} && git status --porcelain); \
186 if [ ! -z "$${modified}" ]; then \
187 echo "Unable to checkout, you have pending changes in fabric-tofino repository"; \
188 exit 1; \
189 fi
190
191 if ! (cd ${FABRIC_TOFINO_ROOT} && git checkout ${FABRIC_TOFINO_VERSION}); then \
192 if ! (cd ${FABRIC_TOFINO_ROOT} && git fetch ${FABRIC_TOFINO_REPO} ${FABRIC_TOFINO_VERSION} && git checkout FETCH_HEAD); then \
193 echo "Unable to fetch the changes from the fabric-tofino repository"; \
194 exit 1; \
195 fi \
196 fi
pierventre16709162020-07-16 20:48:24 +0200197
198fabric-tofino-build: mvn_settings.xml local-apps fabric-tofino ## : Builds fabric-tofino using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200199 @./app-build.sh $@
200
201fabric-tofino-fetch: ## : downloads commits, files, and refs from remote fabric-tofino
202 cd ${FABRIC_TOFINO_ROOT} && git fetch
pierventre16709162020-07-16 20:48:24 +0200203
204up4: ## : Checkout up4 code
205 if [ ! -d "up4" ]; then \
206 git clone ${UP4_REPO}; \
207 fi
pierventre83611422020-08-14 22:53:15 +0200208
209 @modified=$$(cd ${UP4_ROOT} && git status --porcelain); \
210 if [ ! -z "$${modified}" ]; then \
211 echo "Unable to checkout, you have pending changes in up4 repository"; \
212 exit 1; \
213 fi
214
215 if ! (cd ${UP4_ROOT} && git checkout ${UP4_VERSION}); then \
216 if ! (cd ${UP4_ROOT} && git fetch ${UP4_REPO} ${UP4_VERSION} && git checkout FETCH_HEAD); then \
217 echo "Unable to fetch the changes from the up4 repository"; \
218 exit 1; \
219 fi \
220 fi
pierventre16709162020-07-16 20:48:24 +0200221
pierventref33fc112020-07-30 12:55:54 +0200222up4-build: mvn_settings.xml local-apps up4 ## : Builds up4 using local app
pierventre83611422020-08-14 22:53:15 +0200223 @./app-build.sh $@
224
225up4-fetch: ## : downloads commits, files, and refs from remote up4
226 cd ${UP4_ROOT} && git fetch
pierventre16709162020-07-16 20:48:24 +0200227
228kafka-onos: ## : Checkout kafka-onos code
229 if [ ! -d "kafka-onos" ]; then \
pierventre83611422020-08-14 22:53:15 +0200230 git clone ${KAFKA_ONOS_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200231 fi
pierventre83611422020-08-14 22:53:15 +0200232
233 @modified=$$(cd ${KAFKA_ONOS_ROOT} && git status --porcelain); \
234 if [ ! -z "$${modified}" ]; then \
235 echo "Unable to checkout, you have pending changes in kafka-onos repository"; \
236 exit 1; \
237 fi
238
239 if ! (cd ${KAFKA_ONOS_ROOT} && git checkout ${KAFKA_ONOS_VERSION}); then \
240 if ! (cd ${KAFKA_ONOS_ROOT} && git fetch ${KAFKA_ONOS_REPO} ${KAFKA_ONOS_VERSION} && git checkout FETCH_HEAD); then \
241 echo "Unable to fetch the changes from the kafka-onos repository"; \
242 fi \
243 fi
pierventre16709162020-07-16 20:48:24 +0200244
245kafka-onos-build: mvn_settings.xml local-apps kafka-onos ## : Builds kafka-onos using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200246 @./app-build.sh $@
247
248kafka-onos-fetch: ## : downloads commits, files, and refs from remote kafka-onos
249 cd ${KAFKA_ONOS_ROOT} && git fetch
pierventre16709162020-07-16 20:48:24 +0200250
pierventref33fc112020-07-30 12:55:54 +0200251fabric-tna: ## : Checkout fabric-tna code
252 if [ ! -d "fabric-tna" ]; then \
253 git clone ${FABRIC_TNA_REPO}; \
254 fi
pierventre83611422020-08-14 22:53:15 +0200255
256 @modified=$$(cd ${FABRIC_TNA_ROOT} && git status --porcelain); \
257 if [ ! -z "$${modified}" ]; then \
258 echo "Unable to checkout, you have pending changes in fabric-tna repository"; \
259 exit 1; \
260 fi
261
262 if ! (cd ${FABRIC_TNA_ROOT} && git checkout ${FABRIC_TNA_VERSION}); then \
263 if ! (cd ${FABRIC_TNA_ROOT} && git fetch ${FABRIC_TNA_REPO} ${FABRIC_TNA_VERSION} && git checkout FETCH_HEAD); then \
264 echo "Unable to fetch the changes from the fabric-tna repository"; \
265 exit 1; \
266 fi \
267 fi
pierventref33fc112020-07-30 12:55:54 +0200268
269fabric-tna-build: mvn_settings.xml local-apps fabric-tna ## : Builds fabric-tna using local app
pierventre83611422020-08-14 22:53:15 +0200270 @./app-build.sh $@
271
272fabric-tna-fetch: ## : downloads commits, files, and refs from remote fabric-tna
273 cd ${FABRIC_TNA_ROOT} && git fetch
274
275apps-fetch: trellis-control-fetch trellis-t3-fetch fabric-tofino-fetch up4-fetch kafka-onos-fetch fabric-tna-fetch ## : downloads commits, files, and refs from remotes
276
277apps-build: trellis-control-build trellis-t3-build fabric-tofino-build up4-build kafka-onos-build fabric-tna-build ## : Build the onos apps
pierventref33fc112020-07-30 12:55:54 +0200278
pierventre2c7a4db2020-06-26 21:24:00 +0200279onos: ## : Checkout onos code
pierventre2c7a4db2020-06-26 21:24:00 +0200280 if [ ! -d "onos" ]; then \
281 git clone https://gerrit.onosproject.org/onos; \
282 fi
pierventre2c7a4db2020-06-26 21:24:00 +0200283
pierventre83611422020-08-14 22:53:15 +0200284 @modified=$$(cd ${ONOS_ROOT} && git status --porcelain); \
285 if [ ! -z "$${modified}" ]; then \
286 echo "Unable to checkout, you have pending changes in onos repository"; \
287 exit 1; \
288 fi
289
290 # In case of failure, we do not proceed because we cannot build with mvn
291 if ! (cd ${ONOS_ROOT} && git checkout ${ONOS_VERSION}); then \
292 if ! (cd ${ONOS_ROOT} && git fetch ${ONOS_REPO} ${ONOS_VERSION} && git checkout FETCH_HEAD); then \
293 echo "Unable to fetch the changes from the onos repository"; \
294 exit 1; \
295 fi \
296 fi
pierventred9cb7292020-07-31 00:01:47 +0200297
pierventref03097a2020-07-15 18:49:05 +0200298onos-build: onos ## : Builds the tost-onos docker image
pierventre2c7a4db2020-06-26 21:24:00 +0200299 # Set some env variables
300 cd ${ONOS_ROOT} && \
301 . tools/build/envDefaults && \
302 docker build . -t ${ONOS_IMAGENAME} \
303 --build-arg PROFILE=${ONOS_PROFILE}
304
pierventre16709162020-07-16 20:48:24 +0200305tost-build: ## : Builds the tost docker image
306 docker build $(DOCKER_BUILD_ARGS) \
307 -t ${TOST_IMAGENAME} \
308 --build-arg LOCAL_APPS=${LOCAL_APPS} \
309 --build-arg KARAF_VERSION=${KARAF_VERSION} \
310 --build-arg org_label_schema_version="${VERSION}" \
311 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
312 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
313 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
pierventre83611422020-08-14 22:53:15 +0200314 --build-arg org_onosproject_onos_version="${ONOS_VERSION}"\
315 --build-arg org_onosproject_trellis_control_version="${TRELLIS_CONTROL_VERSION}"\
316 --build-arg org_onosproject_trellis_t3_version="${TRELLIS_T3_VERSION}"\
317 --build-arg org_opencord_fabric_tofino_version="${FABRIC_TOFINO_VERSION}"\
318 --build-arg org_omecproject_up4_version="${UP4_VERSION}"\
319 --build-arg org_opencord_kafka_onos_version="${KAFKA_ONOS_VERSION}"\
320 --build-arg org_stratumproject_fabric_tna_version="${FABRIC_TNA_VERSION}"\
pierventre16709162020-07-16 20:48:24 +0200321 -f Dockerfile.tost .
322
pierventref03097a2020-07-15 18:49:05 +0200323onos-push: ## : Pushes the tost-onos docker image to an external repository
pierventre2c7a4db2020-06-26 21:24:00 +0200324 docker push ${ONOS_IMAGENAME}
325
pierventre16709162020-07-16 20:48:24 +0200326tost-push: ## : Pushes the tost docker image to an external repository
327 docker push ${TOST_IMAGENAME}
pierventre2c7a4db2020-06-26 21:24:00 +0200328
pierventref03097a2020-07-15 18:49:05 +0200329# Used for CI job
pierventre83611422020-08-14 22:53:15 +0200330docker-build: check-scripts onos-build apps-build tost-build ## : Builds the tost image
pierventre2c7a4db2020-06-26 21:24:00 +0200331
pierventref03097a2020-07-15 18:49:05 +0200332# User for CD job
pierventre16709162020-07-16 20:48:24 +0200333docker-push: tost-push ## : Pushes the tost image
pierventref03097a2020-07-15 18:49:05 +0200334
pierventre16709162020-07-16 20:48:24 +0200335clean: ## : Deletes any locally copied files or artifacts
336 rm -rf ${ONOS_ROOT}
337 rm -rf ${TRELLIS_CONTROL_ROOT}
338 rm -rf ${TRELLIS_T3_ROOT}
339 rm -rf ${FABRIC_TOFINO_ROOT}
340 rm -rf ${UP4_ROOT}
341 rm -rf ${KAFKA_ONOS_ROOT}
pierventref33fc112020-07-30 12:55:54 +0200342 rm -rf ${FABRIC_TNA_ROOT}
pierventre16709162020-07-16 20:48:24 +0200343 rm -rf ${LOCAL_APPS}
344 rm -rf .m2
345 rm -rf mvn_settings.xml
pierventre2c7a4db2020-06-26 21:24:00 +0200346
347# end file