52c779cf0233d9f70213f233cc0a84a00efdd9fa
[demo.git] / vnfs / DAaaS / microservices / collectd-operator / Makefile
1 # SPDX-license-identifier: Apache-2.0
2 ##############################################################################
3 # Copyright (c) 2019 Intel Corporation
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 # Common
11 VERSION := $(shell git describe --tags)
12 BUILD := $(shell git rev-parse --short HEAD)
13 PROJECTNAME := $(shell basename "$(PWD)")
14
15 ROOTPATH := $(shell realpath "$(PWD)/../")
16 COP := ${PWD}/build/_output/bin/collectd-operator
17 COP_LOCAL := ${COP}-local
18 IMAGE_NAME := dcr.cluster.local:32644/collectd-operator:latest
19
20 export GO111MODULE=on
21
22 .PHONY: clean plugins
23
24 ## build: Generate the k8s and openapi artifacts using operator-sdk
25 build: clean
26         GOOS=linux GOARCH=amd64
27         operator-sdk generate k8s --verbose
28         operator-sdk generate openapi --verbose
29         @go build -o ${COP_LOCAL} collectd-operator/cmd/manager
30         @operator-sdk build ${IMAGE_NAME} --verbose
31
32 # The following is done this way as each patch on CI runs build and each merge runs deploy. So for build we don't need to build binary and hence
33 # no need to create a static binary with additional flags. However, for generating binary, additional build flags are necessary. This if used with
34 # mock plugin errors out for unit tests. So the seperation avoids the error.
35
36 ## all: Delete the image, binary, complete build, test and run coverage
37 all: build test cover
38 ## debug: Build local binary for debugging
39 debug:
40         @echo "Deleting ${COP_LOCAL} binary"
41         @rm -rf ${COP_LOCAL}
42         operator-sdk generate k8s --verbose
43         operator-sdk generate openapi --verbose
44         @echo "Building ${COP_LOCAL} binary"
45         @go build -o ${COP_LOCAL} collectd-operator/cmd/manager
46
47 ## deploy: Build Dockerfile and publish to repository
48 deploy: build publish
49
50 ## publish: Push docker image to repository
51 publish:
52         @docker push ${IMAGE_NAME}
53 .PHONY: test
54 ## test: run tests
55 test: clean
56         @go test -v ./...
57 ## format: format source code
58 format:
59         @go fmt ./...
60
61 ## clean: clean build artifacts, image, binary 
62 clean:
63         @echo "Deleting the collectd-operator binary"
64         @rm -rf ${COP}
65         @rm -rf ${COP_LOCAL}
66         @echo "Deleting the collectd-operator docker image"
67         @docker rmi ${IMAGE_NAME}
68
69 .PHONY: cover
70 ## cover: run tests and generate coverage report
71 cover:
72         @go test ./... -coverprofile=coverage.out
73         @go tool cover -html=coverage.out -o coverage.html
74
75 .PHONY: help
76 ## help: Print help message
77 help: Makefile
78         @echo
79         @echo " Requires Operator SDK v0.8.0+, go1.12.5+"
80         @echo
81         @echo " Choose a command run in "$(PROJECTNAME)":"
82         @echo
83         @sed -n 's/^## //p' $< | column -t -s ':' |  sed -e 's/^/ /'
84         @echo