blob: 3ff200a35ac33f685bb8dc2ed6c8df61782c78ca [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##--------------------##
30include $(MAKEDIR)/include.mk
31
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040032# Variables
33VERSION ?= $(shell cat ./VERSION)
34
35## Docker related
36DOCKER_REGISTRY ?=
37DOCKER_REPOSITORY ?=
38DOCKER_BUILD_ARGS ?=
39DOCKER_TAG ?= ${VERSION}
40ONOS_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-onos:${DOCKER_TAG}
41
42## Docker labels. Only set ref and commit date if committed
43DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040044DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
Matt Jeanneret805f76e2019-05-16 16:18:26 -040045DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
46
47ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
48 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
49else
50 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
51endif
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040052
53.PHONY: docker-build
54
Matteo Scandoloc209e802021-06-07 16:59:30 +020055# 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 -050056help :: ## Print help for each Makefile target
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040057 @echo
Joey Armstrong695ba5c2023-01-20 11:17:49 -050058 @grep --no-filename '^[[:alpha:]_-]*:.* ##' $(MAKEFILE_LIST) \
59 | sort \
60 | awk 'BEGIN {FS=":.* ## "}; {printf " %-25s : %s\n", $$1, $$2};'
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040061
62## Docker targets
63
Matteo Scandoloc209e802021-06-07 16:59:30 +020064build: docker-build ## alias for "docker-build"
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040065
Matteo Scandoloc209e802021-06-07 16:59:30 +020066local-onosapps: ## if LOCAL_ONOSAPPS=true runs the get-local-oars.sh
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040067 mkdir -p local_imports/oar
68ifdef LOCAL_ONOSAPPS
Joey Armstrong4048c1f2022-12-17 22:24:42 -050069 $(RM) -r local_imports/oar
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040070 ./get-local-oars.sh
71endif
72
Matteo Scandoloc209e802021-06-07 16:59:30 +020073docker-build: local-onosapps ## build docker image: use DOCKER_REGISTRY, DOCKER_REPOSITORY and DOCKER_TAG to customize
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040074 docker build $(DOCKER_BUILD_ARGS) \
75 -t ${ONOS_IMAGENAME} \
76 --build-arg LOCAL_ONOSAPPS=$(LOCAL_ONOSAPPS) \
77 --build-arg org_label_schema_version="${VERSION}" \
78 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
79 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
80 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
81 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
82 -f Dockerfile.voltha-onos .
83
Matteo Scandoloc209e802021-06-07 16:59:30 +020084test: ## verify that if the version is released we're not pointing to SNAPSHOT apps
85 bash tests/version-check.sh
86
87docker-push: ## push to docker registy: use DOCKER_REGISTRY, DOCKER_REPOSITORY and DOCKER_TAG to customize
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040088 docker push ${ONOS_IMAGENAME}
89
Matteo Scandoloc209e802021-06-07 16:59:30 +020090clean: ## clean the build environment
Joey Armstrong4048c1f2022-12-17 22:24:42 -050091 $(RM) -r local_imports
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040092
93# end file