blob: 2bf35e682d4e59105a1188e6ddff80a0a33990c4 [file] [log] [blame]
Joey Armstrong695ba5c2023-01-20 11:17:49 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2016-2023 Open Networking Foundation (ONF) and the ONF Contributors
Matt Jeanneretc7b437c2019-05-13 12:33:08 -04004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Joey Armstrong695ba5c2023-01-20 11:17:49 -050016# -----------------------------------------------------------------------
17
18.PHONY: help
19.DEFAULT_GOAL := help
20
21TOP ?= .
22MAKEDIR ?= $(TOP)/makefiles
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040023
24# set default shell
25SHELL = bash -e -o pipefail
26
Joey Armstrong695ba5c2023-01-20 11:17:49 -050027##--------------------##
28##---] INCLUDES [---##
29##--------------------##
Joey Armstrong99a72d02023-06-09 10:26:42 -040030include config.mk
31include makefiles/include.mk
Joey Armstrong695ba5c2023-01-20 11:17:49 -050032
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040033# Variables
34VERSION ?= $(shell cat ./VERSION)
35
36## Docker related
37DOCKER_REGISTRY ?=
38DOCKER_REPOSITORY ?=
39DOCKER_BUILD_ARGS ?=
40DOCKER_TAG ?= ${VERSION}
41ONOS_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-onos:${DOCKER_TAG}
42
43## Docker labels. Only set ref and commit date if committed
44DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040045DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
Matt Jeanneret805f76e2019-05-16 16:18:26 -040046DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
47
48ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
49 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
50else
51 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
52endif
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040053
54.PHONY: docker-build
55
Matteo Scandoloc209e802021-06-07 16:59:30 +020056# For each makefile target, add ## <description> on the target line and it will be listed by 'make help'
Joey Armstrong695ba5c2023-01-20 11:17:49 -050057help :: ## Print help for each Makefile target
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040058 @echo
Joey Armstrong695ba5c2023-01-20 11:17:49 -050059 @grep --no-filename '^[[:alpha:]_-]*:.* ##' $(MAKEFILE_LIST) \
60 | sort \
61 | awk 'BEGIN {FS=":.* ## "}; {printf " %-25s : %s\n", $$1, $$2};'
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040062
63## Docker targets
64
Matteo Scandoloc209e802021-06-07 16:59:30 +020065build: docker-build ## alias for "docker-build"
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040066
Matteo Scandoloc209e802021-06-07 16:59:30 +020067local-onosapps: ## if LOCAL_ONOSAPPS=true runs the get-local-oars.sh
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040068 mkdir -p local_imports/oar
69ifdef LOCAL_ONOSAPPS
Joey Armstrong4048c1f2022-12-17 22:24:42 -050070 $(RM) -r local_imports/oar
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040071 ./get-local-oars.sh
72endif
73
Matteo Scandoloc209e802021-06-07 16:59:30 +020074docker-build: local-onosapps ## build docker image: use DOCKER_REGISTRY, DOCKER_REPOSITORY and DOCKER_TAG to customize
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040075 docker build $(DOCKER_BUILD_ARGS) \
76 -t ${ONOS_IMAGENAME} \
77 --build-arg LOCAL_ONOSAPPS=$(LOCAL_ONOSAPPS) \
78 --build-arg org_label_schema_version="${VERSION}" \
79 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
80 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
81 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
82 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
83 -f Dockerfile.voltha-onos .
84
Matteo Scandoloc209e802021-06-07 16:59:30 +020085test: ## verify that if the version is released we're not pointing to SNAPSHOT apps
86 bash tests/version-check.sh
87
88docker-push: ## push to docker registy: use DOCKER_REGISTRY, DOCKER_REPOSITORY and DOCKER_TAG to customize
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040089 docker push ${ONOS_IMAGENAME}
90
Joey Armstrong99a72d02023-06-09 10:26:42 -040091clean :: ## clean the build environment
Joey Armstrong4048c1f2022-12-17 22:24:42 -050092 $(RM) -r local_imports
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040093
94# end file