blob: fe0d932f8568e85e47a0ac444523a81ebd411d38 [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 ?=
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
pierventredd900102020-11-06 19:23:41 +010041ifeq ($(DOCKER_TAG),stable)
pierventre83611422020-08-14 22:53:15 +020042# Includes the default ("working") versions of each component
pierventredd900102020-11-06 19:23:41 +010043 include ./Makefile.vars.stable
44else ifeq ($(DOCKER_TAG),master)
45# Includes the master versions of each component
46 include ./Makefile.vars.master
47else
48 $(error You must define properly the DOCKER_TAG variable)
49endif
50
pierventre83611422020-08-14 22:53:15 +020051
52# Shellcheck related
53SHELLCHECK_TAG=v0.7.1
54SHELLCHECK_IMAGE=koalaman/shellcheck:${SHELLCHECK_TAG}
55
pierventre16709162020-07-16 20:48:24 +020056# ONOS related
pierventredd900102020-11-06 19:23:41 +010057ONOS_IMAGENAME := tost-onos:${DOCKER_TAG}${DOCKER_TAG_BUILD_DATE}
pierventre16709162020-07-16 20:48:24 +020058export ONOS_ROOT := $(shell pwd)/onos
pierventre83611422020-08-14 22:53:15 +020059ONOS_REPO := https://gerrit.onosproject.org/onos
pierventre16709162020-07-16 20:48:24 +020060ONOS_PROFILE := "tost"
61KARAF_VERSION := 4.2.9
pierventre2c7a4db2020-06-26 21:24:00 +020062
pierventre16709162020-07-16 20:48:24 +020063# TOST related
pierventredd900102020-11-06 19:23:41 +010064TOST_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}tost:${DOCKER_TAG}${DOCKER_TAG_BUILD_DATE}
pierventre83611422020-08-14 22:53:15 +020065export LOCAL_APPS := local-apps
pierventre16709162020-07-16 20:48:24 +020066
67# Trellis-Control related
pierventre83611422020-08-14 22:53:15 +020068export TRELLIS_CONTROL_ROOT := $(shell pwd)/trellis-control
69export TRELLIS_CONTROL_REPO := https://gerrit.onosproject.org/trellis-control
pierventre16709162020-07-16 20:48:24 +020070
71# Trellis-T3 related
pierventre83611422020-08-14 22:53:15 +020072export TRELLIS_T3_ROOT := $(shell pwd)/trellis-t3
73export TRELLIS_T3_REPO := https://gerrit.onosproject.org/trellis-t3
pierventre16709162020-07-16 20:48:24 +020074
pierventre16709162020-07-16 20:48:24 +020075# Up4 related
pierventre83611422020-08-14 22:53:15 +020076export UP4_ROOT := $(shell pwd)/up4
pierventre0b6a9c32020-10-02 11:32:54 +020077export UP4_REPO := git@github.com:omec-project/up4.git
pierventre16709162020-07-16 20:48:24 +020078
79# Kafka-onos related
pierventre83611422020-08-14 22:53:15 +020080export KAFKA_ONOS_ROOT := $(shell pwd)/kafka-onos
81export KAFKA_ONOS_REPO := https://gerrit.opencord.org/kafka-onos
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
Carmelo Cascone10d7a862021-02-04 15:53:58 -080087.PHONY: onos trellis-control trellis-t3 up4 kafka-onos 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"
104 @echo "KAFKA_ONOS_VERSION : Override to use a specific branch/commit/tag/release to build the image"
105 @echo "FABRIC_TNA_VERSION : Override to use a specific branch/commit/tag/release to build the image"
pierventre2c7a4db2020-06-26 21:24:00 +0200106 @echo ""
pierventredd900102020-11-06 19:23:41 +0100107 @echo "'Makefile.vars.stable' defines the stable values for '*_VERSION' variables".
108 @echo "'Makefile.vars.master' defines the tip values for '*_VERSION' variables".
pierventref33fc112020-07-30 12:55:54 +0200109 @echo ""
pierventre2c7a4db2020-06-26 21:24:00 +0200110
111## Make targets
112
pierventre83611422020-08-14 22:53:15 +0200113check-scripts: ## : Provides warnings and suggestions for bash/sh shell scripts
114 # Fail if any of these files have warnings, exclude sed replacement warnings
115 docker run --rm -v "${PWD}:/mnt" ${SHELLCHECK_IMAGE} *.sh -e SC2001
116
pierventre16709162020-07-16 20:48:24 +0200117mvn_settings.xml: mvn_settings.sh ## : Builds mvn_settings file for proxy
118 @./$<
119
120local-apps: ## : Creates the folder that will host the oar file
121 mkdir -p ${LOCAL_APPS}/
122
123trellis-control: ## : Checkout trellis-control code
124 # Clones trellis-control if it does not exist
125 if [ ! -d "trellis-control" ]; then \
pierventre83611422020-08-14 22:53:15 +0200126 git clone ${TRELLIS_CONTROL_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200127 fi
pierventre83611422020-08-14 22:53:15 +0200128
129 # Pending changes - do not proceed
130 @modified=$$(cd ${TRELLIS_CONTROL_ROOT} && git status --porcelain); \
131 if [ ! -z "$${modified}" ]; then \
132 echo "Unable to checkout, you have pending changes in trellis-control repository"; \
133 exit 1; \
134 fi
135
pierventre3b5f9f12020-10-22 16:24:34 +0200136 # Updates the repo and avoids any stale branches
137 cd ${TRELLIS_CONTROL_ROOT} && git remote update
138
pierventre0b6a9c32020-10-02 11:32:54 +0200139 # Try the git checkout first otherwise we download the review
pierventre3b5f9f12020-10-22 16:24:34 +0200140 if ! (cd ${TRELLIS_CONTROL_ROOT} && (git checkout origin/${TRELLIS_CONTROL_VERSION} || git checkout ${TRELLIS_CONTROL_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200141 if ! (cd ${TRELLIS_CONTROL_ROOT} && git fetch ${TRELLIS_CONTROL_REPO} ${TRELLIS_CONTROL_VERSION} && git checkout FETCH_HEAD); then \
142 echo "Unable to fetch the changes from the trellis-control repository"; \
143 fi \
144 fi
pierventre16709162020-07-16 20:48:24 +0200145
146trellis-control-build: mvn_settings.xml local-apps trellis-control ## : Builds trellis-control using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200147 @./app-build.sh $@
148
pierventre16709162020-07-16 20:48:24 +0200149trellis-t3: ## : Checkout trellis-t3 code
150 if [ ! -d "trellis-t3" ]; then \
pierventre83611422020-08-14 22:53:15 +0200151 git clone ${TRELLIS_T3_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200152 fi
pierventre83611422020-08-14 22:53:15 +0200153
154 @modified=$$(cd ${TRELLIS_T3_ROOT} && git status --porcelain); \
155 if [ ! -z "$${modified}" ]; then \
156 echo "Unable to checkout, you have pending changes in trellis-t3 repository"; \
157 exit 1; \
158 fi
159
pierventre3b5f9f12020-10-22 16:24:34 +0200160 cd ${TRELLIS_T3_ROOT} && git remote update
161
162 if ! (cd ${TRELLIS_T3_ROOT} && (git checkout origin/${TRELLIS_T3_VERSION} || git checkout ${TRELLIS_T3_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200163 if ! (cd ${TRELLIS_T3_ROOT} && git fetch ${TRELLIS_T3_REPO} ${TRELLIS_T3_VERSION} && git checkout FETCH_HEAD); then \
164 echo "Unable to fetch the changes from the trellis-t3 repository"; \
165 fi \
166 fi
pierventre16709162020-07-16 20:48:24 +0200167
168trellis-t3-build: mvn_settings.xml local-apps trellis-t3 ## : Builds trellis-t3 using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200169 @./app-build.sh $@
170
pierventre16709162020-07-16 20:48:24 +0200171up4: ## : Checkout up4 code
172 if [ ! -d "up4" ]; then \
173 git clone ${UP4_REPO}; \
174 fi
pierventre83611422020-08-14 22:53:15 +0200175
176 @modified=$$(cd ${UP4_ROOT} && git status --porcelain); \
177 if [ ! -z "$${modified}" ]; then \
178 echo "Unable to checkout, you have pending changes in up4 repository"; \
179 exit 1; \
180 fi
181
pierventre3b5f9f12020-10-22 16:24:34 +0200182 cd ${UP4_ROOT} && git remote update
183
184 if ! (cd ${UP4_ROOT} && (git checkout origin/${UP4_VERSION} || git checkout ${UP4_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200185 if ! (cd ${UP4_ROOT} && git fetch ${UP4_REPO} ${UP4_VERSION} && git checkout FETCH_HEAD); then \
186 echo "Unable to fetch the changes from the up4 repository"; \
187 exit 1; \
188 fi \
189 fi
pierventre16709162020-07-16 20:48:24 +0200190
pierventref33fc112020-07-30 12:55:54 +0200191up4-build: mvn_settings.xml local-apps up4 ## : Builds up4 using local app
pierventre83611422020-08-14 22:53:15 +0200192 @./app-build.sh $@
193
pierventre16709162020-07-16 20:48:24 +0200194kafka-onos: ## : Checkout kafka-onos code
195 if [ ! -d "kafka-onos" ]; then \
pierventre83611422020-08-14 22:53:15 +0200196 git clone ${KAFKA_ONOS_REPO}; \
pierventre16709162020-07-16 20:48:24 +0200197 fi
pierventre83611422020-08-14 22:53:15 +0200198
199 @modified=$$(cd ${KAFKA_ONOS_ROOT} && git status --porcelain); \
200 if [ ! -z "$${modified}" ]; then \
201 echo "Unable to checkout, you have pending changes in kafka-onos repository"; \
202 exit 1; \
203 fi
204
pierventre3b5f9f12020-10-22 16:24:34 +0200205 cd ${KAFKA_ONOS_ROOT} && git remote update
206
207 if ! (cd ${KAFKA_ONOS_ROOT} && (git checkout origin/${KAFKA_ONOS_VERSION} || git checkout ${KAFKA_ONOS_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200208 if ! (cd ${KAFKA_ONOS_ROOT} && git fetch ${KAFKA_ONOS_REPO} ${KAFKA_ONOS_VERSION} && git checkout FETCH_HEAD); then \
209 echo "Unable to fetch the changes from the kafka-onos repository"; \
210 fi \
211 fi
pierventre16709162020-07-16 20:48:24 +0200212
213kafka-onos-build: mvn_settings.xml local-apps kafka-onos ## : Builds kafka-onos using local app or mvn
pierventre83611422020-08-14 22:53:15 +0200214 @./app-build.sh $@
215
pierventref33fc112020-07-30 12:55:54 +0200216fabric-tna: ## : Checkout fabric-tna code
217 if [ ! -d "fabric-tna" ]; then \
218 git clone ${FABRIC_TNA_REPO}; \
219 fi
pierventre83611422020-08-14 22:53:15 +0200220
221 @modified=$$(cd ${FABRIC_TNA_ROOT} && git status --porcelain); \
222 if [ ! -z "$${modified}" ]; then \
223 echo "Unable to checkout, you have pending changes in fabric-tna repository"; \
224 exit 1; \
225 fi
226
pierventre3b5f9f12020-10-22 16:24:34 +0200227 cd ${FABRIC_TNA_ROOT} && git remote update
228
229 if ! (cd ${FABRIC_TNA_ROOT} && (git checkout origin/${FABRIC_TNA_VERSION} || git checkout ${FABRIC_TNA_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200230 if ! (cd ${FABRIC_TNA_ROOT} && git fetch ${FABRIC_TNA_REPO} ${FABRIC_TNA_VERSION} && git checkout FETCH_HEAD); then \
231 echo "Unable to fetch the changes from the fabric-tna repository"; \
232 exit 1; \
233 fi \
234 fi
pierventref33fc112020-07-30 12:55:54 +0200235
236fabric-tna-build: mvn_settings.xml local-apps fabric-tna ## : Builds fabric-tna using local app
pierventre83611422020-08-14 22:53:15 +0200237 @./app-build.sh $@
238
Carmelo Cascone10d7a862021-02-04 15:53:58 -0800239apps: trellis-control trellis-t3 up4 kafka-onos fabric-tna ## : downloads commits, files, and refs from remotes
pierventre83611422020-08-14 22:53:15 +0200240
Carmelo Cascone10d7a862021-02-04 15:53:58 -0800241apps-build: trellis-control-build trellis-t3-build up4-build kafka-onos-build fabric-tna-build ## : Build the onos apps
pierventref33fc112020-07-30 12:55:54 +0200242
pierventre2c7a4db2020-06-26 21:24:00 +0200243onos: ## : Checkout onos code
pierventre2c7a4db2020-06-26 21:24:00 +0200244 if [ ! -d "onos" ]; then \
245 git clone https://gerrit.onosproject.org/onos; \
246 fi
pierventre2c7a4db2020-06-26 21:24:00 +0200247
pierventre83611422020-08-14 22:53:15 +0200248 @modified=$$(cd ${ONOS_ROOT} && git status --porcelain); \
249 if [ ! -z "$${modified}" ]; then \
250 echo "Unable to checkout, you have pending changes in onos repository"; \
251 exit 1; \
252 fi
253
pierventre3b5f9f12020-10-22 16:24:34 +0200254 cd ${ONOS_ROOT} && git remote update
255
pierventre83611422020-08-14 22:53:15 +0200256 # In case of failure, we do not proceed because we cannot build with mvn
pierventre3b5f9f12020-10-22 16:24:34 +0200257 if ! (cd ${ONOS_ROOT} && (git checkout origin/${ONOS_VERSION} || git checkout ${ONOS_VERSION})); then \
pierventre83611422020-08-14 22:53:15 +0200258 if ! (cd ${ONOS_ROOT} && git fetch ${ONOS_REPO} ${ONOS_VERSION} && git checkout FETCH_HEAD); then \
259 echo "Unable to fetch the changes from the onos repository"; \
260 exit 1; \
261 fi \
262 fi
pierventred9cb7292020-07-31 00:01:47 +0200263
pierventref03097a2020-07-15 18:49:05 +0200264onos-build: onos ## : Builds the tost-onos docker image
pierventre2c7a4db2020-06-26 21:24:00 +0200265 # Set some env variables
266 cd ${ONOS_ROOT} && \
267 . tools/build/envDefaults && \
268 docker build . -t ${ONOS_IMAGENAME} \
269 --build-arg PROFILE=${ONOS_PROFILE}
270
pierventre16709162020-07-16 20:48:24 +0200271tost-build: ## : Builds the tost docker image
272 docker build $(DOCKER_BUILD_ARGS) \
273 -t ${TOST_IMAGENAME} \
pierventredd900102020-11-06 19:23:41 +0100274 --build-arg DOCKER_TAG="${DOCKER_TAG}${DOCKER_TAG_BUILD_DATE}" \
pierventre16709162020-07-16 20:48:24 +0200275 --build-arg LOCAL_APPS=${LOCAL_APPS} \
276 --build-arg KARAF_VERSION=${KARAF_VERSION} \
pierventredd900102020-11-06 19:23:41 +0100277 --build-arg org_label_schema_version="${DOCKER_TAG}${DOCKER_TAG_BUILD_DATE}" \
pierventre16709162020-07-16 20:48:24 +0200278 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
279 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
280 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
pierventredd900102020-11-06 19:23:41 +0100281 --build-arg org_onosproject_onos_version="$(shell cd ${ONOS_ROOT} && git rev-parse HEAD)"\
282 --build-arg org_onosproject_trellis_control_version="$(shell cd ${TRELLIS_CONTROL_ROOT} && git rev-parse HEAD)"\
283 --build-arg org_onosproject_trellis_t3_version="$(shell cd ${TRELLIS_T3_ROOT} && git rev-parse HEAD)"\
pierventredd900102020-11-06 19:23:41 +0100284 --build-arg org_omecproject_up4_version="$(shell cd ${UP4_ROOT} && git rev-parse HEAD)"\
285 --build-arg org_opencord_kafka_onos_version="$(shell cd ${KAFKA_ONOS_ROOT} && git rev-parse HEAD)"\
286 --build-arg org_stratumproject_fabric_tna_version="$(shell cd ${FABRIC_TNA_ROOT} && git rev-parse HEAD)"\
pierventre16709162020-07-16 20:48:24 +0200287 -f Dockerfile.tost .
288
pierventref03097a2020-07-15 18:49:05 +0200289onos-push: ## : Pushes the tost-onos docker image to an external repository
pierventre2c7a4db2020-06-26 21:24:00 +0200290 docker push ${ONOS_IMAGENAME}
291
pierventre16709162020-07-16 20:48:24 +0200292tost-push: ## : Pushes the tost docker image to an external repository
293 docker push ${TOST_IMAGENAME}
pierventre2c7a4db2020-06-26 21:24:00 +0200294
pierventref03097a2020-07-15 18:49:05 +0200295# Used for CI job
pierventre83611422020-08-14 22:53:15 +0200296docker-build: check-scripts onos-build apps-build tost-build ## : Builds the tost image
pierventre2c7a4db2020-06-26 21:24:00 +0200297
pierventref03097a2020-07-15 18:49:05 +0200298# User for CD job
pierventre16709162020-07-16 20:48:24 +0200299docker-push: tost-push ## : Pushes the tost image
pierventref03097a2020-07-15 18:49:05 +0200300
pierventre16709162020-07-16 20:48:24 +0200301clean: ## : Deletes any locally copied files or artifacts
302 rm -rf ${ONOS_ROOT}
303 rm -rf ${TRELLIS_CONTROL_ROOT}
304 rm -rf ${TRELLIS_T3_ROOT}
pierventre16709162020-07-16 20:48:24 +0200305 rm -rf ${UP4_ROOT}
306 rm -rf ${KAFKA_ONOS_ROOT}
pierventref33fc112020-07-30 12:55:54 +0200307 rm -rf ${FABRIC_TNA_ROOT}
pierventre16709162020-07-16 20:48:24 +0200308 rm -rf ${LOCAL_APPS}
309 rm -rf .m2
310 rm -rf mvn_settings.xml
pierventre2c7a4db2020-06-26 21:24:00 +0200311
312# end file