blob: b396297288bb13033cf86221e4b126bcd081119a [file] [log] [blame]
Ganesh Bhure8bb19822019-06-10 10:56:22 +05301# Copyright 2019-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Configure shell
16SHELL = bash -eu -o pipefail
17
18# Variables
19VERSION ?= $(shell cat ./VERSION)
20CONTAINER_NAME ?= $(notdir $(abspath .))
kesavand0c064922020-12-15 15:36:25 +053021VOLTHA_TOOLS_VERSION ?= 2.0.0
Ganesh Bhure8bb19822019-06-10 10:56:22 +053022
23## Docker related
24DOCKER_REGISTRY ?=
25DOCKER_REPOSITORY ?=
26DOCKER_BUILD_ARGS ?=
27DOCKER_TAG ?= ${VERSION}
28DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CONTAINER_NAME}:${DOCKER_TAG}
29
30## Docker labels. Only set ref and commit date if committed
31DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
32DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
33DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
34DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
35
kesavand0c064922020-12-15 15:36:25 +053036GO = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golang go
37GO_JUNIT_REPORT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app -i voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-go-junit-report go-junit-report
38GOCOVER_COBERTURA = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app -i voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-gocover-cobertura gocover-cobertura
39
Daniele Moro16e29a52020-01-29 13:15:13 -080040all: test docker-build
41
Ganesh Bhure8bb19822019-06-10 10:56:22 +053042docker-build:
43 docker build $(DOCKER_BUILD_ARGS) \
44 -t ${DOCKER_IMAGENAME} \
45 --build-arg org_label_schema_version="${VERSION}" \
46 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
47 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
48 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
49 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
50 -f Dockerfile .
Daniele Moro16e29a52020-01-29 13:15:13 -080051
Ganesh Bhure8bb19822019-06-10 10:56:22 +053052docker-push:
53 docker push ${DOCKER_IMAGENAME}
54
Daniele Moro16e29a52020-01-29 13:15:13 -080055test:
kesavand0c064922020-12-15 15:36:25 +053056 @mkdir -p ./tests/results
57 @${GO} test -mod=vendor -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
58 RETURN=$$? ;\
59 ${GO_JUNIT_REPORT} < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
60 ${GOCOVER_COBERTURA} < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
61 exit $$RETURN
Ganesh Bhure8bb19822019-06-10 10:56:22 +053062
63clean:
64 @echo "No cleanup available"
kesavand2cde6582020-06-22 04:56:23 -040065
66mod-update:
67 go mod tidy
68 go mod vendor
69