blob: b84e83750adadc9e75210e0ea4d99655909dce81 [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
pierventre83611422020-08-14 22:53:15 +020072export UP4_ROOT := $(shell pwd)/up4
pierventre0b6a9c32020-10-02 11:32:54 +020073export UP4_REPO := git@github.com:omec-project/up4.git
pierventre16709162020-07-16 20:48:24 +020074
75# Kafka-onos related
pierventre83611422020-08-14 22:53:15 +020076export KAFKA_ONOS_ROOT := $(shell pwd)/kafka-onos
77export KAFKA_ONOS_REPO := https://gerrit.opencord.org/kafka-onos
pierventre16709162020-07-16 20:48:24 +020078
pierventref33fc112020-07-30 12:55:54 +020079# Fabric-TNA related
pierventre83611422020-08-14 22:53:15 +020080export FABRIC_TNA_ROOT := $(shell pwd)/fabric-tna
pierventre0b6a9c32020-10-02 11:32:54 +020081export FABRIC_TNA_REPO := git@github.com:stratum/fabric-tna.git
pierventref33fc112020-07-30 12:55:54 +020082
Jon Hall49981fd2020-08-13 17:24:22 -070083.PHONY: onos trellis-control trellis-t3 fabric-tofino up4 kafka-onos fabric-tna
pierventre16709162020-07-16 20:48:24 +020084
pierventref33fc112020-07-30 12:55:54 +020085.SILENT: up4 fabric-tna
pierventre2c7a4db2020-06-26 21:24:00 +020086
87# This should to be the first and default target in this Makefile
88help: ## : Print this help
89 @echo "Usage: make [<target>]"
90 @echo "where available targets are:"
91 @echo
pierventre83611422020-08-14 22:53:15 +020092 @grep '^[[:alnum:]_-]*:.* ##' $(THIS_MAKE) \
pierventre2c7a4db2020-06-26 21:24:00 +020093 | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'
94 @echo
95 @echo "Environment variables:"
pierventre83611422020-08-14 22:53:15 +020096 @echo "ONOS_VERSION : Override to use a specific branch/commit/tag/release to build the image"
97 @echo "TRELLIS_CONTROL_VERSION : Override to use a specific branch/commit/tag/release to build the image"
98 @echo "TRELLIS_T3_VERSION : Override to use a specific branch/commit/tag/release to build the image"
99 @echo "FABRIC_TOFINO_VERSION : Override to use a specific branch/commit/tag/release to build the image"
100 @echo "UP4_VERSION : Override to use a specific branch/commit/tag/release to build the image"
101 @echo "KAFKA_ONOS_VERSION : Override to use a specific branch/commit/tag/release to build the image"
102 @echo "FABRIC_TNA_VERSION : Override to use a specific branch/commit/tag/release to build the image"
pierventre2c7a4db2020-06-26 21:24:00 +0200103 @echo ""
pierventre83611422020-08-14 22:53:15 +0200104 @echo "'Makefile.vars' defines default values for '*_VERSION' variables".
pierventref33fc112020-07-30 12:55:54 +0200105 @echo ""
pierventre2c7a4db2020-06-26 21:24:00 +0200106
107## Make targets
108
pierventre83611422020-08-14 22:53:15 +0200109check-scripts: ## : Provides warnings and suggestions for bash/sh shell scripts
110 # Fail if any of these files have warnings, exclude sed replacement warnings
111 docker run --rm -v "${PWD}:/mnt" ${SHELLCHECK_IMAGE} *.sh -e SC2001
112
pierventre16709162020-07-16 20:48:24 +0200113mvn_settings.xml: mvn_settings.sh ## : Builds mvn_settings file for proxy
114 @./$<
115
116local-apps: ## : Creates the folder that will host the oar file
117 mkdir -p ${LOCAL_APPS}/
118
119trellis-control: ## : Checkout trellis-control code
120 # Clones trellis-control if it does not exist
121 if [ ! -d "trellis-control" ]; then \
pierventre83611422020-08-14 22:53:15 +0200122 git clone ${TRELLIS_CONTROL_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200123 fi
pierventre83611422020-08-14 22:53:15 +0200124
125 # Pending changes - do not proceed
126 @modified=$$(cd ${TRELLIS_CONTROL_ROOT} && git status --porcelain); \
127 if [ ! -z "$${modified}" ]; then \
128 echo "Unable to checkout, you have pending changes in trellis-control repository"; \
129 exit 1; \
130 fi
131
pierventre3b5f9f12020-10-22 16:24:34 +0200132 # Updates the repo and avoids any stale branches
133 cd ${TRELLIS_CONTROL_ROOT} && git remote update
134
pierventre0b6a9c32020-10-02 11:32:54 +0200135 # Try the git checkout first otherwise we download the review
pierventre3b5f9f12020-10-22 16:24:34 +0200136 if ! (cd ${TRELLIS_CONTROL_ROOT} && (git checkout origin/${TRELLIS_CONTROL_VERSION} || git checkout ${TRELLIS_CONTROL_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200137 if ! (cd ${TRELLIS_CONTROL_ROOT} && git fetch ${TRELLIS_CONTROL_REPO} ${TRELLIS_CONTROL_VERSION} && git checkout FETCH_HEAD); then \
138 echo "Unable to fetch the changes from the trellis-control repository"; \
139 fi \
140 fi
pierventre16709162020-07-16 20:48:24 +0200141
142trellis-control-build: mvn_settings.xml local-apps trellis-control ## : Builds trellis-control using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200143 @./app-build.sh $@
144
pierventre16709162020-07-16 20:48:24 +0200145trellis-t3: ## : Checkout trellis-t3 code
146 if [ ! -d "trellis-t3" ]; then \
pierventre83611422020-08-14 22:53:15 +0200147 git clone ${TRELLIS_T3_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200148 fi
pierventre83611422020-08-14 22:53:15 +0200149
150 @modified=$$(cd ${TRELLIS_T3_ROOT} && git status --porcelain); \
151 if [ ! -z "$${modified}" ]; then \
152 echo "Unable to checkout, you have pending changes in trellis-t3 repository"; \
153 exit 1; \
154 fi
155
pierventre3b5f9f12020-10-22 16:24:34 +0200156 cd ${TRELLIS_T3_ROOT} && git remote update
157
158 if ! (cd ${TRELLIS_T3_ROOT} && (git checkout origin/${TRELLIS_T3_VERSION} || git checkout ${TRELLIS_T3_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200159 if ! (cd ${TRELLIS_T3_ROOT} && git fetch ${TRELLIS_T3_REPO} ${TRELLIS_T3_VERSION} && git checkout FETCH_HEAD); then \
160 echo "Unable to fetch the changes from the trellis-t3 repository"; \
161 fi \
162 fi
pierventre16709162020-07-16 20:48:24 +0200163
164trellis-t3-build: mvn_settings.xml local-apps trellis-t3 ## : Builds trellis-t3 using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200165 @./app-build.sh $@
166
pierventre16709162020-07-16 20:48:24 +0200167fabric-tofino: ## : Checkout fabric-tofino code
168 if [ ! -d "fabric-tofino" ]; then \
pierventre83611422020-08-14 22:53:15 +0200169 git clone ${FABRIC_TOFINO_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200170 fi
pierventre83611422020-08-14 22:53:15 +0200171
172 @modified=$$(cd ${FABRIC_TOFINO_ROOT} && git status --porcelain); \
173 if [ ! -z "$${modified}" ]; then \
174 echo "Unable to checkout, you have pending changes in fabric-tofino repository"; \
175 exit 1; \
176 fi
177
pierventre3b5f9f12020-10-22 16:24:34 +0200178 cd ${FABRIC_TOFINO_ROOT} && git remote update
179
180 if ! (cd ${FABRIC_TOFINO_ROOT} && (git checkout origin/${FABRIC_TOFINO_VERSION} || git checkout ${FABRIC_TOFINO_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200181 if ! (cd ${FABRIC_TOFINO_ROOT} && git fetch ${FABRIC_TOFINO_REPO} ${FABRIC_TOFINO_VERSION} && git checkout FETCH_HEAD); then \
182 echo "Unable to fetch the changes from the fabric-tofino repository"; \
183 exit 1; \
184 fi \
185 fi
pierventre16709162020-07-16 20:48:24 +0200186
187fabric-tofino-build: mvn_settings.xml local-apps fabric-tofino ## : Builds fabric-tofino using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200188 @./app-build.sh $@
189
pierventre16709162020-07-16 20:48:24 +0200190up4: ## : Checkout up4 code
191 if [ ! -d "up4" ]; then \
192 git clone ${UP4_REPO}; \
193 fi
pierventre83611422020-08-14 22:53:15 +0200194
195 @modified=$$(cd ${UP4_ROOT} && git status --porcelain); \
196 if [ ! -z "$${modified}" ]; then \
197 echo "Unable to checkout, you have pending changes in up4 repository"; \
198 exit 1; \
199 fi
200
pierventre3b5f9f12020-10-22 16:24:34 +0200201 cd ${UP4_ROOT} && git remote update
202
203 if ! (cd ${UP4_ROOT} && (git checkout origin/${UP4_VERSION} || git checkout ${UP4_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200204 if ! (cd ${UP4_ROOT} && git fetch ${UP4_REPO} ${UP4_VERSION} && git checkout FETCH_HEAD); then \
205 echo "Unable to fetch the changes from the up4 repository"; \
206 exit 1; \
207 fi \
208 fi
pierventre16709162020-07-16 20:48:24 +0200209
pierventref33fc112020-07-30 12:55:54 +0200210up4-build: mvn_settings.xml local-apps up4 ## : Builds up4 using local app
pierventre83611422020-08-14 22:53:15 +0200211 @./app-build.sh $@
212
pierventre16709162020-07-16 20:48:24 +0200213kafka-onos: ## : Checkout kafka-onos code
214 if [ ! -d "kafka-onos" ]; then \
pierventre83611422020-08-14 22:53:15 +0200215 git clone ${KAFKA_ONOS_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200216 fi
pierventre83611422020-08-14 22:53:15 +0200217
218 @modified=$$(cd ${KAFKA_ONOS_ROOT} && git status --porcelain); \
219 if [ ! -z "$${modified}" ]; then \
220 echo "Unable to checkout, you have pending changes in kafka-onos repository"; \
221 exit 1; \
222 fi
223
pierventre3b5f9f12020-10-22 16:24:34 +0200224 cd ${KAFKA_ONOS_ROOT} && git remote update
225
226 if ! (cd ${KAFKA_ONOS_ROOT} && (git checkout origin/${KAFKA_ONOS_VERSION} || git checkout ${KAFKA_ONOS_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200227 if ! (cd ${KAFKA_ONOS_ROOT} && git fetch ${KAFKA_ONOS_REPO} ${KAFKA_ONOS_VERSION} && git checkout FETCH_HEAD); then \
228 echo "Unable to fetch the changes from the kafka-onos repository"; \
229 fi \
230 fi
pierventre16709162020-07-16 20:48:24 +0200231
232kafka-onos-build: mvn_settings.xml local-apps kafka-onos ## : Builds kafka-onos using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200233 @./app-build.sh $@
234
pierventref33fc112020-07-30 12:55:54 +0200235fabric-tna: ## : Checkout fabric-tna code
236 if [ ! -d "fabric-tna" ]; then \
237 git clone ${FABRIC_TNA_REPO}; \
238 fi
pierventre83611422020-08-14 22:53:15 +0200239
240 @modified=$$(cd ${FABRIC_TNA_ROOT} && git status --porcelain); \
241 if [ ! -z "$${modified}" ]; then \
242 echo "Unable to checkout, you have pending changes in fabric-tna repository"; \
243 exit 1; \
244 fi
245
pierventre3b5f9f12020-10-22 16:24:34 +0200246 cd ${FABRIC_TNA_ROOT} && git remote update
247
248 if ! (cd ${FABRIC_TNA_ROOT} && (git checkout origin/${FABRIC_TNA_VERSION} || git checkout ${FABRIC_TNA_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200249 if ! (cd ${FABRIC_TNA_ROOT} && git fetch ${FABRIC_TNA_REPO} ${FABRIC_TNA_VERSION} && git checkout FETCH_HEAD); then \
250 echo "Unable to fetch the changes from the fabric-tna repository"; \
251 exit 1; \
252 fi \
253 fi
pierventref33fc112020-07-30 12:55:54 +0200254
255fabric-tna-build: mvn_settings.xml local-apps fabric-tna ## : Builds fabric-tna using local app
pierventre83611422020-08-14 22:53:15 +0200256 @./app-build.sh $@
257
pierventre3b5f9f12020-10-22 16:24:34 +0200258apps: trellis-control trellis-t3 fabric-tofino up4 kafka-onos fabric-tna ## : downloads commits, files, and refs from remotes
pierventre83611422020-08-14 22:53:15 +0200259
260apps-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 +0200261
pierventre2c7a4db2020-06-26 21:24:00 +0200262onos: ## : Checkout onos code
pierventre2c7a4db2020-06-26 21:24:00 +0200263 if [ ! -d "onos" ]; then \
264 git clone https://gerrit.onosproject.org/onos; \
265 fi
pierventre2c7a4db2020-06-26 21:24:00 +0200266
pierventre83611422020-08-14 22:53:15 +0200267 @modified=$$(cd ${ONOS_ROOT} && git status --porcelain); \
268 if [ ! -z "$${modified}" ]; then \
269 echo "Unable to checkout, you have pending changes in onos repository"; \
270 exit 1; \
271 fi
272
pierventre3b5f9f12020-10-22 16:24:34 +0200273 cd ${ONOS_ROOT} && git remote update
274
pierventre83611422020-08-14 22:53:15 +0200275 # In case of failure, we do not proceed because we cannot build with mvn
pierventre3b5f9f12020-10-22 16:24:34 +0200276 if ! (cd ${ONOS_ROOT} && (git checkout origin/${ONOS_VERSION} || git checkout ${ONOS_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200277 if ! (cd ${ONOS_ROOT} && git fetch ${ONOS_REPO} ${ONOS_VERSION} && git checkout FETCH_HEAD); then \
278 echo "Unable to fetch the changes from the onos repository"; \
279 exit 1; \
280 fi \
281 fi
pierventred9cb7292020-07-31 00:01:47 +0200282
pierventref03097a2020-07-15 18:49:05 +0200283onos-build: onos ## : Builds the tost-onos docker image
pierventre2c7a4db2020-06-26 21:24:00 +0200284 # Set some env variables
285 cd ${ONOS_ROOT} && \
286 . tools/build/envDefaults && \
287 docker build . -t ${ONOS_IMAGENAME} \
288 --build-arg PROFILE=${ONOS_PROFILE}
289
pierventre16709162020-07-16 20:48:24 +0200290tost-build: ## : Builds the tost docker image
291 docker build $(DOCKER_BUILD_ARGS) \
292 -t ${TOST_IMAGENAME} \
293 --build-arg LOCAL_APPS=${LOCAL_APPS} \
294 --build-arg KARAF_VERSION=${KARAF_VERSION} \
295 --build-arg org_label_schema_version="${VERSION}" \
296 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
297 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
298 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
pierventre83611422020-08-14 22:53:15 +0200299 --build-arg org_onosproject_onos_version="${ONOS_VERSION}"\
300 --build-arg org_onosproject_trellis_control_version="${TRELLIS_CONTROL_VERSION}"\
301 --build-arg org_onosproject_trellis_t3_version="${TRELLIS_T3_VERSION}"\
302 --build-arg org_opencord_fabric_tofino_version="${FABRIC_TOFINO_VERSION}"\
303 --build-arg org_omecproject_up4_version="${UP4_VERSION}"\
304 --build-arg org_opencord_kafka_onos_version="${KAFKA_ONOS_VERSION}"\
305 --build-arg org_stratumproject_fabric_tna_version="${FABRIC_TNA_VERSION}"\
pierventre16709162020-07-16 20:48:24 +0200306 -f Dockerfile.tost .
307
pierventref03097a2020-07-15 18:49:05 +0200308onos-push: ## : Pushes the tost-onos docker image to an external repository
pierventre2c7a4db2020-06-26 21:24:00 +0200309 docker push ${ONOS_IMAGENAME}
310
pierventre16709162020-07-16 20:48:24 +0200311tost-push: ## : Pushes the tost docker image to an external repository
312 docker push ${TOST_IMAGENAME}
pierventre2c7a4db2020-06-26 21:24:00 +0200313
pierventref03097a2020-07-15 18:49:05 +0200314# Used for CI job
pierventre83611422020-08-14 22:53:15 +0200315docker-build: check-scripts onos-build apps-build tost-build ## : Builds the tost image
pierventre2c7a4db2020-06-26 21:24:00 +0200316
pierventref03097a2020-07-15 18:49:05 +0200317# User for CD job
pierventre16709162020-07-16 20:48:24 +0200318docker-push: tost-push ## : Pushes the tost image
pierventref03097a2020-07-15 18:49:05 +0200319
pierventre16709162020-07-16 20:48:24 +0200320clean: ## : Deletes any locally copied files or artifacts
321 rm -rf ${ONOS_ROOT}
322 rm -rf ${TRELLIS_CONTROL_ROOT}
323 rm -rf ${TRELLIS_T3_ROOT}
324 rm -rf ${FABRIC_TOFINO_ROOT}
325 rm -rf ${UP4_ROOT}
326 rm -rf ${KAFKA_ONOS_ROOT}
pierventref33fc112020-07-30 12:55:54 +0200327 rm -rf ${FABRIC_TNA_ROOT}
pierventre16709162020-07-16 20:48:24 +0200328 rm -rf ${LOCAL_APPS}
329 rm -rf .m2
330 rm -rf mvn_settings.xml
pierventre2c7a4db2020-06-26 21:24:00 +0200331
332# end file