Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
| 3 | # Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors |
| 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 | # |
| 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.d |
| 16 | # ----------------------------------------------------------------------- |
| 17 | |
| 18 | $(if $(DEBUG),$(warning ENTER)) |
| 19 | |
| 20 | # Per-repository |
| 21 | include $(ONF_MAKEDIR)/docker/config/$(--repo-name--).mk |
| 22 | |
| 23 | # ------------------- ## |
| 24 | # ---] GLOBALS [--- ## |
| 25 | # ------------------- ## |
| 26 | VOLTHA_TOOLS_VERSION ?= 2.4.0 |
| 27 | |
| 28 | # --------------------------------- |
| 29 | # Induce error for misconfiguration |
| 30 | # --------------------------------- |
| 31 | go-cobertura-docker-mount ?= $(error go-cobertura-docker-mount= is required) |
| 32 | protoc-sh-docker-mount ?= $(error protoc-sh-docker-mount= is required) |
| 33 | |
| 34 | # --------------------------- |
| 35 | # Macros: command refactoring |
| 36 | # --------------------------- |
| 37 | docker-iam ?= --user $$(id -u):$$(id -g)# # override for local use |
| 38 | docker-run = docker run --rm $(docker-iam)# # Docker command stem |
| 39 | docker-run-is = $(docker-run) $(is-stdin)# # Attach streams when interactive |
| 40 | docker-run-app = $(docker-run-is) -v ${CURDIR}:/app# # w/filesystem mount |
| 41 | |
| 42 | # ----------------------------------------------------------------------- |
| 43 | # --interactive: Attach streams when stdout (fh==0) defined |
| 44 | # --tty : Always create a pseudo-tty else jenkins:docker is silent |
| 45 | # ----------------------------------------------------------------------- |
| 46 | is-stdin = $(shell test -t 0 && { echo '--interactive'; }) |
| 47 | is-stdin += --tty |
| 48 | |
| 49 | # Docker volume mounts: container:/app/release <=> localhost:{pwd}/release |
| 50 | vee-golang = -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg |
| 51 | vee-citools = voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION} |
| 52 | |
| 53 | # --------------- |
| 54 | # Tool Containers |
| 55 | # --------------- |
| 56 | docker-go-stem = $(docker-run-app) -v gocache:/.cache $(vee-golang) $(vee-citools)-golang |
| 57 | |
| 58 | # ----------------------------------------------------------------------- |
| 59 | # Usage: GO := $(call get-cmd-docker-go) |
| 60 | # ----------------------------------------------------------------------- |
| 61 | get-cmd-docker-go = $(docker-go-stem) go |
| 62 | GO ?= $(call get-cmd-docker-go) |
| 63 | |
| 64 | # ----------------------------------------------------------------------- |
| 65 | # Usage: GO_SH := $(call get-docker-go-sh,./my.env.temp) |
| 66 | # - populate my.env.temp with shell content to pass in |
| 67 | # ----------------------------------------------------------------------- |
| 68 | get-cmd-docker-go-sh = $(docker-go-stem) $(if $(1),--env-file $(1)) sh -c |
| 69 | GO_SH ?= $(call get-cmd-docker-go-sh,./my.env.temp) |
| 70 | |
| 71 | # ----------------------------------------------------------------------- |
| 72 | # Usage: PROTOC := $(call get-cmd-docker-protoc) |
| 73 | # ----------------------------------------------------------------------- |
| 74 | get-cmd-docker-protoc = $(docker-run-app) $(vee-citools)-protoc protoc |
| 75 | PROTOC ?= $(call get-cmd-docker-protoc) |
| 76 | |
| 77 | # ----------------------------------------------------------------------- |
| 78 | # Usage: PROTOC_SH := $(call get-cmd-docker-protoc-sh) |
| 79 | # ----------------------------------------------------------------------- |
| 80 | get-cmd-docker-protoc-sh =\ |
| 81 | $(strip \ |
| 82 | $(docker-run-is) \ |
| 83 | $(if $(protc-sh-docker-mount), \ |
| 84 | -v ${CURDIR}:$(protoc-sh-docker-mount) \ |
| 85 | --workdir=$(protoc-sh-docker-mount) \ |
| 86 | ) \ |
| 87 | $(vee-citools)-protoc \ |
| 88 | sh -c \ |
| 89 | ) |
| 90 | PROTOC_SH ?= $(call get-cmd-docker-protoc-sh) |
| 91 | |
| 92 | # get-docker-protoc-sh = $(strip ) |
| 93 | #PROTOC_SH = $(docker-run-is) |
| 94 | #ifdef protc-sh-docker-mount |
| 95 | # PROTOC_SH += -v ${CURDIR}:$(protoc-sh-docker-mount) |
| 96 | # PROTOC_SH += --workdir=$(protoc-sh-docker-mount) |
| 97 | #endif # protoc-sh-docker-mount |
| 98 | #PROTOC_SH += $(vee-citools)-protoc sh -c |
| 99 | |
| 100 | # Usage: GO_JUNIT_REPORT := $(call get-docker-go-junit-repo) |
| 101 | # get-docker-go-junit-repo = $(docker-run-app) $(vee-citools)-go-junit-report go-junit-report |
| 102 | # GO_JUNIT_REPORT ?= $(call get-docker-go-junit-repo) |
| 103 | |
| 104 | # ----------------------------------------------------------------------- |
| 105 | # get-docker-gocover-cobertura = $(docker-run-app)/src/github.com/opencord/voltha-openolt-adapter $(vee-citools)-gocover-cobertura gocover-cobertura |
| 106 | # GOCOVER_COBERTURA ?= $(call get-docker-gocover-cobertura) |
| 107 | |
| 108 | ## ----------------------------------------------------------------------- |
| 109 | ## Coverage report: junit |
| 110 | ## ----------------------------------------------------------------------- |
| 111 | ## Usage: GO_JUNIT_REPORT ?= $(call get-go-junit-report-cmd) |
| 112 | ## ----------------------------------------------------------------------- |
| 113 | get-go-junit-report-cmd =\ |
| 114 | $(strip \ |
| 115 | $(docker-run) \ |
| 116 | -v ${CURDIR}:/app \ |
| 117 | -i $(vee-citools)-go-junit-report go-junit-report \ |
| 118 | ) |
| 119 | GO_JUNIT_REPORT ?= $(call get-go-junit-report-cmd) |
| 120 | |
| 121 | ## ----------------------------------------------------------------------- |
| 122 | ## Coverage report: cobertura |
| 123 | ## ----------------------------------------------------------------------- |
| 124 | ## Usage: GOCOVER_COBERTURA ?= $(call get-docker-gocover-cobertura-cmd) |
| 125 | ## ----------------------------------------------------------------------- |
| 126 | get-docker-go-cobertura-cmd =\ |
| 127 | $(strip \ |
| 128 | $(docker-run)\ |
| 129 | -v ${CURDIR}:$(go-cobertura-docker-mount)\ |
| 130 | -i $(vee-citools)-gocover-cobertura gocover-cobertura\ |
| 131 | ) |
| 132 | GOCOVER_COBERTURA ?= $(call get-docker-go-cobertura-cmd) |
| 133 | |
| 134 | ## ----------------------------------------------------------------------- |
| 135 | ## |
| 136 | ## ----------------------------------------------------------------------- |
| 137 | get-cmd-docker-golangci-lint =\ |
| 138 | $(strip \ |
| 139 | $(docker-run-app) \ |
| 140 | -v gocache:/.cache \ |
| 141 | $(vee-golang)\ |
| 142 | $(vee-citools)-golangci-lint\ |
| 143 | golangci-lint\ |
| 144 | ) |
| 145 | GOLANGCI_LINT ?= $(call get-cmd-docker-golangci-lint) |
| 146 | |
| 147 | ## ----------------------------------------------------------------------- |
| 148 | ## |
| 149 | ## ----------------------------------------------------------------------- |
| 150 | get-docker-hadolint =\ |
| 151 | $(strip \ |
| 152 | $(docker-run-app) \ |
| 153 | $(vee-citools)-hadolint \ |
| 154 | hadolint \ |
| 155 | ) |
| 156 | HADOLINT ?= $(call get-docker-hadolint) |
| 157 | |
| 158 | $(if $(DEBUG),$(warning LEAVE)) |
| 159 | |
| 160 | # [EOF] |