blob: 94d2ae7cb30e9980d3a3dcc138c66d7a28720b38 [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 ?=
25DOCKER_REPOSITORY ?=
26DOCKER_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)
pierventred3ba4522022-01-12 22:10:58 +010043# FIXME temporary until stable moves to newer commits
44 KARAF_VERSION := 4.2.9
pierventre83611422020-08-14 22:53:15 +020045# Includes the default ("working") versions of each component
pierventredd900102020-11-06 19:23:41 +010046 include ./Makefile.vars.stable
47else ifeq ($(DOCKER_TAG),master)
pierventred3ba4522022-01-12 22:10:58 +010048# FIXME temporary until stable moves to newer commits
49 KARAF_VERSION := 4.2.14
pierventredd900102020-11-06 19:23:41 +010050# Includes the master versions of each component
51 include ./Makefile.vars.master
52else
53 $(error You must define properly the DOCKER_TAG variable)
54endif
55
pierventre83611422020-08-14 22:53:15 +020056
57# Shellcheck related
58SHELLCHECK_TAG=v0.7.1
59SHELLCHECK_IMAGE=koalaman/shellcheck:${SHELLCHECK_TAG}
60
pierventre16709162020-07-16 20:48:24 +020061# ONOS related
pierventre7fdd3602021-05-05 10:54:38 +020062ONOS_IMAGENAME := tost-onos:${DOCKER_TAG}${DOCKER_TAG_PROFILER}${DOCKER_TAG_BUILD_DATE}
pierventre16709162020-07-16 20:48:24 +020063export ONOS_ROOT := $(shell pwd)/onos
pierventre83611422020-08-14 22:53:15 +020064ONOS_REPO := https://gerrit.onosproject.org/onos
pierventre16709162020-07-16 20:48:24 +020065ONOS_PROFILE := "tost"
pierventre7fdd3602021-05-05 10:54:38 +020066PROFILER ?=
67ONOS_YOURKIT := 2021.3-b230
Daniele Morod49dd092021-06-04 17:56:32 +020068USE_ONOS_BAZEL_OUTPUT ?=
Daniele Morof969c742022-01-03 22:01:00 +010069USE_LOCAL_SNAPSHOT_ARTIFACTS ?=
pierventre2c7a4db2020-06-26 21:24:00 +020070
pierventre16709162020-07-16 20:48:24 +020071# TOST related
pierventre7fdd3602021-05-05 10:54:38 +020072TOST_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}tost:${DOCKER_TAG}${DOCKER_TAG_PROFILER}${DOCKER_TAG_BUILD_DATE}
pierventre83611422020-08-14 22:53:15 +020073export LOCAL_APPS := local-apps
pierventre16709162020-07-16 20:48:24 +020074
75# Trellis-Control related
pierventre83611422020-08-14 22:53:15 +020076export TRELLIS_CONTROL_ROOT := $(shell pwd)/trellis-control
77export TRELLIS_CONTROL_REPO := https://gerrit.onosproject.org/trellis-control
pierventre16709162020-07-16 20:48:24 +020078
79# Trellis-T3 related
pierventre83611422020-08-14 22:53:15 +020080export TRELLIS_T3_ROOT := $(shell pwd)/trellis-t3
81export TRELLIS_T3_REPO := https://gerrit.onosproject.org/trellis-t3
pierventre16709162020-07-16 20:48:24 +020082
pierventre16709162020-07-16 20:48:24 +020083# Up4 related
pierventre83611422020-08-14 22:53:15 +020084export UP4_ROOT := $(shell pwd)/up4
pierventre0b6a9c32020-10-02 11:32:54 +020085export UP4_REPO := git@github.com:omec-project/up4.git
pierventre16709162020-07-16 20:48:24 +020086
pierventref33fc112020-07-30 12:55:54 +020087# Fabric-TNA related
pierventre83611422020-08-14 22:53:15 +020088export FABRIC_TNA_ROOT := $(shell pwd)/fabric-tna
pierventre0b6a9c32020-10-02 11:32:54 +020089export FABRIC_TNA_REPO := git@github.com:stratum/fabric-tna.git
pierventref33fc112020-07-30 12:55:54 +020090
pierventre8bd63502021-04-12 12:34:23 +020091.PHONY: onos trellis-control trellis-t3 up4 fabric-tna
pierventre16709162020-07-16 20:48:24 +020092
pierventref33fc112020-07-30 12:55:54 +020093.SILENT: up4 fabric-tna
pierventre2c7a4db2020-06-26 21:24:00 +020094
95# This should to be the first and default target in this Makefile
96help: ## : Print this help
97 @echo "Usage: make [<target>]"
98 @echo "where available targets are:"
99 @echo
pierventre83611422020-08-14 22:53:15 +0200100 @grep '^[[:alnum:]_-]*:.* ##' $(THIS_MAKE) \
pierventre2c7a4db2020-06-26 21:24:00 +0200101 | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'
102 @echo
103 @echo "Environment variables:"
pierventre83611422020-08-14 22:53:15 +0200104 @echo "ONOS_VERSION : Override to use a specific branch/commit/tag/release to build the image"
105 @echo "TRELLIS_CONTROL_VERSION : Override to use a specific branch/commit/tag/release to build the image"
106 @echo "TRELLIS_T3_VERSION : Override to use a specific branch/commit/tag/release to build the image"
pierventre83611422020-08-14 22:53:15 +0200107 @echo "UP4_VERSION : Override to use a specific branch/commit/tag/release to build the image"
pierventre83611422020-08-14 22:53:15 +0200108 @echo "FABRIC_TNA_VERSION : Override to use a specific branch/commit/tag/release to build the image"
pierventre2c7a4db2020-06-26 21:24:00 +0200109 @echo ""
pierventredd900102020-11-06 19:23:41 +0100110 @echo "'Makefile.vars.stable' defines the stable values for '*_VERSION' variables".
111 @echo "'Makefile.vars.master' defines the tip values for '*_VERSION' variables".
pierventref33fc112020-07-30 12:55:54 +0200112 @echo ""
pierventre2c7a4db2020-06-26 21:24:00 +0200113
114## Make targets
115
pierventre83611422020-08-14 22:53:15 +0200116check-scripts: ## : Provides warnings and suggestions for bash/sh shell scripts
117 # Fail if any of these files have warnings, exclude sed replacement warnings
118 docker run --rm -v "${PWD}:/mnt" ${SHELLCHECK_IMAGE} *.sh -e SC2001
119
pierventre16709162020-07-16 20:48:24 +0200120mvn_settings.xml: mvn_settings.sh ## : Builds mvn_settings file for proxy
121 @./$<
122
123local-apps: ## : Creates the folder that will host the oar file
124 mkdir -p ${LOCAL_APPS}/
125
126trellis-control: ## : Checkout trellis-control code
127 # Clones trellis-control if it does not exist
128 if [ ! -d "trellis-control" ]; then \
pierventre83611422020-08-14 22:53:15 +0200129 git clone ${TRELLIS_CONTROL_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200130 fi
pierventre83611422020-08-14 22:53:15 +0200131
132 # Pending changes - do not proceed
133 @modified=$$(cd ${TRELLIS_CONTROL_ROOT} && git status --porcelain); \
134 if [ ! -z "$${modified}" ]; then \
135 echo "Unable to checkout, you have pending changes in trellis-control repository"; \
136 exit 1; \
137 fi
138
pierventre3b5f9f12020-10-22 16:24:34 +0200139 # Updates the repo and avoids any stale branches
140 cd ${TRELLIS_CONTROL_ROOT} && git remote update
141
pierventre0b6a9c32020-10-02 11:32:54 +0200142 # Try the git checkout first otherwise we download the review
pierventre3b5f9f12020-10-22 16:24:34 +0200143 if ! (cd ${TRELLIS_CONTROL_ROOT} && (git checkout origin/${TRELLIS_CONTROL_VERSION} || git checkout ${TRELLIS_CONTROL_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200144 if ! (cd ${TRELLIS_CONTROL_ROOT} && git fetch ${TRELLIS_CONTROL_REPO} ${TRELLIS_CONTROL_VERSION} && git checkout FETCH_HEAD); then \
145 echo "Unable to fetch the changes from the trellis-control repository"; \
146 fi \
147 fi
pierventre16709162020-07-16 20:48:24 +0200148
Daniele Morof969c742022-01-03 22:01:00 +0100149trellis-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 +0200150 @./app-build.sh $@
151
pierventre16709162020-07-16 20:48:24 +0200152trellis-t3: ## : Checkout trellis-t3 code
153 if [ ! -d "trellis-t3" ]; then \
pierventre83611422020-08-14 22:53:15 +0200154 git clone ${TRELLIS_T3_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200155 fi
pierventre83611422020-08-14 22:53:15 +0200156
157 @modified=$$(cd ${TRELLIS_T3_ROOT} && git status --porcelain); \
158 if [ ! -z "$${modified}" ]; then \
159 echo "Unable to checkout, you have pending changes in trellis-t3 repository"; \
160 exit 1; \
161 fi
162
pierventre3b5f9f12020-10-22 16:24:34 +0200163 cd ${TRELLIS_T3_ROOT} && git remote update
164
165 if ! (cd ${TRELLIS_T3_ROOT} && (git checkout origin/${TRELLIS_T3_VERSION} || git checkout ${TRELLIS_T3_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200166 if ! (cd ${TRELLIS_T3_ROOT} && git fetch ${TRELLIS_T3_REPO} ${TRELLIS_T3_VERSION} && git checkout FETCH_HEAD); then \
167 echo "Unable to fetch the changes from the trellis-t3 repository"; \
168 fi \
169 fi
pierventre16709162020-07-16 20:48:24 +0200170
Daniele Morof969c742022-01-03 22:01:00 +0100171trellis-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 +0200172 @./app-build.sh $@
173
pierventre16709162020-07-16 20:48:24 +0200174up4: ## : Checkout up4 code
175 if [ ! -d "up4" ]; then \
176 git clone ${UP4_REPO}; \
177 fi
pierventre83611422020-08-14 22:53:15 +0200178
179 @modified=$$(cd ${UP4_ROOT} && git status --porcelain); \
180 if [ ! -z "$${modified}" ]; then \
181 echo "Unable to checkout, you have pending changes in up4 repository"; \
182 exit 1; \
183 fi
184
pierventre3b5f9f12020-10-22 16:24:34 +0200185 cd ${UP4_ROOT} && git remote update
186
187 if ! (cd ${UP4_ROOT} && (git checkout origin/${UP4_VERSION} || git checkout ${UP4_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200188 if ! (cd ${UP4_ROOT} && git fetch ${UP4_REPO} ${UP4_VERSION} && git checkout FETCH_HEAD); then \
189 echo "Unable to fetch the changes from the up4 repository"; \
190 exit 1; \
191 fi \
192 fi
pierventre16709162020-07-16 20:48:24 +0200193
Daniele Morof969c742022-01-03 22:01:00 +0100194up4-build: mvn_settings.xml .onos-publish-local local-apps up4 ## : Builds up4 using local app
pierventre83611422020-08-14 22:53:15 +0200195 @./app-build.sh $@
196
pierventref33fc112020-07-30 12:55:54 +0200197fabric-tna: ## : Checkout fabric-tna code
198 if [ ! -d "fabric-tna" ]; then \
199 git clone ${FABRIC_TNA_REPO}; \
200 fi
pierventre83611422020-08-14 22:53:15 +0200201
202 @modified=$$(cd ${FABRIC_TNA_ROOT} && git status --porcelain); \
203 if [ ! -z "$${modified}" ]; then \
204 echo "Unable to checkout, you have pending changes in fabric-tna repository"; \
205 exit 1; \
206 fi
207
pierventre3b5f9f12020-10-22 16:24:34 +0200208 cd ${FABRIC_TNA_ROOT} && git remote update
209
210 if ! (cd ${FABRIC_TNA_ROOT} && (git checkout origin/${FABRIC_TNA_VERSION} || git checkout ${FABRIC_TNA_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200211 if ! (cd ${FABRIC_TNA_ROOT} && git fetch ${FABRIC_TNA_REPO} ${FABRIC_TNA_VERSION} && git checkout FETCH_HEAD); then \
212 echo "Unable to fetch the changes from the fabric-tna repository"; \
213 exit 1; \
214 fi \
215 fi
pierventref33fc112020-07-30 12:55:54 +0200216
Daniele Morof969c742022-01-03 22:01:00 +0100217fabric-tna-build: mvn_settings.xml .onos-publish-local local-apps fabric-tna ## : Builds fabric-tna using local app
pierventre83611422020-08-14 22:53:15 +0200218 @./app-build.sh $@
219
pierventre8bd63502021-04-12 12:34:23 +0200220apps: trellis-control trellis-t3 up4 fabric-tna ## : downloads commits, files, and refs from remotes
pierventre83611422020-08-14 22:53:15 +0200221
pierventre8bd63502021-04-12 12:34:23 +0200222apps-build: trellis-control-build trellis-t3-build up4-build fabric-tna-build ## : Build the onos apps
pierventref33fc112020-07-30 12:55:54 +0200223
pierventre2c7a4db2020-06-26 21:24:00 +0200224onos: ## : Checkout onos code
pierventre2c7a4db2020-06-26 21:24:00 +0200225 if [ ! -d "onos" ]; then \
226 git clone https://gerrit.onosproject.org/onos; \
227 fi
pierventre2c7a4db2020-06-26 21:24:00 +0200228
pierventre83611422020-08-14 22:53:15 +0200229 @modified=$$(cd ${ONOS_ROOT} && git status --porcelain); \
230 if [ ! -z "$${modified}" ]; then \
231 echo "Unable to checkout, you have pending changes in onos repository"; \
232 exit 1; \
233 fi
234
pierventre3b5f9f12020-10-22 16:24:34 +0200235 cd ${ONOS_ROOT} && git remote update
236
pierventre83611422020-08-14 22:53:15 +0200237 # In case of failure, we do not proceed because we cannot build with mvn
pierventre3b5f9f12020-10-22 16:24:34 +0200238 if ! (cd ${ONOS_ROOT} && (git checkout origin/${ONOS_VERSION} || git checkout ${ONOS_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200239 if ! (cd ${ONOS_ROOT} && git fetch ${ONOS_REPO} ${ONOS_VERSION} && git checkout FETCH_HEAD); then \
240 echo "Unable to fetch the changes from the onos repository"; \
241 exit 1; \
242 fi \
243 fi
pierventred9cb7292020-07-31 00:01:47 +0200244
pierventref03097a2020-07-15 18:49:05 +0200245onos-build: onos ## : Builds the tost-onos docker image
Daniele Morof969c742022-01-03 22:01:00 +0100246 rm -rf .onos-publish-local
pierventre7fdd3602021-05-05 10:54:38 +0200247ifeq ($(PROFILER),true)
248 # profiler enabled
249 cd ${ONOS_ROOT} && \
250 . tools/build/envDefaults && \
251 docker build . -t ${ONOS_IMAGENAME} \
252 --build-arg PROFILE=${ONOS_PROFILE} \
253 --build-arg ONOS_YOURKIT=${ONOS_YOURKIT} \
254 -f tools/dev/Dockerfile-yourkit
Daniele Morod49dd092021-06-04 17:56:32 +0200255else ifeq ($(USE_ONOS_BAZEL_OUTPUT),true)
256 # profiler not enabled, using local bazel output
257 cd ${ONOS_ROOT} && \
258 . tools/build/envDefaults && \
259 bazel build onos --define profile=${ONOS_PROFILE}
260 docker build -t ${ONOS_IMAGENAME} -f ${ONOS_ROOT}/tools/dev/Dockerfile-bazel ${ONOS_ROOT}/bazel-bin
pierventre7fdd3602021-05-05 10:54:38 +0200261else
262 # profiler not enabled
pierventre2c7a4db2020-06-26 21:24:00 +0200263 cd ${ONOS_ROOT} && \
264 . tools/build/envDefaults && \
265 docker build . -t ${ONOS_IMAGENAME} \
266 --build-arg PROFILE=${ONOS_PROFILE}
pierventre7fdd3602021-05-05 10:54:38 +0200267endif
Daniele Morof969c742022-01-03 22:01:00 +0100268 make .onos-publish-local
269
270.onos-publish-local:
271ifeq ($(USE_LOCAL_SNAPSHOT_ARTIFACTS),true)
272 @# TODO: build custom docker container with required dependencies instead of installing via publish-local script
273 docker run --rm --entrypoint bash -it -v $(shell pwd)/:/tost \
274 -e ONOS_ROOT=/tost/onos -e MAVEN_REPO=/tost/.m2/repository -w /tost \
275 bitnami/minideb:buster ./publish-local.sh
276endif
277 touch .onos-publish-local
pierventre2c7a4db2020-06-26 21:24:00 +0200278
pierventre16709162020-07-16 20:48:24 +0200279tost-build: ## : Builds the tost docker image
280 docker build $(DOCKER_BUILD_ARGS) \
281 -t ${TOST_IMAGENAME} \
pierventre7fdd3602021-05-05 10:54:38 +0200282 --build-arg DOCKER_TAG="${DOCKER_TAG}${DOCKER_TAG_PROFILER}${DOCKER_TAG_BUILD_DATE}" \
pierventre16709162020-07-16 20:48:24 +0200283 --build-arg LOCAL_APPS=${LOCAL_APPS} \
284 --build-arg KARAF_VERSION=${KARAF_VERSION} \
pierventre7fdd3602021-05-05 10:54:38 +0200285 --build-arg org_label_schema_version="${DOCKER_TAG}${DOCKER_TAG_PROFILER}${DOCKER_TAG_BUILD_DATE}" \
pierventre16709162020-07-16 20:48:24 +0200286 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
287 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
288 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
pierventredd900102020-11-06 19:23:41 +0100289 --build-arg org_onosproject_onos_version="$(shell cd ${ONOS_ROOT} && git rev-parse HEAD)"\
290 --build-arg org_onosproject_trellis_control_version="$(shell cd ${TRELLIS_CONTROL_ROOT} && git rev-parse HEAD)"\
291 --build-arg org_onosproject_trellis_t3_version="$(shell cd ${TRELLIS_T3_ROOT} && git rev-parse HEAD)"\
pierventredd900102020-11-06 19:23:41 +0100292 --build-arg org_omecproject_up4_version="$(shell cd ${UP4_ROOT} && git rev-parse HEAD)"\
pierventredd900102020-11-06 19:23:41 +0100293 --build-arg org_stratumproject_fabric_tna_version="$(shell cd ${FABRIC_TNA_ROOT} && git rev-parse HEAD)"\
pierventre16709162020-07-16 20:48:24 +0200294 -f Dockerfile.tost .
295
pierventref03097a2020-07-15 18:49:05 +0200296onos-push: ## : Pushes the tost-onos docker image to an external repository
pierventre2c7a4db2020-06-26 21:24:00 +0200297 docker push ${ONOS_IMAGENAME}
298
pierventre16709162020-07-16 20:48:24 +0200299tost-push: ## : Pushes the tost docker image to an external repository
300 docker push ${TOST_IMAGENAME}
pierventre2c7a4db2020-06-26 21:24:00 +0200301
pierventref03097a2020-07-15 18:49:05 +0200302# Used for CI job
pierventre83611422020-08-14 22:53:15 +0200303docker-build: check-scripts onos-build apps-build tost-build ## : Builds the tost image
pierventre2c7a4db2020-06-26 21:24:00 +0200304
pierventref03097a2020-07-15 18:49:05 +0200305# User for CD job
pierventre16709162020-07-16 20:48:24 +0200306docker-push: tost-push ## : Pushes the tost image
pierventref03097a2020-07-15 18:49:05 +0200307
pierventre16709162020-07-16 20:48:24 +0200308clean: ## : Deletes any locally copied files or artifacts
309 rm -rf ${ONOS_ROOT}
310 rm -rf ${TRELLIS_CONTROL_ROOT}
311 rm -rf ${TRELLIS_T3_ROOT}
pierventre16709162020-07-16 20:48:24 +0200312 rm -rf ${UP4_ROOT}
pierventref33fc112020-07-30 12:55:54 +0200313 rm -rf ${FABRIC_TNA_ROOT}
pierventre16709162020-07-16 20:48:24 +0200314 rm -rf ${LOCAL_APPS}
315 rm -rf .m2
316 rm -rf mvn_settings.xml
Daniele Morof969c742022-01-03 22:01:00 +0100317 rm -rf .onos-publish-local
pierventre2c7a4db2020-06-26 21:24:00 +0200318
319# end file