blob: cd1bc6bdbec5c0bab3e61e51d2d13140fac945a3 [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
18SHELL := /bin/bash -e -o pipefail
19
20# Variables
21VERSION ?= $(shell cat ./VERSION)
pierventre16709162020-07-16 20:48:24 +020022CURRENT_UID := $(shell id -u)
23CURRENT_GID := $(shell id -g)
24MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
25CURRENT_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
26LOCAL_APPS := local-apps
pierventre2c7a4db2020-06-26 21:24:00 +020027
28# Docker related
29DOCKER_REGISTRY ?=
30DOCKER_REPOSITORY ?=
31DOCKER_BUILD_ARGS ?=
32DOCKER_TAG ?= ${VERSION}
pierventre16709162020-07-16 20:48:24 +020033DOCKER_MVN_TAG := 3.6.3-openjdk-11-slim
34DOCKER_MVN_IMAGE := maven:${DOCKER_MVN_TAG}
pierventre2c7a4db2020-06-26 21:24:00 +020035
36# Docker labels. Only set ref and commit date if committed
37DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
38DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
39DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
40
41ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
42 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
43else
44 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
45endif
46
pierventre16709162020-07-16 20:48:24 +020047# ONOS related
48ONOS_VERSION ?= $(shell cat ./ONOS_VERSION)
49ONOS_DOCKER_TAG ?= ${ONOS_VERSION}
50ONOS_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}tost-onos:${ONOS_DOCKER_TAG}
51ONOS_BRANCH ?=
52ONOS_REVIEW ?=
53export ONOS_ROOT := $(shell pwd)/onos
54ONOS_PROFILE := "tost"
55KARAF_VERSION := 4.2.9
pierventre2c7a4db2020-06-26 21:24:00 +020056
pierventre16709162020-07-16 20:48:24 +020057# TOST related
58TOST_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}tost:${DOCKER_TAG}
59
60# Trellis-Control related
61TRELLIS_CONTROL_BRANCH ?=
62TRELLIS_CONTROL_REVIEW ?=
63TRELLIS_CONTROL_MVN ?=
64TRELLIS_CONTROL_ROOT := $(shell pwd)/trellis-control
65TRELLIS_CONTROL_GROUPID := org.onosproject
66TRELLIS_CONTROL_ARTIFACTID := segmentrouting-oar
67TRELLIS_CONTROL_ARTIFACT := ${TRELLIS_CONTROL_GROUPID}:${TRELLIS_CONTROL_ARTIFACTID}
68TRELLIS_CONTROL_VERSION := 3.0.0-SNAPSHOT
69
70# Trellis-T3 related
71TRELLIS_T3_BRANCH ?=
72TRELLIS_T3_REVIEW ?=
73TRELLIS_T3_MVN ?=
74TRELLIS_T3_ROOT := $(shell pwd)/trellis-t3
75TRELLIS_T3_GROUPID := org.onosproject
76TRELLIS_T3_ARTIFACTID := t3-app
77TRELLIS_T3_ARTIFACT := ${TRELLIS_T3_GROUPID}:${TRELLIS_T3_ARTIFACTID}
78TRELLIS_T3_VERSION := 3.0.0-SNAPSHOT
79
80# Fabric-Tofino related
81FABRIC_TOFINO_BRANCH ?=
82FABRIC_TOFINO_REVIEW ?=
83FABRIC_TOFINO_MVN ?=
84FABRIC_TOFINO_ROOT := $(shell pwd)/fabric-tofino
85FABRIC_TOFINO_GROUPID := org.opencord
86FABRIC_TOFINO_ARTIFACTID := fabric-tofino
87FABRIC_TOFINO_ARTIFACT := ${FABRIC_TOFINO_GROUPID}:${FABRIC_TOFINO_ARTIFACTID}
88FABRIC_TOFINO_VERSION := 1.1.1-SNAPSHOT
89FABRIC_TOFINO_TARGETS := clean fabric-spgw
90export SDE_DOCKER_IMG := opennetworking/bf-sde:9.0.0-p4c
91export P4CFLAGS := "-DS1U_SGW_PREFIX='(8w192++8w0++8w0++8w0)' -DS1U_SGW_PREFIX_LEN=8"
92
93# Up4 related
94UP4_BRANCH ?=
95OMECPROJECT_API ?=
96UP4_ROOT := $(shell pwd)/up4
97UP4_ARTIFACTID := up4-app
98UP4_VERSION := 1.0.0-SNAPSHOT
99UP4_TARGETS := _prepare_app_build
100ifeq ($(OMECPROJECT_API),)
101 UP4_REPO = https://github.com/omec-project/up4.git
102else
103 UP4_REPO = https://omecproject:${OMECPROJECT_API}@github.com/omec-project/up4.git
104endif
105
106# Kafka-onos related
107KAFKA_ONOS_BRANCH ?=
108KAKFA_ONOS_REVIEW ?=
109KAFKA_ONOS_MVN ?=
110KAFKA_ONOS_ROOT := $(shell pwd)/kafka-onos
111KAFKA_ONOS_GROUPID := org.opencord
112KAFKA_ONOS_ARTIFACTID := kafka
113KAFKA_ONOS_ARTIFACT := ${KAFKA_ONOS_GROUPID}:${KAFKA_ONOS_ARTIFACTID}
114KAFKA_ONOS_VERSION := 2.4.0-SNAPSHOT
115
116.PHONY:
117
118.SILENT: up4
pierventre2c7a4db2020-06-26 21:24:00 +0200119
120# This should to be the first and default target in this Makefile
121help: ## : Print this help
122 @echo "Usage: make [<target>]"
123 @echo "where available targets are:"
124 @echo
125 @grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \
126 | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'
127 @echo
128 @echo "Environment variables:"
pierventre16709162020-07-16 20:48:24 +0200129 @echo "ONOS_BRANCH : Define to use the following branch to build the image"
130 @echo "ONOS_REVIEW : Define to use the following review to build the image"
131 @echo "TRELLIS_CONTROL_BRANCH : Define to use the following branch to build the image"
132 @echo "TRELLIS_CONTROL_REVIEW : Define to use the following review to build the image"
133 @echo "TRELLIS_CONTROL_MVN : Define to download the app using mvn"
134 @echo "TRELLIS_T3_BRANCH : Define to use the following branch to build the image"
135 @echo "TRELLIS_T3_REVIEW : Define to use the following review to build the image"
136 @echo "TRELLIS_T3_MVN : Define to download the app using mvn"
137 @echo "FABRIC_TOFINO_BRANCH : Define to use the following branch to build the image"
138 @echo "FABRIC_TOFINO_REVIEW : Define to use the following review to build the image"
139 @echo "FABRIC_TOFINO_MVN : Define to download the app using mvn"
140 @echo "UP4_BRANCH : Define to use the following branch to build the image"
141 @echo "KAFKA_ONOS_BRANCH : Define to use the following branch to build the image"
142 @echo "KAFKA_ONOS_REVIEW : Define to use the following review to build the image"
143 @echo "KAFKA_ONOS_MVN : Define to download the app using mvn"
pierventre2c7a4db2020-06-26 21:24:00 +0200144 @echo ""
pierventre16709162020-07-16 20:48:24 +0200145 @echo "'onos' clones onos if it does not exist in the workspace."
pierventre2c7a4db2020-06-26 21:24:00 +0200146 @echo "Uses current workspace unless above vars are defined."
147 @echo ""
pierventre16709162020-07-16 20:48:24 +0200148 @echo "'trellis-control' clones trellis-control if it does not exist in the workspace."
149 @echo "Uses current workspace unless above vars are defined."
150 @echo ""
151 @echo "'trellis-t3' clones trellis-t3 if it does not exist in the workspace."
152 @echo "Uses current workspace unless above vars are defined."
153 @echo ""
154 @echo "'fabric-tofino' clones fabric-tofino if it does not exist in the workspace."
155 @echo "Uses current workspace unless above vars are defined."
156 @echo ""
157 @echo "'up4' clones up4 if it does not exist in the workspace."
158 @echo "Uses current workspace unless above vars are defined."
159 @echo ""
160 @echo "'kafka-onos' clones kafka-onos if it does not exist in the workspace."
161 @echo "Uses current workspace unless above vars are"
162 @echo ""
pierventre2c7a4db2020-06-26 21:24:00 +0200163
164## Make targets
165
pierventre16709162020-07-16 20:48:24 +0200166mvn_settings.xml: mvn_settings.sh ## : Builds mvn_settings file for proxy
167 @./$<
168
169local-apps: ## : Creates the folder that will host the oar file
170 mkdir -p ${LOCAL_APPS}/
171
172trellis-control: ## : Checkout trellis-control code
173 # Clones trellis-control if it does not exist
174 if [ ! -d "trellis-control" ]; then \
175 git clone https://gerrit.onosproject.org/trellis-control; \
176 fi
177# Both are not supported
178ifdef TRELLIS_CONTROL_BRANCH
179ifdef TRELLIS_CONTROL_REVIEW
180 @echo "Too many parameters. You cannot specify branch and review."
181 exit 1
182else
183 cd ${TRELLIS_CONTROL_ROOT} && git checkout ${TRELLIS_CONTROL_BRANCH}
184endif
185else
186ifdef TRELLIS_CONTROL_REVIEW
187 cd ${TRELLIS_CONTROL_ROOT} && git review -d ${TRELLIS_CONTROL_REVIEW}
188endif
189endif
190
191trellis-control-build: mvn_settings.xml local-apps trellis-control ## : Builds trellis-control using local app or mvn
192 # Settings are needed by both build processes - contains proxy settings and extra
193 cp mvn_settings.xml ${TRELLIS_CONTROL_ROOT}/
194ifdef TRELLIS_CONTROL_MVN
195 # Dependencies are needed only by the mvn copy - contains repo settings
196 cp dependencies.xml ${TRELLIS_CONTROL_ROOT}/
197 # Mounting the current dir allows to cache the .m2 folder that is persisted and leveraged by subsequent builds
198 docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/trellis-control ${DOCKER_MVN_IMAGE} \
199 bash -c "mvn dependency:copy -Dartifact=${TRELLIS_CONTROL_ARTIFACT}:${TRELLIS_CONTROL_VERSION}:oar \
200 -DoutputDirectory=oar/target -Dmdep.useBaseVersion=true \
201 -Dmdep.overWriteReleases=true -Dmdep.overWriteSnapshots=true -f dependencies.xml \
202 -s mvn_settings.xml; \
203 chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
204else
205 # Having the same mount file allows to reduce build time.
206 docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/trellis-control ${DOCKER_MVN_IMAGE} \
207 bash -c "mvn clean install -s mvn_settings.xml; \
208 chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
209endif
210 # Final step requires to move the oar to the folder used by the tost docker file
211 cp ${TRELLIS_CONTROL_ROOT}/oar/target/${TRELLIS_CONTROL_ARTIFACTID}-${TRELLIS_CONTROL_VERSION}.oar ${LOCAL_APPS}/
212
213trellis-t3: ## : Checkout trellis-t3 code
214 if [ ! -d "trellis-t3" ]; then \
215 git clone https://gerrit.onosproject.org/trellis-t3; \
216 fi
217ifdef TRELLIS_T3_BRANCH
218ifdef TRELLIS_T3_REVIEW
219 @echo "Too many parameters. You cannot specify branch and review."
220 exit 1
221else
222 cd ${TRELLIS_T3_ROOT} && git checkout ${TRELLIS_T3_BRANCH}
223endif
224else
225ifdef TRELLIS_T3_REVIEW
226 cd ${TRELLIS_T3_ROOT} && git review -d ${TRELLIS_T3_REVIEW}
227endif
228endif
229
230trellis-t3-build: mvn_settings.xml local-apps trellis-t3 ## : Builds trellis-t3 using local app or mvn
231 cp mvn_settings.xml ${TRELLIS_T3_ROOT}/
232ifdef TRELLIS_T3_MVN
233 cp dependencies.xml ${TRELLIS_T3_ROOT}/
234 docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/trellis-t3 ${DOCKER_MVN_IMAGE} \
235 bash -c "mvn dependency:copy -Dartifact=${TRELLIS_T3_ARTIFACT}:${TRELLIS_T3_VERSION}:oar \
236 -DoutputDirectory=app/target -Dmdep.useBaseVersion=true \
237 -Dmdep.overWriteReleases=true -Dmdep.overWriteSnapshots=true -f dependencies.xml \
238 -s mvn_settings.xml; \
239 chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
240else
241 docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/trellis-t3 ${DOCKER_MVN_IMAGE} \
242 bash -c "mvn clean install -s mvn_settings.xml; \
243 chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
244endif
245 cp ${TRELLIS_T3_ROOT}/app/target/${TRELLIS_T3_ARTIFACTID}-${TRELLIS_T3_VERSION}.oar ${LOCAL_APPS}/
246
247fabric-tofino: ## : Checkout fabric-tofino code
248 if [ ! -d "fabric-tofino" ]; then \
249 git clone https://gerrit.opencord.org/fabric-tofino; \
250 fi
251ifdef FABRIC_TOFINO_BRANCH
252ifdef FABRIC_TOFINO_REVIEW
253 @echo "Too many parameters. You cannot specify branch and review."
254 exit 1
255else
256 cd ${FABRIC_TOFINO_ROOT} && git checkout ${FABRIC_TOFINO_BRANCH}
257endif
258else
259ifdef FABRIC_TOFINO_REVIEW
260 cd ${FABRIC_TOFINO_ROOT} && git review -d ${FABRIC_TOFINO_REVIEW}
261endif
262endif
263
264fabric-tofino-build: mvn_settings.xml local-apps fabric-tofino ## : Builds fabric-tofino using local app or mvn
265 cp mvn_settings.xml ${FABRIC_TOFINO_ROOT}/
266ifdef FABRIC_TOFINO_MVN
267 cp dependencies.xml ${FABRIC_TOFINO_ROOT}/
268 docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/fabric-tofino ${DOCKER_MVN_IMAGE} \
269 bash -c "mvn dependency:copy -Dartifact=${FABRIC_TOFINO_ARTIFACT}:${FABRIC_TOFINO_VERSION}:oar \
270 -DoutputDirectory=target -Dmdep.useBaseVersion=true \
271 -Dmdep.overWriteReleases=true -Dmdep.overWriteSnapshots=true -f dependencies.xml \
272 -s mvn_settings.xml; \
273 chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
274else
275 # This workaround is temporary - typically we need to build only the pipeconf
276 cd ${FABRIC_TOFINO_ROOT} && make ${FABRIC_TOFINO_TARGETS}
277 docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/fabric-tofino ${DOCKER_MVN_IMAGE} \
278 bash -c "mvn clean install -s mvn_settings.xml; \
279 chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
280endif
281 cp ${FABRIC_TOFINO_ROOT}/target/${FABRIC_TOFINO_ARTIFACTID}-${FABRIC_TOFINO_VERSION}.oar ${LOCAL_APPS}/
282
283up4: ## : Checkout up4 code
284 if [ ! -d "up4" ]; then \
285 git clone ${UP4_REPO}; \
286 fi
287ifdef UP4_BRANCH
288 cd ${UP4_ROOT} && git checkout ${UP4_BRANCH}
289endif
290
291up4-build: mvn_settings.xml local-apps up4 ## : Builds up4 using local app or mvn
292 cp mvn_settings.xml ${UP4_ROOT}/app
293 # Copy the p4 reources inside the app before the actual build
294 cd ${UP4_ROOT} && make ${UP4_TARGETS}
295 docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/up4/app ${DOCKER_MVN_IMAGE} \
296 bash -c "mvn clean install -s mvn_settings.xml; \
297 chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
298 cp ${UP4_ROOT}/app/app/target/${UP4_ARTIFACTID}-${UP4_VERSION}.oar ${LOCAL_APPS}/
299
300kafka-onos: ## : Checkout kafka-onos code
301 if [ ! -d "kafka-onos" ]; then \
302 git clone https://gerrit.opencord.org/kafka-onos; \
303 fi
304ifdef KAFKA_ONOS_BRANCH
305ifdef KAFKA_ONOS_REVIEW
306 @echo "Too many parameters. You cannot specify branch and review."
307 exit 1
308else
309 cd ${KAFKA_ONOS_ROOT} && git checkout ${KAFKA_ONOS_BRANCH}
310endif
311else
312ifdef KAFKA_ONOS_REVIEW
313 cd ${KAFKA_ONOS_ROOT} && git review -d ${KAFKA_ONOS_REVIEW}
314endif
315endif
316
317kafka-onos-build: mvn_settings.xml local-apps kafka-onos ## : Builds kafka-onos using local app or mvn
318 cp mvn_settings.xml ${KAFKA_ONOS_ROOT}/
319ifdef KAFKA_ONOS_MVN
320 cp dependencies.xml ${KAFKA_ONOS_ROOT}/
321 docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/kafka-onos ${DOCKER_MVN_IMAGE} \
322 bash -c "mvn dependency:copy -Dartifact=${KAFKA_ONOS_ARTIFACT}:${KAFKA_ONOS_VERSION}:oar \
323 -DoutputDirectory=target -Dmdep.useBaseVersion=true \
324 -Dmdep.overWriteReleases=true -Dmdep.overWriteSnapshots=true -f dependencies.xml \
325 -s mvn_settings.xml; \
326 chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
327else
328 docker run -t --rm -v ${CURRENT_DIR}:/root -w /root/kafka-onos ${DOCKER_MVN_IMAGE} \
329 bash -c "mvn clean install -s mvn_settings.xml; \
330 chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
331endif
332 cp ${KAFKA_ONOS_ROOT}/target/${KAFKA_ONOS_ARTIFACTID}-${KAFKA_ONOS_VERSION}.oar ${LOCAL_APPS}/
333
pierventre2c7a4db2020-06-26 21:24:00 +0200334onos: ## : Checkout onos code
pierventre2c7a4db2020-06-26 21:24:00 +0200335 if [ ! -d "onos" ]; then \
336 git clone https://gerrit.onosproject.org/onos; \
337 fi
pierventre2c7a4db2020-06-26 21:24:00 +0200338ifdef ONOS_BRANCH
339ifdef ONOS_REVIEW
340 @echo "Too many parameters. You cannot specify branch and review."
341 exit 1
342else
343 cd ${ONOS_ROOT} && git checkout ${ONOS_BRANCH}
344endif
345else
346ifdef ONOS_REVIEW
347 cd ${ONOS_ROOT} && git review -d ${ONOS_REVIEW}
348endif
349endif
350
pierventref03097a2020-07-15 18:49:05 +0200351onos-build: onos ## : Builds the tost-onos docker image
pierventre2c7a4db2020-06-26 21:24:00 +0200352 # Set some env variables
353 cd ${ONOS_ROOT} && \
354 . tools/build/envDefaults && \
355 docker build . -t ${ONOS_IMAGENAME} \
356 --build-arg PROFILE=${ONOS_PROFILE}
357
pierventre16709162020-07-16 20:48:24 +0200358tost-build: ## : Builds the tost docker image
359 docker build $(DOCKER_BUILD_ARGS) \
360 -t ${TOST_IMAGENAME} \
361 --build-arg LOCAL_APPS=${LOCAL_APPS} \
362 --build-arg KARAF_VERSION=${KARAF_VERSION} \
363 --build-arg org_label_schema_version="${VERSION}" \
364 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
365 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
366 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
367 --build-arg org_onosproject_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
368 -f Dockerfile.tost .
369
pierventref03097a2020-07-15 18:49:05 +0200370onos-push: ## : Pushes the tost-onos docker image to an external repository
pierventre2c7a4db2020-06-26 21:24:00 +0200371 docker push ${ONOS_IMAGENAME}
372
pierventre16709162020-07-16 20:48:24 +0200373tost-push: ## : Pushes the tost docker image to an external repository
374 docker push ${TOST_IMAGENAME}
pierventre2c7a4db2020-06-26 21:24:00 +0200375
pierventref03097a2020-07-15 18:49:05 +0200376# Used for CI job
pierventre16709162020-07-16 20:48:24 +0200377docker-build: onos trellis-control-build trellis-t3-build kafka-onos-build fabric-tofino-build up4-build tost-build ## : Builds the tost image
pierventre2c7a4db2020-06-26 21:24:00 +0200378
pierventref03097a2020-07-15 18:49:05 +0200379# User for CD job
pierventre16709162020-07-16 20:48:24 +0200380docker-push: tost-push ## : Pushes the tost image
pierventref03097a2020-07-15 18:49:05 +0200381
pierventre16709162020-07-16 20:48:24 +0200382clean: ## : Deletes any locally copied files or artifacts
383 rm -rf ${ONOS_ROOT}
384 rm -rf ${TRELLIS_CONTROL_ROOT}
385 rm -rf ${TRELLIS_T3_ROOT}
386 rm -rf ${FABRIC_TOFINO_ROOT}
387 rm -rf ${UP4_ROOT}
388 rm -rf ${KAFKA_ONOS_ROOT}
389 rm -rf ${LOCAL_APPS}
390 rm -rf .m2
391 rm -rf mvn_settings.xml
pierventre2c7a4db2020-06-26 21:24:00 +0200392
393# end file