Joey Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | dc04c93 | 2024-04-01 12:14:21 -0400 | [diff] [blame] | 3 | # Copyright 2017-2024 Open Networking Foundation Contributors |
Joey Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 4 | # |
| 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 Armstrong | dc04c93 | 2024-04-01 12:14:21 -0400 | [diff] [blame] | 9 | # http:#www.apache.org/licenses/LICENSE-2.0 |
Joey Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 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 |
Joey Armstrong | dc04c93 | 2024-04-01 12:14:21 -0400 | [diff] [blame] | 15 | # 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 Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 21 | # ----------------------------------------------------------------------- |
| 22 | |
| 23 | $(if $(DEBUG),$(warning ENTER)) |
| 24 | |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 25 | # ------------------- ## |
| 26 | # ---] GLOBALS [--- ## |
| 27 | # ------------------- ## |
Joey Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 28 | VOLTHA_TOOLS_VERSION ?= 2.4.0 |
| 29 | |
Joey Armstrong | ac97b07 | 2024-08-23 14:35:21 -0400 | [diff] [blame] | 30 | # -------------------- ## |
| 31 | # ---] INCLUDES [--- ## |
| 32 | # -------------------- ## |
| 33 | # include $(onf-mk-dir)/docker/help.mk |
| 34 | |
| 35 | # ----------------------------------------------------------------------- |
| 36 | # Load per-repository config: docker mount points, etc |
| 37 | # ----------------------------------------------------------------------- |
| 38 | include $(firstword $(wildcard \ |
| 39 | $(local-mk-dir)/docker/config/include.mk \ |
| 40 | $(onf-mk-dir)/docker/config/$(--repo-name--).mk \ |
| 41 | )) |
| 42 | |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 43 | # --------------------------------- |
| 44 | # Induce error for misconfiguration |
| 45 | # --------------------------------- |
| 46 | go-cobertura-docker-mount ?= $(error go-cobertura-docker-mount= is required) |
| 47 | protoc-sh-docker-mount ?= $(error protoc-sh-docker-mount= is required) |
| 48 | |
Joey Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 49 | # --------------------------- |
| 50 | # Macros: command refactoring |
| 51 | # --------------------------- |
| 52 | docker-iam ?= --user $$(id -u):$$(id -g)# # override for local use |
| 53 | docker-run = docker run --rm $(docker-iam)# # Docker command stem |
Joey Armstrong | 7ad5c36 | 2023-07-09 19:10:16 -0400 | [diff] [blame] | 54 | docker-run-is = $(docker-run) $(is-stdin)# # Attach streams when interactive |
Joey Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 55 | docker-run-app = $(docker-run-is) -v ${CURDIR}:/app# # w/filesystem mount |
Joey Armstrong | 7ad5c36 | 2023-07-09 19:10:16 -0400 | [diff] [blame] | 56 | |
| 57 | # ----------------------------------------------------------------------- |
| 58 | # --interactive: Attach streams when stdout (fh==0) defined |
| 59 | # --tty : Always create a pseudo-tty else jenkins:docker is silent |
| 60 | # ----------------------------------------------------------------------- |
| 61 | is-stdin = $(shell test -t 0 && { echo '--interactive'; }) |
| 62 | is-stdin += --tty |
Joey Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 63 | |
Joey Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 64 | # Docker volume mounts: container:/app/release <=> localhost:{pwd}/release |
| 65 | vee-golang = -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg |
| 66 | vee-citools = voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION} |
| 67 | |
| 68 | # --------------- |
| 69 | # Tool Containers |
| 70 | # --------------- |
| 71 | docker-go-stem = $(docker-run-app) -v gocache:/.cache $(vee-golang) $(vee-citools)-golang |
| 72 | |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 73 | # ----------------------------------------------------------------------- |
| 74 | # Usage: GO := $(call get-cmd-docker-go) |
| 75 | # ----------------------------------------------------------------------- |
| 76 | get-cmd-docker-go = $(docker-go-stem) go |
| 77 | GO ?= $(call get-cmd-docker-go) |
Joey Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 78 | |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 79 | # ----------------------------------------------------------------------- |
Joey Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 80 | # Usage: GO_SH := $(call get-docker-go-sh,./my.env.temp) |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 81 | # - populate my.env.temp with shell content to pass in |
| 82 | # ----------------------------------------------------------------------- |
| 83 | get-cmd-docker-go-sh = $(docker-go-stem) $(if $(1),--env-file $(1)) sh -c |
| 84 | GO_SH ?= $(call get-cmd-docker-go-sh,./my.env.temp) |
Joey Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 85 | |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 86 | # ----------------------------------------------------------------------- |
| 87 | # Usage: PROTOC := $(call get-cmd-docker-protoc) |
| 88 | # ----------------------------------------------------------------------- |
| 89 | get-cmd-docker-protoc = $(docker-run-app) $(vee-citools)-protoc protoc |
| 90 | PROTOC ?= $(call get-cmd-docker-protoc) |
| 91 | |
| 92 | # ----------------------------------------------------------------------- |
Joey Armstrong | 50fb252 | 2024-08-26 14:04:46 -0400 | [diff] [blame] | 93 | # 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 | # ----------------------------------------------------------------------- |
| 101 | get-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 Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 114 | # ----------------------------------------------------------------------- |
| 115 | get-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 | ) |
| 125 | PROTOC_SH ?= $(call get-cmd-docker-protoc-sh) |
Joey Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 126 | |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 127 | ## ----------------------------------------------------------------------- |
| 128 | ## Coverage report: junit |
| 129 | ## ----------------------------------------------------------------------- |
| 130 | ## Usage: GO_JUNIT_REPORT ?= $(call get-go-junit-report-cmd) |
| 131 | ## ----------------------------------------------------------------------- |
| 132 | get-go-junit-report-cmd =\ |
| 133 | $(strip \ |
| 134 | $(docker-run) \ |
| 135 | -v ${CURDIR}:/app \ |
| 136 | -i $(vee-citools)-go-junit-report go-junit-report \ |
| 137 | ) |
| 138 | GO_JUNIT_REPORT ?= $(call get-go-junit-report-cmd) |
Joey Armstrong | 7ad5c36 | 2023-07-09 19:10:16 -0400 | [diff] [blame] | 139 | |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 140 | ## ----------------------------------------------------------------------- |
| 141 | ## Coverage report: cobertura |
| 142 | ## ----------------------------------------------------------------------- |
| 143 | ## Usage: GOCOVER_COBERTURA ?= $(call get-docker-gocover-cobertura-cmd) |
| 144 | ## ----------------------------------------------------------------------- |
| 145 | get-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 | ) |
| 151 | GOCOVER_COBERTURA ?= $(call get-docker-go-cobertura-cmd) |
Joey Armstrong | 7ad5c36 | 2023-07-09 19:10:16 -0400 | [diff] [blame] | 152 | |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 153 | ## ----------------------------------------------------------------------- |
| 154 | ## |
| 155 | ## ----------------------------------------------------------------------- |
| 156 | get-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 | ) |
| 164 | GOLANGCI_LINT ?= $(call get-cmd-docker-golangci-lint) |
Joey Armstrong | 7ad5c36 | 2023-07-09 19:10:16 -0400 | [diff] [blame] | 165 | |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 166 | ## ----------------------------------------------------------------------- |
| 167 | ## |
| 168 | ## ----------------------------------------------------------------------- |
| 169 | get-docker-hadolint =\ |
| 170 | $(strip \ |
| 171 | $(docker-run-app) \ |
| 172 | $(vee-citools)-hadolint \ |
| 173 | hadolint \ |
| 174 | ) |
| 175 | HADOLINT ?= $(call get-docker-hadolint) |
Joey Armstrong | 7ad5c36 | 2023-07-09 19:10:16 -0400 | [diff] [blame] | 176 | |
Joey Armstrong | 8621842 | 2023-05-09 12:24:44 -0400 | [diff] [blame] | 177 | $(if $(DEBUG),$(warning LEAVE)) |
| 178 | |
| 179 | # [EOF] |