blob: 958cd35a16117b75efc446767d1e1dfff1d69850 [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# Per-repository
Joey Armstrong95a52432024-04-29 15:26:18 -040026include $(onf-mk-dir)/docker/config/$(--repo-name--).mk
Joey Armstrongf128de82023-09-08 17:05:18 -040027
28# ------------------- ##
29# ---] GLOBALS [--- ##
30# ------------------- ##
Joey Armstrong86218422023-05-09 12:24:44 -040031VOLTHA_TOOLS_VERSION ?= 2.4.0
32
Joey Armstrongf128de82023-09-08 17:05:18 -040033# ---------------------------------
34# Induce error for misconfiguration
35# ---------------------------------
36go-cobertura-docker-mount ?= $(error go-cobertura-docker-mount= is required)
37protoc-sh-docker-mount ?= $(error protoc-sh-docker-mount= is required)
38
Joey Armstrong86218422023-05-09 12:24:44 -040039# ---------------------------
40# Macros: command refactoring
41# ---------------------------
42docker-iam ?= --user $$(id -u):$$(id -g)# # override for local use
43docker-run = docker run --rm $(docker-iam)# # Docker command stem
Joey Armstrong7ad5c362023-07-09 19:10:16 -040044docker-run-is = $(docker-run) $(is-stdin)# # Attach streams when interactive
Joey Armstrong86218422023-05-09 12:24:44 -040045docker-run-app = $(docker-run-is) -v ${CURDIR}:/app# # w/filesystem mount
Joey Armstrong7ad5c362023-07-09 19:10:16 -040046
47# -----------------------------------------------------------------------
48# --interactive: Attach streams when stdout (fh==0) defined
49# --tty : Always create a pseudo-tty else jenkins:docker is silent
50# -----------------------------------------------------------------------
51is-stdin = $(shell test -t 0 && { echo '--interactive'; })
52is-stdin += --tty
Joey Armstrong86218422023-05-09 12:24:44 -040053
Joey Armstrong86218422023-05-09 12:24:44 -040054# Docker volume mounts: container:/app/release <=> localhost:{pwd}/release
55vee-golang = -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg
56vee-citools = voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}
57
58# ---------------
59# Tool Containers
60# ---------------
61docker-go-stem = $(docker-run-app) -v gocache:/.cache $(vee-golang) $(vee-citools)-golang
62
Joey Armstrongf128de82023-09-08 17:05:18 -040063# -----------------------------------------------------------------------
64# Usage: GO := $(call get-cmd-docker-go)
65# -----------------------------------------------------------------------
66get-cmd-docker-go = $(docker-go-stem) go
67GO ?= $(call get-cmd-docker-go)
Joey Armstrong86218422023-05-09 12:24:44 -040068
Joey Armstrongf128de82023-09-08 17:05:18 -040069# -----------------------------------------------------------------------
Joey Armstrong86218422023-05-09 12:24:44 -040070# Usage: GO_SH := $(call get-docker-go-sh,./my.env.temp)
Joey Armstrongf128de82023-09-08 17:05:18 -040071# - populate my.env.temp with shell content to pass in
72# -----------------------------------------------------------------------
73get-cmd-docker-go-sh = $(docker-go-stem) $(if $(1),--env-file $(1)) sh -c
74GO_SH ?= $(call get-cmd-docker-go-sh,./my.env.temp)
Joey Armstrong86218422023-05-09 12:24:44 -040075
Joey Armstrongf128de82023-09-08 17:05:18 -040076# -----------------------------------------------------------------------
77# Usage: PROTOC := $(call get-cmd-docker-protoc)
78# -----------------------------------------------------------------------
79get-cmd-docker-protoc = $(docker-run-app) $(vee-citools)-protoc protoc
80PROTOC ?= $(call get-cmd-docker-protoc)
81
82# -----------------------------------------------------------------------
83# Usage: PROTOC_SH := $(call get-cmd-docker-protoc-sh)
84# -----------------------------------------------------------------------
85get-cmd-docker-protoc-sh =\
86 $(strip \
87 $(docker-run-is) \
88 $(if $(protc-sh-docker-mount), \
89 -v ${CURDIR}:$(protoc-sh-docker-mount) \
90 --workdir=$(protoc-sh-docker-mount) \
91 ) \
92 $(vee-citools)-protoc \
93 sh -c \
94 )
95PROTOC_SH ?= $(call get-cmd-docker-protoc-sh)
Joey Armstrong86218422023-05-09 12:24:44 -040096
97# get-docker-protoc-sh = $(strip )
Joey Armstrongf128de82023-09-08 17:05:18 -040098#PROTOC_SH = $(docker-run-is)
99#ifdef protc-sh-docker-mount
100# PROTOC_SH += -v ${CURDIR}:$(protoc-sh-docker-mount)
101# PROTOC_SH += --workdir=$(protoc-sh-docker-mount)
102#endif # protoc-sh-docker-mount
103#PROTOC_SH += $(vee-citools)-protoc sh -c
Joey Armstrong86218422023-05-09 12:24:44 -0400104
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400105# Usage: GO_JUNIT_REPORT := $(call get-docker-go-junit-repo)
106# get-docker-go-junit-repo = $(docker-run-app) $(vee-citools)-go-junit-report go-junit-report
107# GO_JUNIT_REPORT ?= $(call get-docker-go-junit-repo)
108
Joey Armstrongf128de82023-09-08 17:05:18 -0400109# -----------------------------------------------------------------------
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400110# get-docker-gocover-cobertura = $(docker-run-app)/src/github.com/opencord/voltha-openolt-adapter $(vee-citools)-gocover-cobertura gocover-cobertura
111# GOCOVER_COBERTURA ?= $(call get-docker-gocover-cobertura)
112
Joey Armstrongf128de82023-09-08 17:05:18 -0400113## -----------------------------------------------------------------------
114## Coverage report: junit
115## -----------------------------------------------------------------------
116## Usage: GO_JUNIT_REPORT ?= $(call get-go-junit-report-cmd)
117## -----------------------------------------------------------------------
118get-go-junit-report-cmd =\
119 $(strip \
120 $(docker-run) \
121 -v ${CURDIR}:/app \
122 -i $(vee-citools)-go-junit-report go-junit-report \
123 )
124GO_JUNIT_REPORT ?= $(call get-go-junit-report-cmd)
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400125
Joey Armstrongf128de82023-09-08 17:05:18 -0400126## -----------------------------------------------------------------------
127## Coverage report: cobertura
128## -----------------------------------------------------------------------
129## Usage: GOCOVER_COBERTURA ?= $(call get-docker-gocover-cobertura-cmd)
130## -----------------------------------------------------------------------
131get-docker-go-cobertura-cmd =\
132 $(strip \
133 $(docker-run)\
134 -v ${CURDIR}:$(go-cobertura-docker-mount)\
135 -i $(vee-citools)-gocover-cobertura gocover-cobertura\
136 )
137GOCOVER_COBERTURA ?= $(call get-docker-go-cobertura-cmd)
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400138
Joey Armstrongf128de82023-09-08 17:05:18 -0400139## -----------------------------------------------------------------------
140##
141## -----------------------------------------------------------------------
142get-cmd-docker-golangci-lint =\
143 $(strip \
144 $(docker-run-app) \
145 -v gocache:/.cache \
146 $(vee-golang)\
147 $(vee-citools)-golangci-lint\
148 golangci-lint\
149 )
150GOLANGCI_LINT ?= $(call get-cmd-docker-golangci-lint)
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400151
Joey Armstrongf128de82023-09-08 17:05:18 -0400152## -----------------------------------------------------------------------
153##
154## -----------------------------------------------------------------------
155get-docker-hadolint =\
156 $(strip \
157 $(docker-run-app) \
158 $(vee-citools)-hadolint \
159 hadolint \
160 )
161HADOLINT ?= $(call get-docker-hadolint)
Joey Armstrong7ad5c362023-07-09 19:10:16 -0400162
Joey Armstrong86218422023-05-09 12:24:44 -0400163$(if $(DEBUG),$(warning LEAVE))
164
165# [EOF]