blob: 1561782f23eb30cb92cbf2daba2f01755a6e56e3 [file] [log] [blame]
Joey Armstrong86218422023-05-09 12:24:44 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrongdc04c932024-04-01 12:14:21 -04003# Copyright 2017-2024 Open Networking Foundation Contributors
Joey Armstrong86218422023-05-09 12:24:44 -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#
Joey Armstrongdc04c932024-04-01 12:14:21 -04009# http:#www.apache.org/licenses/LICENSE-2.0
Joey Armstrong86218422023-05-09 12:24:44 -040010#
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
Joey Armstrongdc04c932024-04-01 12:14:21 -040015# limitations under the License.
16# -----------------------------------------------------------------------
17# SPDX-FileCopyrightText: 2017-2024 Open Networking Foundation Contributors
18# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
20# Intent:
Joey Armstrong86218422023-05-09 12:24:44 -040021# -----------------------------------------------------------------------
22
23$(if $(DEBUG),$(warning ENTER))
24
Joey Armstrongf128de82023-09-08 17:05:18 -040025# ------------------- ##
26# ---] GLOBALS [--- ##
27# ------------------- ##
Joey Armstrong86218422023-05-09 12:24:44 -040028VOLTHA_TOOLS_VERSION ?= 2.4.0
29
Joey Armstrongac97b072024-08-23 14:35:21 -040030# -------------------- ##
31# ---] INCLUDES [--- ##
32# -------------------- ##
33# include $(onf-mk-dir)/docker/help.mk
34
35# -----------------------------------------------------------------------
36# Load per-repository config: docker mount points, etc
37# -----------------------------------------------------------------------
38include $(firstword $(wildcard \
39 $(local-mk-dir)/docker/config/include.mk \
40 $(onf-mk-dir)/docker/config/$(--repo-name--).mk \
41))
42
Joey Armstrongf128de82023-09-08 17:05:18 -040043# ---------------------------------
44# Induce error for misconfiguration
45# ---------------------------------
46go-cobertura-docker-mount ?= $(error go-cobertura-docker-mount= is required)
47protoc-sh-docker-mount ?= $(error protoc-sh-docker-mount= is required)
48
Joey Armstrong86218422023-05-09 12:24:44 -040049# ---------------------------
50# Macros: command refactoring
51# ---------------------------
52docker-iam ?= --user $$(id -u):$$(id -g)# # override for local use
53docker-run = docker run --rm $(docker-iam)# # Docker command stem
Joey Armstrong7ad5c362023-07-09 19:10:16 -040054docker-run-is = $(docker-run) $(is-stdin)# # Attach streams when interactive
Joey Armstrong86218422023-05-09 12:24:44 -040055docker-run-app = $(docker-run-is) -v ${CURDIR}:/app# # w/filesystem mount
Joey Armstrong7ad5c362023-07-09 19:10:16 -040056
57# -----------------------------------------------------------------------
58# --interactive: Attach streams when stdout (fh==0) defined
59# --tty : Always create a pseudo-tty else jenkins:docker is silent
60# -----------------------------------------------------------------------
61is-stdin = $(shell test -t 0 && { echo '--interactive'; })
62is-stdin += --tty
Joey Armstrong86218422023-05-09 12:24:44 -040063
Joey Armstrong86218422023-05-09 12:24:44 -040064# Docker volume mounts: container:/app/release <=> localhost:{pwd}/release
65vee-golang = -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg
66vee-citools = voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}
67
68# ---------------
69# Tool Containers
70# ---------------
71docker-go-stem = $(docker-run-app) -v gocache:/.cache $(vee-golang) $(vee-citools)-golang
72
Joey Armstrongf128de82023-09-08 17:05:18 -040073# -----------------------------------------------------------------------
74# Usage: GO := $(call get-cmd-docker-go)
75# -----------------------------------------------------------------------
76get-cmd-docker-go = $(docker-go-stem) go
77GO ?= $(call get-cmd-docker-go)
Joey Armstrong86218422023-05-09 12:24:44 -040078
Joey Armstrongf128de82023-09-08 17:05:18 -040079# -----------------------------------------------------------------------
Joey Armstrong86218422023-05-09 12:24:44 -040080# Usage: GO_SH := $(call get-docker-go-sh,./my.env.temp)
Joey Armstrongf128de82023-09-08 17:05:18 -040081# - populate my.env.temp with shell content to pass in
82# -----------------------------------------------------------------------
83get-cmd-docker-go-sh = $(docker-go-stem) $(if $(1),--env-file $(1)) sh -c
84GO_SH ?= $(call get-cmd-docker-go-sh,./my.env.temp)
Joey Armstrong86218422023-05-09 12:24:44 -040085
Joey Armstrongf128de82023-09-08 17:05:18 -040086# -----------------------------------------------------------------------
87# Usage: PROTOC := $(call get-cmd-docker-protoc)
88# -----------------------------------------------------------------------
89get-cmd-docker-protoc = $(docker-run-app) $(vee-citools)-protoc protoc
90PROTOC ?= $(call get-cmd-docker-protoc)
91
92# -----------------------------------------------------------------------
93# Usage: PROTOC_SH := $(call get-cmd-docker-protoc-sh)
94# -----------------------------------------------------------------------
95get-cmd-docker-protoc-sh =\
96 $(strip \
97 $(docker-run-is) \
98 $(if $(protc-sh-docker-mount), \
99 -v ${CURDIR}:$(protoc-sh-docker-mount) \
100 --workdir=$(protoc-sh-docker-mount) \
101 ) \
102 $(vee-citools)-protoc \
103 sh -c \
104 )
105PROTOC_SH ?= $(call get-cmd-docker-protoc-sh)
Joey Armstrong86218422023-05-09 12:24:44 -0400106
107# get-docker-protoc-sh = $(strip )
Joey Armstrongf128de82023-09-08 17:05:18 -0400108#PROTOC_SH = $(docker-run-is)
109#ifdef protc-sh-docker-mount
110# PROTOC_SH += -v ${CURDIR}:$(protoc-sh-docker-mount)
111# PROTOC_SH += --workdir=$(protoc-sh-docker-mount)
112#endif # protoc-sh-docker-mount
113#PROTOC_SH += $(vee-citools)-protoc sh -c
Joey Armstrong86218422023-05-09 12:24:44 -0400114
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400115# Usage: GO_JUNIT_REPORT := $(call get-docker-go-junit-repo)
116# get-docker-go-junit-repo = $(docker-run-app) $(vee-citools)-go-junit-report go-junit-report
117# GO_JUNIT_REPORT ?= $(call get-docker-go-junit-repo)
118
Joey Armstrongf128de82023-09-08 17:05:18 -0400119# -----------------------------------------------------------------------
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400120# get-docker-gocover-cobertura = $(docker-run-app)/src/github.com/opencord/voltha-openolt-adapter $(vee-citools)-gocover-cobertura gocover-cobertura
121# GOCOVER_COBERTURA ?= $(call get-docker-gocover-cobertura)
122
Joey Armstrongf128de82023-09-08 17:05:18 -0400123## -----------------------------------------------------------------------
124## Coverage report: junit
125## -----------------------------------------------------------------------
126## Usage: GO_JUNIT_REPORT ?= $(call get-go-junit-report-cmd)
127## -----------------------------------------------------------------------
128get-go-junit-report-cmd =\
129 $(strip \
130 $(docker-run) \
131 -v ${CURDIR}:/app \
132 -i $(vee-citools)-go-junit-report go-junit-report \
133 )
134GO_JUNIT_REPORT ?= $(call get-go-junit-report-cmd)
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400135
Joey Armstrongf128de82023-09-08 17:05:18 -0400136## -----------------------------------------------------------------------
137## Coverage report: cobertura
138## -----------------------------------------------------------------------
139## Usage: GOCOVER_COBERTURA ?= $(call get-docker-gocover-cobertura-cmd)
140## -----------------------------------------------------------------------
141get-docker-go-cobertura-cmd =\
142 $(strip \
143 $(docker-run)\
144 -v ${CURDIR}:$(go-cobertura-docker-mount)\
145 -i $(vee-citools)-gocover-cobertura gocover-cobertura\
146 )
147GOCOVER_COBERTURA ?= $(call get-docker-go-cobertura-cmd)
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400148
Joey Armstrongf128de82023-09-08 17:05:18 -0400149## -----------------------------------------------------------------------
150##
151## -----------------------------------------------------------------------
152get-cmd-docker-golangci-lint =\
153 $(strip \
154 $(docker-run-app) \
155 -v gocache:/.cache \
156 $(vee-golang)\
157 $(vee-citools)-golangci-lint\
158 golangci-lint\
159 )
160GOLANGCI_LINT ?= $(call get-cmd-docker-golangci-lint)
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400161
Joey Armstrongf128de82023-09-08 17:05:18 -0400162## -----------------------------------------------------------------------
163##
164## -----------------------------------------------------------------------
165get-docker-hadolint =\
166 $(strip \
167 $(docker-run-app) \
168 $(vee-citools)-hadolint \
169 hadolint \
170 )
171HADOLINT ?= $(call get-docker-hadolint)
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400172
Joey Armstrong86218422023-05-09 12:24:44 -0400173$(if $(DEBUG),$(warning LEAVE))
174
175# [EOF]