0798914827a6fca147611593177d1a4d55eace3e
[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 GOPATH := $(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 GOPATH ...
21 export GO111MODULE=on
22
23 .PHONY: clean plugins
24
25 ## build: Generate the k8s and openapi artifacts using operator-sdk
26 build: clean vendor
27         GOOS=linux GOARCH=amd64
28         operator-sdk generate k8s --verbose
29         operator-sdk generate openapi --verbose
30         #@go build -o ${COP} -gcflags all=-trimpath=${GOPATH} -asmflags all=-trimpath=${GOPATH} -mod=vendor demo/vnfs/DAaaS/microservices/collectd-operator/cmd/manager
31         @go build -o ${COP_LOCAL} -mod=vendor demo/vnfs/DAaaS/microservices/collectd-operator/cmd/manager
32         @operator-sdk build ${IMAGE_NAME} --verbose
33
34 # 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
35 # no need to create a static binary with additional flags. However, for generating binary, additional build flags are necessary. This if used with
36 # mock plugin errors out for unit tests. So the seperation avoids the error.
37
38 ## all: Delete the image, binary, complete build, test and run coverage
39 all: build test cover
40 ## debug: Build local binary for debugging
41 debug:
42         @echo "Deleting ${COP_LOCAL} binary"
43         @rm -rf ${COP_LOCAL}
44         operator-sdk generate k8s --verbose
45         operator-sdk generate openapi --verbose
46         @echo "Building ${COP_LOCAL} binary"
47         @go build -o ${COP_LOCAL} -mod=vendor demo/vnfs/DAaaS/microservices/collectd-operator/cmd/manager
48
49 ## deploy: Build Dockerfile and publish to repository
50 deploy: build publish
51 ## vendor: Build the vendor module
52 vendor:
53         @go mod vendor
54 ## publish: Push docker image to repository
55 publish:
56         @docker push ${IMAGE_NAME}
57 .PHONY: test
58 ## test: run tests
59 test: clean
60         @go test -v ./...
61 ## format: format source code
62 format:
63         @go fmt ./...
64
65 ## clean: clean build artifacts, image, binary 
66 clean:
67         @echo "Deleting the collectd-operator binary"
68         @rm -rf ${COP}
69         @rm -rf ${COP_LOCAL}
70         @echo "Deleting the collectd-operator docker image"
71         @docker rmi ${IMAGE_NAME}
72
73 .PHONY: cover
74 ## cover: run tests and generate coverage report
75 cover:
76         @go test ./... -coverprofile=coverage.out
77         @go tool cover -html=coverage.out -o coverage.html
78
79 .PHONY: help
80 ## help: Print help message
81 help: Makefile
82         @echo
83         @echo " Requires Operator SDK v0.8.0+, go1.12.5+"
84         @echo
85         @echo " Choose a command run in "$(PROJECTNAME)":"
86         @echo
87         @sed -n 's/^## //p' $< | column -t -s ':' |  sed -e 's/^/ /'
88         @echo