blob: b47d1e63f8b3440c6816815736ae4c763ad60ed3 [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
pierventre83611422020-08-14 22:53:15 +020021THIS_MAKE := $(lastword $(MAKEFILE_LIST))
pierventre2c7a4db2020-06-26 21:24:00 +020022
23# Docker related
pierventre83611422020-08-14 22:53:15 +020024DOCKER_REGISTRY ?=
Carmelo Cascone68528e82022-02-04 18:42:34 -080025DOCKER_REPOSITORY ?= opennetworking/sdfabric-onos
pierventre83611422020-08-14 22:53:15 +020026DOCKER_BUILD_ARGS ?=
pierventredd900102020-11-06 19:23:41 +010027DOCKER_TAG ?= stable
28DOCKER_TAG_BUILD_DATE ?=
pierventre7fdd3602021-05-05 10:54:38 +020029DOCKER_TAG_PROFILER ?=
pierventre2c7a4db2020-06-26 21:24:00 +020030
31# Docker labels. Only set ref and commit date if committed
pierventre83611422020-08-14 22:53:15 +020032DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
33DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
34DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
pierventre2c7a4db2020-06-26 21:24:00 +020035
36ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
37 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
38else
39 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
40endif
41
pierventredd900102020-11-06 19:23:41 +010042ifeq ($(DOCKER_TAG),stable)
pierventre83611422020-08-14 22:53:15 +020043# Includes the default ("working") versions of each component
pierventredd900102020-11-06 19:23:41 +010044 include ./Makefile.vars.stable
45else ifeq ($(DOCKER_TAG),master)
46# Includes the master versions of each component
47 include ./Makefile.vars.master
48else
49 $(error You must define properly the DOCKER_TAG variable)
50endif
51
Carmelo Cascone68528e82022-02-04 18:42:34 -080052FINAL_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}:${DOCKER_TAG}${DOCKER_TAG_PROFILER}${DOCKER_TAG_BUILD_DATE}
53export LOCAL_APPS := local-apps
pierventre83611422020-08-14 22:53:15 +020054
55# Shellcheck related
56SHELLCHECK_TAG=v0.7.1
57SHELLCHECK_IMAGE=koalaman/shellcheck:${SHELLCHECK_TAG}
58
pierventre16709162020-07-16 20:48:24 +020059# ONOS related
Carmelo Cascone68528e82022-02-04 18:42:34 -080060ONOS_BASE_IMAGENAME := onos-base:${DOCKER_TAG}${DOCKER_TAG_PROFILER}${DOCKER_TAG_BUILD_DATE}
pierventre16709162020-07-16 20:48:24 +020061export ONOS_ROOT := $(shell pwd)/onos
pierventre83611422020-08-14 22:53:15 +020062ONOS_REPO := https://gerrit.onosproject.org/onos
Charles Chanca28c842022-02-04 21:49:00 -080063# This profile contains the minimal set of ONOS built-in apps required to control SD-Fabric.
64ONOS_PROFILE := "sdfabric"
pierventre7fdd3602021-05-05 10:54:38 +020065PROFILER ?=
66ONOS_YOURKIT := 2021.3-b230
Daniele Morod49dd092021-06-04 17:56:32 +020067USE_ONOS_BAZEL_OUTPUT ?=
Daniele Morof969c742022-01-03 22:01:00 +010068USE_LOCAL_SNAPSHOT_ARTIFACTS ?=
Carmelo Casconee281c3b2022-03-09 13:25:01 -080069KARAF_VERSION := 4.2.14
pierventre2c7a4db2020-06-26 21:24:00 +020070
pierventre16709162020-07-16 20:48:24 +020071# Trellis-Control related
pierventre83611422020-08-14 22:53:15 +020072export TRELLIS_CONTROL_ROOT := $(shell pwd)/trellis-control
73export TRELLIS_CONTROL_REPO := https://gerrit.onosproject.org/trellis-control
pierventre16709162020-07-16 20:48:24 +020074
75# Trellis-T3 related
pierventre83611422020-08-14 22:53:15 +020076export TRELLIS_T3_ROOT := $(shell pwd)/trellis-t3
77export TRELLIS_T3_REPO := https://gerrit.onosproject.org/trellis-t3
pierventre16709162020-07-16 20:48:24 +020078
pierventre16709162020-07-16 20:48:24 +020079# Up4 related
pierventre83611422020-08-14 22:53:15 +020080export UP4_ROOT := $(shell pwd)/up4
pierventre0b6a9c32020-10-02 11:32:54 +020081export UP4_REPO := git@github.com:omec-project/up4.git
pierventre16709162020-07-16 20:48:24 +020082
pierventref33fc112020-07-30 12:55:54 +020083# Fabric-TNA related
pierventre83611422020-08-14 22:53:15 +020084export FABRIC_TNA_ROOT := $(shell pwd)/fabric-tna
pierventre0b6a9c32020-10-02 11:32:54 +020085export FABRIC_TNA_REPO := git@github.com:stratum/fabric-tna.git
pierventref33fc112020-07-30 12:55:54 +020086
Charles Chanc11ecd62022-02-07 15:46:48 -080087.PHONY: onos trellis-control up4 fabric-tna
pierventre16709162020-07-16 20:48:24 +020088
pierventref33fc112020-07-30 12:55:54 +020089.SILENT: up4 fabric-tna
pierventre2c7a4db2020-06-26 21:24:00 +020090
91# This should to be the first and default target in this Makefile
92help: ## : Print this help
93 @echo "Usage: make [<target>]"
94 @echo "where available targets are:"
95 @echo
pierventre83611422020-08-14 22:53:15 +020096 @grep '^[[:alnum:]_-]*:.* ##' $(THIS_MAKE) \
pierventre2c7a4db2020-06-26 21:24:00 +020097 | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'
98 @echo
99 @echo "Environment variables:"
pierventre83611422020-08-14 22:53:15 +0200100 @echo "ONOS_VERSION : Override to use a specific branch/commit/tag/release to build the image"
101 @echo "TRELLIS_CONTROL_VERSION : Override to use a specific branch/commit/tag/release to build the image"
102 @echo "TRELLIS_T3_VERSION : Override to use a specific branch/commit/tag/release to build the image"
pierventre83611422020-08-14 22:53:15 +0200103 @echo "UP4_VERSION : Override to use a specific branch/commit/tag/release to build the image"
pierventre83611422020-08-14 22:53:15 +0200104 @echo "FABRIC_TNA_VERSION : Override to use a specific branch/commit/tag/release to build the image"
pierventre2c7a4db2020-06-26 21:24:00 +0200105 @echo ""
pierventredd900102020-11-06 19:23:41 +0100106 @echo "'Makefile.vars.stable' defines the stable values for '*_VERSION' variables".
107 @echo "'Makefile.vars.master' defines the tip values for '*_VERSION' variables".
pierventref33fc112020-07-30 12:55:54 +0200108 @echo ""
pierventre2c7a4db2020-06-26 21:24:00 +0200109
110## Make targets
111
pierventre83611422020-08-14 22:53:15 +0200112check-scripts: ## : Provides warnings and suggestions for bash/sh shell scripts
113 # Fail if any of these files have warnings, exclude sed replacement warnings
114 docker run --rm -v "${PWD}:/mnt" ${SHELLCHECK_IMAGE} *.sh -e SC2001
115
pierventre16709162020-07-16 20:48:24 +0200116mvn_settings.xml: mvn_settings.sh ## : Builds mvn_settings file for proxy
117 @./$<
118
119local-apps: ## : Creates the folder that will host the oar file
120 mkdir -p ${LOCAL_APPS}/
121
122trellis-control: ## : Checkout trellis-control code
123 # Clones trellis-control if it does not exist
124 if [ ! -d "trellis-control" ]; then \
pierventre83611422020-08-14 22:53:15 +0200125 git clone ${TRELLIS_CONTROL_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200126 fi
pierventre83611422020-08-14 22:53:15 +0200127
128 # Pending changes - do not proceed
129 @modified=$$(cd ${TRELLIS_CONTROL_ROOT} && git status --porcelain); \
130 if [ ! -z "$${modified}" ]; then \
131 echo "Unable to checkout, you have pending changes in trellis-control repository"; \
132 exit 1; \
133 fi
134
pierventre3b5f9f12020-10-22 16:24:34 +0200135 # Updates the repo and avoids any stale branches
136 cd ${TRELLIS_CONTROL_ROOT} && git remote update
137
pierventre0b6a9c32020-10-02 11:32:54 +0200138 # Try the git checkout first otherwise we download the review
pierventre3b5f9f12020-10-22 16:24:34 +0200139 if ! (cd ${TRELLIS_CONTROL_ROOT} && (git checkout origin/${TRELLIS_CONTROL_VERSION} || git checkout ${TRELLIS_CONTROL_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200140 if ! (cd ${TRELLIS_CONTROL_ROOT} && git fetch ${TRELLIS_CONTROL_REPO} ${TRELLIS_CONTROL_VERSION} && git checkout FETCH_HEAD); then \
141 echo "Unable to fetch the changes from the trellis-control repository"; \
142 fi \
143 fi
pierventre16709162020-07-16 20:48:24 +0200144
Daniele Morof969c742022-01-03 22:01:00 +0100145trellis-control-build: mvn_settings.xml .onos-publish-local local-apps trellis-control ## : Builds trellis-control using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200146 @./app-build.sh $@
147
pierventre16709162020-07-16 20:48:24 +0200148trellis-t3: ## : Checkout trellis-t3 code
149 if [ ! -d "trellis-t3" ]; then \
pierventre83611422020-08-14 22:53:15 +0200150 git clone ${TRELLIS_T3_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200151 fi
pierventre83611422020-08-14 22:53:15 +0200152
153 @modified=$$(cd ${TRELLIS_T3_ROOT} && git status --porcelain); \
154 if [ ! -z "$${modified}" ]; then \
155 echo "Unable to checkout, you have pending changes in trellis-t3 repository"; \
156 exit 1; \
157 fi
158
pierventre3b5f9f12020-10-22 16:24:34 +0200159 cd ${TRELLIS_T3_ROOT} && git remote update
160
161 if ! (cd ${TRELLIS_T3_ROOT} && (git checkout origin/${TRELLIS_T3_VERSION} || git checkout ${TRELLIS_T3_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200162 if ! (cd ${TRELLIS_T3_ROOT} && git fetch ${TRELLIS_T3_REPO} ${TRELLIS_T3_VERSION} && git checkout FETCH_HEAD); then \
163 echo "Unable to fetch the changes from the trellis-t3 repository"; \
164 fi \
165 fi
pierventre16709162020-07-16 20:48:24 +0200166
Daniele Morof969c742022-01-03 22:01:00 +0100167trellis-t3-build: mvn_settings.xml .onos-publish-local local-apps trellis-t3 ## : Builds trellis-t3 using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200168 @./app-build.sh $@
169
pierventre16709162020-07-16 20:48:24 +0200170up4: ## : Checkout up4 code
171 if [ ! -d "up4" ]; then \
172 git clone ${UP4_REPO}; \
173 fi
pierventre83611422020-08-14 22:53:15 +0200174
175 @modified=$$(cd ${UP4_ROOT} && git status --porcelain); \
176 if [ ! -z "$${modified}" ]; then \
177 echo "Unable to checkout, you have pending changes in up4 repository"; \
178 exit 1; \
179 fi
180
pierventre3b5f9f12020-10-22 16:24:34 +0200181 cd ${UP4_ROOT} && git remote update
182
183 if ! (cd ${UP4_ROOT} && (git checkout origin/${UP4_VERSION} || git checkout ${UP4_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200184 if ! (cd ${UP4_ROOT} && git fetch ${UP4_REPO} ${UP4_VERSION} && git checkout FETCH_HEAD); then \
185 echo "Unable to fetch the changes from the up4 repository"; \
186 exit 1; \
187 fi \
188 fi
pierventre16709162020-07-16 20:48:24 +0200189
Daniele Morof969c742022-01-03 22:01:00 +0100190up4-build: mvn_settings.xml .onos-publish-local local-apps up4 ## : Builds up4 using local app
pierventre83611422020-08-14 22:53:15 +0200191 @./app-build.sh $@
192
pierventref33fc112020-07-30 12:55:54 +0200193fabric-tna: ## : Checkout fabric-tna code
194 if [ ! -d "fabric-tna" ]; then \
195 git clone ${FABRIC_TNA_REPO}; \
196 fi
pierventre83611422020-08-14 22:53:15 +0200197
198 @modified=$$(cd ${FABRIC_TNA_ROOT} && git status --porcelain); \
199 if [ ! -z "$${modified}" ]; then \
200 echo "Unable to checkout, you have pending changes in fabric-tna repository"; \
201 exit 1; \
202 fi
203
pierventre3b5f9f12020-10-22 16:24:34 +0200204 cd ${FABRIC_TNA_ROOT} && git remote update
205
206 if ! (cd ${FABRIC_TNA_ROOT} && (git checkout origin/${FABRIC_TNA_VERSION} || git checkout ${FABRIC_TNA_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200207 if ! (cd ${FABRIC_TNA_ROOT} && git fetch ${FABRIC_TNA_REPO} ${FABRIC_TNA_VERSION} && git checkout FETCH_HEAD); then \
208 echo "Unable to fetch the changes from the fabric-tna repository"; \
209 exit 1; \
210 fi \
211 fi
pierventref33fc112020-07-30 12:55:54 +0200212
Daniele Morof969c742022-01-03 22:01:00 +0100213fabric-tna-build: mvn_settings.xml .onos-publish-local local-apps fabric-tna ## : Builds fabric-tna using local app
pierventre83611422020-08-14 22:53:15 +0200214 @./app-build.sh $@
215
Charles Chanc11ecd62022-02-07 15:46:48 -0800216## : downloads commits, files, and refs from remotes. Intentionally leave out t3.
217apps: trellis-control up4 fabric-tna
pierventre83611422020-08-14 22:53:15 +0200218
Charles Chanc11ecd62022-02-07 15:46:48 -0800219## : Build the onos apps. Intentionally leave out t3.
220apps-build: trellis-control-build up4-build fabric-tna-build
pierventref33fc112020-07-30 12:55:54 +0200221
pierventre2c7a4db2020-06-26 21:24:00 +0200222onos: ## : Checkout onos code
pierventre2c7a4db2020-06-26 21:24:00 +0200223 if [ ! -d "onos" ]; then \
224 git clone https://gerrit.onosproject.org/onos; \
225 fi
pierventre2c7a4db2020-06-26 21:24:00 +0200226
pierventre83611422020-08-14 22:53:15 +0200227 @modified=$$(cd ${ONOS_ROOT} && git status --porcelain); \
228 if [ ! -z "$${modified}" ]; then \
229 echo "Unable to checkout, you have pending changes in onos repository"; \
230 exit 1; \
231 fi
232
pierventre3b5f9f12020-10-22 16:24:34 +0200233 cd ${ONOS_ROOT} && git remote update
234
pierventre83611422020-08-14 22:53:15 +0200235 # In case of failure, we do not proceed because we cannot build with mvn
pierventre3b5f9f12020-10-22 16:24:34 +0200236 if ! (cd ${ONOS_ROOT} && (git checkout origin/${ONOS_VERSION} || git checkout ${ONOS_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200237 if ! (cd ${ONOS_ROOT} && git fetch ${ONOS_REPO} ${ONOS_VERSION} && git checkout FETCH_HEAD); then \
238 echo "Unable to fetch the changes from the onos repository"; \
239 exit 1; \
240 fi \
241 fi
pierventred9cb7292020-07-31 00:01:47 +0200242
Carmelo Cascone68528e82022-02-04 18:42:34 -0800243onos-build: onos ## : Builds the onos-base docker image
Daniele Morof969c742022-01-03 22:01:00 +0100244 rm -rf .onos-publish-local
pierventre7fdd3602021-05-05 10:54:38 +0200245ifeq ($(PROFILER),true)
246 # profiler enabled
247 cd ${ONOS_ROOT} && \
248 . tools/build/envDefaults && \
Carmelo Cascone68528e82022-02-04 18:42:34 -0800249 docker build . -t ${ONOS_BASE_IMAGENAME} \
pierventre7fdd3602021-05-05 10:54:38 +0200250 --build-arg PROFILE=${ONOS_PROFILE} \
251 --build-arg ONOS_YOURKIT=${ONOS_YOURKIT} \
252 -f tools/dev/Dockerfile-yourkit
Daniele Morod49dd092021-06-04 17:56:32 +0200253else ifeq ($(USE_ONOS_BAZEL_OUTPUT),true)
254 # profiler not enabled, using local bazel output
255 cd ${ONOS_ROOT} && \
256 . tools/build/envDefaults && \
257 bazel build onos --define profile=${ONOS_PROFILE}
Carmelo Cascone68528e82022-02-04 18:42:34 -0800258 docker build -t ${ONOS_BASE_IMAGENAME} -f ${ONOS_ROOT}/tools/dev/Dockerfile-bazel ${ONOS_ROOT}/bazel-bin
pierventre7fdd3602021-05-05 10:54:38 +0200259else
260 # profiler not enabled
pierventre2c7a4db2020-06-26 21:24:00 +0200261 cd ${ONOS_ROOT} && \
262 . tools/build/envDefaults && \
Carmelo Cascone68528e82022-02-04 18:42:34 -0800263 docker build . -t ${ONOS_BASE_IMAGENAME} \
pierventre2c7a4db2020-06-26 21:24:00 +0200264 --build-arg PROFILE=${ONOS_PROFILE}
pierventre7fdd3602021-05-05 10:54:38 +0200265endif
Daniele Morof969c742022-01-03 22:01:00 +0100266 make .onos-publish-local
267
268.onos-publish-local:
269ifeq ($(USE_LOCAL_SNAPSHOT_ARTIFACTS),true)
270 @# TODO: build custom docker container with required dependencies instead of installing via publish-local script
Carmelo Cascone68528e82022-02-04 18:42:34 -0800271 docker run --rm --entrypoint bash -it -v $(shell pwd)/:/src \
272 -e ONOS_ROOT=/src/onos -e MAVEN_REPO=/src/.m2/repository -w /src \
Daniele Morof969c742022-01-03 22:01:00 +0100273 bitnami/minideb:buster ./publish-local.sh
274endif
275 touch .onos-publish-local
pierventre2c7a4db2020-06-26 21:24:00 +0200276
Carmelo Cascone68528e82022-02-04 18:42:34 -0800277package: ## : Builds the sdfabric-onos docker image
pierventre16709162020-07-16 20:48:24 +0200278 docker build $(DOCKER_BUILD_ARGS) \
Carmelo Cascone68528e82022-02-04 18:42:34 -0800279 -t ${FINAL_IMAGENAME} \
pierventre7fdd3602021-05-05 10:54:38 +0200280 --build-arg DOCKER_TAG="${DOCKER_TAG}${DOCKER_TAG_PROFILER}${DOCKER_TAG_BUILD_DATE}" \
pierventre16709162020-07-16 20:48:24 +0200281 --build-arg LOCAL_APPS=${LOCAL_APPS} \
282 --build-arg KARAF_VERSION=${KARAF_VERSION} \
pierventre7fdd3602021-05-05 10:54:38 +0200283 --build-arg org_label_schema_version="${DOCKER_TAG}${DOCKER_TAG_PROFILER}${DOCKER_TAG_BUILD_DATE}" \
pierventre16709162020-07-16 20:48:24 +0200284 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
285 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
286 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
pierventredd900102020-11-06 19:23:41 +0100287 --build-arg org_onosproject_onos_version="$(shell cd ${ONOS_ROOT} && git rev-parse HEAD)"\
288 --build-arg org_onosproject_trellis_control_version="$(shell cd ${TRELLIS_CONTROL_ROOT} && git rev-parse HEAD)"\
pierventredd900102020-11-06 19:23:41 +0100289 --build-arg org_omecproject_up4_version="$(shell cd ${UP4_ROOT} && git rev-parse HEAD)"\
pierventredd900102020-11-06 19:23:41 +0100290 --build-arg org_stratumproject_fabric_tna_version="$(shell cd ${FABRIC_TNA_ROOT} && git rev-parse HEAD)"\
Carmelo Cascone68528e82022-02-04 18:42:34 -0800291 -f Dockerfile .
pierventre16709162020-07-16 20:48:24 +0200292
Carmelo Cascone68528e82022-02-04 18:42:34 -0800293onos-push: ## : Pushes the onos-base docker image to an external repository
294 docker push ${ONOS_BASE_IMAGENAME}
pierventre2c7a4db2020-06-26 21:24:00 +0200295
Carmelo Cascone68528e82022-02-04 18:42:34 -0800296push: ## : Pushes the sdfabric-onos docker image to an external repository
297 docker push ${FINAL_IMAGENAME}
pierventre2c7a4db2020-06-26 21:24:00 +0200298
pierventref03097a2020-07-15 18:49:05 +0200299# Used for CI job
Carmelo Cascone68528e82022-02-04 18:42:34 -0800300docker-build: check-scripts onos-build apps-build package ## : Builds the sdfabric-onos image
pierventre2c7a4db2020-06-26 21:24:00 +0200301
pierventref03097a2020-07-15 18:49:05 +0200302# User for CD job
Carmelo Cascone68528e82022-02-04 18:42:34 -0800303docker-push: push ## : Pushes the sdfabric-onos Docker image
pierventref03097a2020-07-15 18:49:05 +0200304
pierventre16709162020-07-16 20:48:24 +0200305clean: ## : Deletes any locally copied files or artifacts
306 rm -rf ${ONOS_ROOT}
307 rm -rf ${TRELLIS_CONTROL_ROOT}
308 rm -rf ${TRELLIS_T3_ROOT}
pierventre16709162020-07-16 20:48:24 +0200309 rm -rf ${UP4_ROOT}
pierventref33fc112020-07-30 12:55:54 +0200310 rm -rf ${FABRIC_TNA_ROOT}
pierventre16709162020-07-16 20:48:24 +0200311 rm -rf ${LOCAL_APPS}
312 rm -rf .m2
313 rm -rf mvn_settings.xml
Daniele Morof969c742022-01-03 22:01:00 +0100314 rm -rf .onos-publish-local
pierventre2c7a4db2020-06-26 21:24:00 +0200315
316# end file