blob: d812fbcb2b6b5255c2a3ca99d22c1599f7560b74 [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)
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
pierventre83611422020-08-14 22:53:15 +020052
53# Shellcheck related
54SHELLCHECK_TAG=v0.7.1
55SHELLCHECK_IMAGE=koalaman/shellcheck:${SHELLCHECK_TAG}
56
pierventre16709162020-07-16 20:48:24 +020057# ONOS related
pierventre7fdd3602021-05-05 10:54:38 +020058ONOS_IMAGENAME := tost-onos:${DOCKER_TAG}${DOCKER_TAG_PROFILER}${DOCKER_TAG_BUILD_DATE}
pierventre16709162020-07-16 20:48:24 +020059export ONOS_ROOT := $(shell pwd)/onos
pierventre83611422020-08-14 22:53:15 +020060ONOS_REPO := https://gerrit.onosproject.org/onos
pierventre16709162020-07-16 20:48:24 +020061ONOS_PROFILE := "tost"
62KARAF_VERSION := 4.2.9
pierventre7fdd3602021-05-05 10:54:38 +020063PROFILER ?=
64ONOS_YOURKIT := 2021.3-b230
pierventre2c7a4db2020-06-26 21:24:00 +020065
pierventre16709162020-07-16 20:48:24 +020066# TOST related
pierventre7fdd3602021-05-05 10:54:38 +020067TOST_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}tost:${DOCKER_TAG}${DOCKER_TAG_PROFILER}${DOCKER_TAG_BUILD_DATE}
pierventre83611422020-08-14 22:53:15 +020068export LOCAL_APPS := local-apps
pierventre16709162020-07-16 20:48:24 +020069
70# Trellis-Control related
pierventre83611422020-08-14 22:53:15 +020071export TRELLIS_CONTROL_ROOT := $(shell pwd)/trellis-control
72export TRELLIS_CONTROL_REPO := https://gerrit.onosproject.org/trellis-control
pierventre16709162020-07-16 20:48:24 +020073
74# Trellis-T3 related
pierventre83611422020-08-14 22:53:15 +020075export TRELLIS_T3_ROOT := $(shell pwd)/trellis-t3
76export TRELLIS_T3_REPO := https://gerrit.onosproject.org/trellis-t3
pierventre16709162020-07-16 20:48:24 +020077
pierventre16709162020-07-16 20:48:24 +020078# Up4 related
pierventre83611422020-08-14 22:53:15 +020079export UP4_ROOT := $(shell pwd)/up4
pierventre0b6a9c32020-10-02 11:32:54 +020080export UP4_REPO := git@github.com:omec-project/up4.git
pierventre16709162020-07-16 20:48:24 +020081
pierventref33fc112020-07-30 12:55:54 +020082# Fabric-TNA related
pierventre83611422020-08-14 22:53:15 +020083export FABRIC_TNA_ROOT := $(shell pwd)/fabric-tna
pierventre0b6a9c32020-10-02 11:32:54 +020084export FABRIC_TNA_REPO := git@github.com:stratum/fabric-tna.git
pierventref33fc112020-07-30 12:55:54 +020085
pierventre8bd63502021-04-12 12:34:23 +020086.PHONY: onos trellis-control trellis-t3 up4 fabric-tna
pierventre16709162020-07-16 20:48:24 +020087
pierventref33fc112020-07-30 12:55:54 +020088.SILENT: up4 fabric-tna
pierventre2c7a4db2020-06-26 21:24:00 +020089
90# This should to be the first and default target in this Makefile
91help: ## : Print this help
92 @echo "Usage: make [<target>]"
93 @echo "where available targets are:"
94 @echo
pierventre83611422020-08-14 22:53:15 +020095 @grep '^[[:alnum:]_-]*:.* ##' $(THIS_MAKE) \
pierventre2c7a4db2020-06-26 21:24:00 +020096 | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'
97 @echo
98 @echo "Environment variables:"
pierventre83611422020-08-14 22:53:15 +020099 @echo "ONOS_VERSION : Override to use a specific branch/commit/tag/release to build the image"
100 @echo "TRELLIS_CONTROL_VERSION : Override to use a specific branch/commit/tag/release to build the image"
101 @echo "TRELLIS_T3_VERSION : Override to use a specific branch/commit/tag/release to build the image"
pierventre83611422020-08-14 22:53:15 +0200102 @echo "UP4_VERSION : Override to use a specific branch/commit/tag/release to build the image"
pierventre83611422020-08-14 22:53:15 +0200103 @echo "FABRIC_TNA_VERSION : Override to use a specific branch/commit/tag/release to build the image"
pierventre2c7a4db2020-06-26 21:24:00 +0200104 @echo ""
pierventredd900102020-11-06 19:23:41 +0100105 @echo "'Makefile.vars.stable' defines the stable values for '*_VERSION' variables".
106 @echo "'Makefile.vars.master' defines the tip values for '*_VERSION' variables".
pierventref33fc112020-07-30 12:55:54 +0200107 @echo ""
pierventre2c7a4db2020-06-26 21:24:00 +0200108
109## Make targets
110
pierventre83611422020-08-14 22:53:15 +0200111check-scripts: ## : Provides warnings and suggestions for bash/sh shell scripts
112 # Fail if any of these files have warnings, exclude sed replacement warnings
113 docker run --rm -v "${PWD}:/mnt" ${SHELLCHECK_IMAGE} *.sh -e SC2001
114
pierventre16709162020-07-16 20:48:24 +0200115mvn_settings.xml: mvn_settings.sh ## : Builds mvn_settings file for proxy
116 @./$<
117
118local-apps: ## : Creates the folder that will host the oar file
119 mkdir -p ${LOCAL_APPS}/
120
121trellis-control: ## : Checkout trellis-control code
122 # Clones trellis-control if it does not exist
123 if [ ! -d "trellis-control" ]; then \
pierventre83611422020-08-14 22:53:15 +0200124 git clone ${TRELLIS_CONTROL_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200125 fi
pierventre83611422020-08-14 22:53:15 +0200126
127 # Pending changes - do not proceed
128 @modified=$$(cd ${TRELLIS_CONTROL_ROOT} && git status --porcelain); \
129 if [ ! -z "$${modified}" ]; then \
130 echo "Unable to checkout, you have pending changes in trellis-control repository"; \
131 exit 1; \
132 fi
133
pierventre3b5f9f12020-10-22 16:24:34 +0200134 # Updates the repo and avoids any stale branches
135 cd ${TRELLIS_CONTROL_ROOT} && git remote update
136
pierventre0b6a9c32020-10-02 11:32:54 +0200137 # Try the git checkout first otherwise we download the review
pierventre3b5f9f12020-10-22 16:24:34 +0200138 if ! (cd ${TRELLIS_CONTROL_ROOT} && (git checkout origin/${TRELLIS_CONTROL_VERSION} || git checkout ${TRELLIS_CONTROL_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200139 if ! (cd ${TRELLIS_CONTROL_ROOT} && git fetch ${TRELLIS_CONTROL_REPO} ${TRELLIS_CONTROL_VERSION} && git checkout FETCH_HEAD); then \
140 echo "Unable to fetch the changes from the trellis-control repository"; \
141 fi \
142 fi
pierventre16709162020-07-16 20:48:24 +0200143
144trellis-control-build: mvn_settings.xml local-apps trellis-control ## : Builds trellis-control using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200145 @./app-build.sh $@
146
pierventre16709162020-07-16 20:48:24 +0200147trellis-t3: ## : Checkout trellis-t3 code
148 if [ ! -d "trellis-t3" ]; then \
pierventre83611422020-08-14 22:53:15 +0200149 git clone ${TRELLIS_T3_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200150 fi
pierventre83611422020-08-14 22:53:15 +0200151
152 @modified=$$(cd ${TRELLIS_T3_ROOT} && git status --porcelain); \
153 if [ ! -z "$${modified}" ]; then \
154 echo "Unable to checkout, you have pending changes in trellis-t3 repository"; \
155 exit 1; \
156 fi
157
pierventre3b5f9f12020-10-22 16:24:34 +0200158 cd ${TRELLIS_T3_ROOT} && git remote update
159
160 if ! (cd ${TRELLIS_T3_ROOT} && (git checkout origin/${TRELLIS_T3_VERSION} || git checkout ${TRELLIS_T3_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200161 if ! (cd ${TRELLIS_T3_ROOT} && git fetch ${TRELLIS_T3_REPO} ${TRELLIS_T3_VERSION} && git checkout FETCH_HEAD); then \
162 echo "Unable to fetch the changes from the trellis-t3 repository"; \
163 fi \
164 fi
pierventre16709162020-07-16 20:48:24 +0200165
166trellis-t3-build: mvn_settings.xml local-apps trellis-t3 ## : Builds trellis-t3 using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200167 @./app-build.sh $@
168
pierventre16709162020-07-16 20:48:24 +0200169up4: ## : Checkout up4 code
170 if [ ! -d "up4" ]; then \
171 git clone ${UP4_REPO}; \
172 fi
pierventre83611422020-08-14 22:53:15 +0200173
174 @modified=$$(cd ${UP4_ROOT} && git status --porcelain); \
175 if [ ! -z "$${modified}" ]; then \
176 echo "Unable to checkout, you have pending changes in up4 repository"; \
177 exit 1; \
178 fi
179
pierventre3b5f9f12020-10-22 16:24:34 +0200180 cd ${UP4_ROOT} && git remote update
181
182 if ! (cd ${UP4_ROOT} && (git checkout origin/${UP4_VERSION} || git checkout ${UP4_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200183 if ! (cd ${UP4_ROOT} && git fetch ${UP4_REPO} ${UP4_VERSION} && git checkout FETCH_HEAD); then \
184 echo "Unable to fetch the changes from the up4 repository"; \
185 exit 1; \
186 fi \
187 fi
pierventre16709162020-07-16 20:48:24 +0200188
pierventref33fc112020-07-30 12:55:54 +0200189up4-build: mvn_settings.xml local-apps up4 ## : Builds up4 using local app
pierventre83611422020-08-14 22:53:15 +0200190 @./app-build.sh $@
191
pierventref33fc112020-07-30 12:55:54 +0200192fabric-tna: ## : Checkout fabric-tna code
193 if [ ! -d "fabric-tna" ]; then \
194 git clone ${FABRIC_TNA_REPO}; \
195 fi
pierventre83611422020-08-14 22:53:15 +0200196
197 @modified=$$(cd ${FABRIC_TNA_ROOT} && git status --porcelain); \
198 if [ ! -z "$${modified}" ]; then \
199 echo "Unable to checkout, you have pending changes in fabric-tna repository"; \
200 exit 1; \
201 fi
202
pierventre3b5f9f12020-10-22 16:24:34 +0200203 cd ${FABRIC_TNA_ROOT} && git remote update
204
205 if ! (cd ${FABRIC_TNA_ROOT} && (git checkout origin/${FABRIC_TNA_VERSION} || git checkout ${FABRIC_TNA_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200206 if ! (cd ${FABRIC_TNA_ROOT} && git fetch ${FABRIC_TNA_REPO} ${FABRIC_TNA_VERSION} && git checkout FETCH_HEAD); then \
207 echo "Unable to fetch the changes from the fabric-tna repository"; \
208 exit 1; \
209 fi \
210 fi
pierventref33fc112020-07-30 12:55:54 +0200211
212fabric-tna-build: mvn_settings.xml local-apps fabric-tna ## : Builds fabric-tna using local app
pierventre83611422020-08-14 22:53:15 +0200213 @./app-build.sh $@
214
pierventre8bd63502021-04-12 12:34:23 +0200215apps: trellis-control trellis-t3 up4 fabric-tna ## : downloads commits, files, and refs from remotes
pierventre83611422020-08-14 22:53:15 +0200216
pierventre8bd63502021-04-12 12:34:23 +0200217apps-build: trellis-control-build trellis-t3-build up4-build fabric-tna-build ## : Build the onos apps
pierventref33fc112020-07-30 12:55:54 +0200218
pierventre2c7a4db2020-06-26 21:24:00 +0200219onos: ## : Checkout onos code
pierventre2c7a4db2020-06-26 21:24:00 +0200220 if [ ! -d "onos" ]; then \
221 git clone https://gerrit.onosproject.org/onos; \
222 fi
pierventre2c7a4db2020-06-26 21:24:00 +0200223
pierventre83611422020-08-14 22:53:15 +0200224 @modified=$$(cd ${ONOS_ROOT} && git status --porcelain); \
225 if [ ! -z "$${modified}" ]; then \
226 echo "Unable to checkout, you have pending changes in onos repository"; \
227 exit 1; \
228 fi
229
pierventre3b5f9f12020-10-22 16:24:34 +0200230 cd ${ONOS_ROOT} && git remote update
231
pierventre83611422020-08-14 22:53:15 +0200232 # In case of failure, we do not proceed because we cannot build with mvn
pierventre3b5f9f12020-10-22 16:24:34 +0200233 if ! (cd ${ONOS_ROOT} && (git checkout origin/${ONOS_VERSION} || git checkout ${ONOS_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200234 if ! (cd ${ONOS_ROOT} && git fetch ${ONOS_REPO} ${ONOS_VERSION} && git checkout FETCH_HEAD); then \
235 echo "Unable to fetch the changes from the onos repository"; \
236 exit 1; \
237 fi \
238 fi
pierventred9cb7292020-07-31 00:01:47 +0200239
pierventref03097a2020-07-15 18:49:05 +0200240onos-build: onos ## : Builds the tost-onos docker image
pierventre7fdd3602021-05-05 10:54:38 +0200241ifeq ($(PROFILER),true)
242 # profiler enabled
243 cd ${ONOS_ROOT} && \
244 . tools/build/envDefaults && \
245 docker build . -t ${ONOS_IMAGENAME} \
246 --build-arg PROFILE=${ONOS_PROFILE} \
247 --build-arg ONOS_YOURKIT=${ONOS_YOURKIT} \
248 -f tools/dev/Dockerfile-yourkit
249else
250 # profiler not enabled
pierventre2c7a4db2020-06-26 21:24:00 +0200251 cd ${ONOS_ROOT} && \
252 . tools/build/envDefaults && \
253 docker build . -t ${ONOS_IMAGENAME} \
254 --build-arg PROFILE=${ONOS_PROFILE}
pierventre7fdd3602021-05-05 10:54:38 +0200255endif
pierventre2c7a4db2020-06-26 21:24:00 +0200256
pierventre16709162020-07-16 20:48:24 +0200257tost-build: ## : Builds the tost docker image
258 docker build $(DOCKER_BUILD_ARGS) \
259 -t ${TOST_IMAGENAME} \
pierventre7fdd3602021-05-05 10:54:38 +0200260 --build-arg DOCKER_TAG="${DOCKER_TAG}${DOCKER_TAG_PROFILER}${DOCKER_TAG_BUILD_DATE}" \
pierventre16709162020-07-16 20:48:24 +0200261 --build-arg LOCAL_APPS=${LOCAL_APPS} \
262 --build-arg KARAF_VERSION=${KARAF_VERSION} \
pierventre7fdd3602021-05-05 10:54:38 +0200263 --build-arg org_label_schema_version="${DOCKER_TAG}${DOCKER_TAG_PROFILER}${DOCKER_TAG_BUILD_DATE}" \
pierventre16709162020-07-16 20:48:24 +0200264 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
265 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
266 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
pierventredd900102020-11-06 19:23:41 +0100267 --build-arg org_onosproject_onos_version="$(shell cd ${ONOS_ROOT} && git rev-parse HEAD)"\
268 --build-arg org_onosproject_trellis_control_version="$(shell cd ${TRELLIS_CONTROL_ROOT} && git rev-parse HEAD)"\
269 --build-arg org_onosproject_trellis_t3_version="$(shell cd ${TRELLIS_T3_ROOT} && git rev-parse HEAD)"\
pierventredd900102020-11-06 19:23:41 +0100270 --build-arg org_omecproject_up4_version="$(shell cd ${UP4_ROOT} && git rev-parse HEAD)"\
pierventredd900102020-11-06 19:23:41 +0100271 --build-arg org_stratumproject_fabric_tna_version="$(shell cd ${FABRIC_TNA_ROOT} && git rev-parse HEAD)"\
pierventre16709162020-07-16 20:48:24 +0200272 -f Dockerfile.tost .
273
pierventref03097a2020-07-15 18:49:05 +0200274onos-push: ## : Pushes the tost-onos docker image to an external repository
pierventre2c7a4db2020-06-26 21:24:00 +0200275 docker push ${ONOS_IMAGENAME}
276
pierventre16709162020-07-16 20:48:24 +0200277tost-push: ## : Pushes the tost docker image to an external repository
278 docker push ${TOST_IMAGENAME}
pierventre2c7a4db2020-06-26 21:24:00 +0200279
pierventref03097a2020-07-15 18:49:05 +0200280# Used for CI job
pierventre83611422020-08-14 22:53:15 +0200281docker-build: check-scripts onos-build apps-build tost-build ## : Builds the tost image
pierventre2c7a4db2020-06-26 21:24:00 +0200282
pierventref03097a2020-07-15 18:49:05 +0200283# User for CD job
pierventre16709162020-07-16 20:48:24 +0200284docker-push: tost-push ## : Pushes the tost image
pierventref03097a2020-07-15 18:49:05 +0200285
pierventre16709162020-07-16 20:48:24 +0200286clean: ## : Deletes any locally copied files or artifacts
287 rm -rf ${ONOS_ROOT}
288 rm -rf ${TRELLIS_CONTROL_ROOT}
289 rm -rf ${TRELLIS_T3_ROOT}
pierventre16709162020-07-16 20:48:24 +0200290 rm -rf ${UP4_ROOT}
pierventref33fc112020-07-30 12:55:54 +0200291 rm -rf ${FABRIC_TNA_ROOT}
pierventre16709162020-07-16 20:48:24 +0200292 rm -rf ${LOCAL_APPS}
293 rm -rf .m2
294 rm -rf mvn_settings.xml
pierventre2c7a4db2020-06-26 21:24:00 +0200295
296# end file