blob: 15079014e646ed8ba912e134275088bd8c0fc646 [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# -----------------------------------------------------------------------
Joey Armstrong50fb2522024-08-26 14:04:46 -040093# Intent: Construct docker command passing in mounts.
94# To override, declare PROTOC_SH := $(call ) in Makefile
95# -----------------------------------------------------------------------
96# Usage:
97# docker-argv-mounts += -v ${CURDIR}:$(protoc-sh-docker-mount)
98# docker-argv-mounts += --workdir $(protoc-sh-docker-mount)
99# PROTOC_SH := $(call get-cmd-docker-argv-protoc-sh,docker-argv-mounts)
100# -----------------------------------------------------------------------
101get-cmd-docker-argv-protoc-sh =\
102 $(strip \
103 $(foreach argv,$(1),\
104 $(docker-run-is) $(if $(argv),$($(argv))) $(vee-citools)-protoc sh -c \
105 )\
106)
107
108# -----------------------------------------------------------------------
109# Intent: Original get-cmd-docker library function.
110# - conditional mount: use -v or --workdir
111# - See Also: get-cmd-docker-argv-protoc-sh() for generalized mounts
112# -----------------------------------------------------------------------
113# Usage: PROTOC_SH := $(call get-cmd-docker-argv-protoc-sh)
Joey Armstrongf128de82023-09-08 17:05:18 -0400114# -----------------------------------------------------------------------
115get-cmd-docker-protoc-sh =\
116 $(strip \
117 $(docker-run-is) \
118 $(if $(protc-sh-docker-mount), \
119 -v ${CURDIR}:$(protoc-sh-docker-mount) \
120 --workdir=$(protoc-sh-docker-mount) \
121 ) \
122 $(vee-citools)-protoc \
123 sh -c \
124 )
125PROTOC_SH ?= $(call get-cmd-docker-protoc-sh)
Joey Armstrong86218422023-05-09 12:24:44 -0400126
Joey Armstrongf128de82023-09-08 17:05:18 -0400127## -----------------------------------------------------------------------
128## Coverage report: junit
129## -----------------------------------------------------------------------
130## Usage: GO_JUNIT_REPORT ?= $(call get-go-junit-report-cmd)
131## -----------------------------------------------------------------------
132get-go-junit-report-cmd =\
133 $(strip \
134 $(docker-run) \
135 -v ${CURDIR}:/app \
136 -i $(vee-citools)-go-junit-report go-junit-report \
137 )
138GO_JUNIT_REPORT ?= $(call get-go-junit-report-cmd)
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400139
Joey Armstrongf128de82023-09-08 17:05:18 -0400140## -----------------------------------------------------------------------
141## Coverage report: cobertura
142## -----------------------------------------------------------------------
143## Usage: GOCOVER_COBERTURA ?= $(call get-docker-gocover-cobertura-cmd)
144## -----------------------------------------------------------------------
145get-docker-go-cobertura-cmd =\
146 $(strip \
147 $(docker-run)\
148 -v ${CURDIR}:$(go-cobertura-docker-mount)\
149 -i $(vee-citools)-gocover-cobertura gocover-cobertura\
150 )
151GOCOVER_COBERTURA ?= $(call get-docker-go-cobertura-cmd)
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400152
Joey Armstrongf128de82023-09-08 17:05:18 -0400153## -----------------------------------------------------------------------
154##
155## -----------------------------------------------------------------------
156get-cmd-docker-golangci-lint =\
157 $(strip \
158 $(docker-run-app) \
159 -v gocache:/.cache \
160 $(vee-golang)\
161 $(vee-citools)-golangci-lint\
162 golangci-lint\
163 )
164GOLANGCI_LINT ?= $(call get-cmd-docker-golangci-lint)
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400165
Joey Armstrongf128de82023-09-08 17:05:18 -0400166## -----------------------------------------------------------------------
167##
168## -----------------------------------------------------------------------
169get-docker-hadolint =\
170 $(strip \
171 $(docker-run-app) \
172 $(vee-citools)-hadolint \
173 hadolint \
174 )
175HADOLINT ?= $(call get-docker-hadolint)
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400176
Joey Armstrong86218422023-05-09 12:24:44 -0400177$(if $(DEBUG),$(warning LEAVE))
178
179# [EOF]