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