Update RMR library Gerrit repo
[ric-plt/appmgr.git] / Makefile
1 #   Copyright (c) 2019 AT&T Intellectual Property.
2 #   Copyright (c) 2019 Nokia.
3 #
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #   Unless required by applicable law or agreed to in writing, software
11 #   distributed under the License is distributed on an "AS IS" BASIS,
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #   See the License for the specific language governing permissions and
14 #   limitations under the License.
15
16
17 #------------------------------------------------------------------------------
18 #
19 #-------------------------------------------------------------------- ----------
20 ROOT_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
21 BUILD_DIR:=$(abspath $(ROOT_DIR)/build)
22
23 PACKAGEURL:="gerrit.oran-osc.org/r/ric-plt/appmgr"
24 HELMVERSION:=v2.13.0-rc.1
25
26 #------------------------------------------------------------------------------
27 #
28 #-------------------------------------------------------------------- ----------
29 COVEROUT := $(abspath $(BUILD_DIR)/cover.out)
30 COVERHTML := $(abspath $(BUILD_DIR)/cover.html)
31
32 GOOS=$(shell go env GOOS)
33 GOCMD=go
34 GOBUILD=$(GOCMD) build -a -installsuffix cgo
35 GORUN=$(GOCMD) run -a -installsuffix cgo
36 GOCLEAN=$(GOCMD) clean
37 GOTEST=$(GOCMD) test -v -coverprofile $(COVEROUT)
38 GOGET=$(GOCMD) get
39
40 GOFILES := $(shell find $(ROOT_DIR) -name '*.go' -not -name '*_test.go')  go.mod go.sum
41 GOFILES_NO_VENDOR := $(shell find $(ROOT_DIR) -path ./vendor -prune -o -name "*.go" -not -name '*_test.go' -print)
42
43 CMDS:=$(BUILD_DIR)/appmgr
44
45 #------------------------------------------------------------------------------
46 #
47 #-------------------------------------------------------------------- ----------
48  .DEFAULT: build
49
50 default: build
51
52 .PHONY: FORCE 
53
54 FORCE:
55
56 #------------------------------------------------------------------------------
57 #
58 #------------------------------------------------------------------------------
59
60 $(CMDS): $(GOFILES)
61         GO111MODULE=on GO_ENABLED=0 GOOS=linux $(GOBUILD) -o $@ ./cmd/$(shell basename "$@")
62
63
64 $(addsuffix _test,$(CMDS)): $(GOFILES)
65         GO111MODULE=on GO_ENABLED=0 GOOS=linux $(GOTEST) -c -o $@ ./cmd/$(patsubst %_test,%, $(shell basename "$@")) 
66         timeout -s KILL 5s $@ -test.coverprofile $(COVEROUT)
67         go tool cover -html=$(COVEROUT) -o $(COVERHTML)
68
69
70 build: $(CMDS)
71
72
73 test: $(addsuffix _test,$(CMDS))
74
75
76 test-fmt: $(GOFILES_NO_VENDOR)
77         @(RESULT="$$(gofmt -l $^)"; test -z "$${RESULT}" || (echo -e "gofmt failed:\n$${RESULT}" && false) )
78
79
80 fmt: $(GOFILES_NO_VENDOR)
81         gofmt -w -s $^
82
83
84 clean:
85         @echo "  >  Cleaning build cache"
86         @-rm -rf $(CMDS)* 2> /dev/null
87         go clean 2> /dev/null
88
89 #------------------------------------------------------------------------------
90 #
91 #------------------------------------------------------------------------------
92
93 BUILD_PREFIX?="${USER}-"
94
95 DCKR_FILE:=docker/Dockerfile
96
97 DCKR_NAME:=${BUILD_PREFIX}appmgr
98 DCKR_NAME:=$(shell echo $(DCKR_NAME) | tr '[:upper:]' '[:lower:]')
99 DCKR_NAME:=$(subst /,_,${DCKR_NAME})
100
101 DCKR_BUILD_OPTS:=${DCKR_BUILD_OPTS} --network=host --build-arg HELMVERSION=${HELMVERSION} --build-arg PACKAGEURL=${PACKAGEURL}
102
103 DCKR_RUN_OPTS:=${DCKR_RUN_OPTS} --rm -i
104 DCKR_RUN_OPTS:=${DCKR_RUN_OPTS}$(shell test -t 0 && echo ' -t')
105 DCKR_RUN_OPTS:=${DCKR_RUN_OPTS}$(shell test -e /etc/localtime && echo ' -v /etc/localtime:/etc/localtime:ro')
106 DCKR_RUN_OPTS:=${DCKR_RUN_OPTS}$(shell test -e /var/run/docker.sock && echo ' -v /var/run/docker.sock:/var/run/docker.sock')
107
108
109 #------------------------------------------------------------------------------
110 #
111 #------------------------------------------------------------------------------
112 docker-name:
113         @echo $(DCKR_NAME)
114
115 docker-build:
116         docker build --target release ${DCKR_BUILD_OPTS} -t $(DCKR_NAME) -f $(DCKR_FILE) .
117
118 docker-run:
119         docker run ${DCKR_RUN_OPTS} -v /opt/ric:/opt/ric -p 8080:8080 $(DCKR_NAME)
120
121 docker-clean:
122         docker rmi $(DCKR_NAME)
123
124
125 #------------------------------------------------------------------------------
126 #
127 #------------------------------------------------------------------------------
128
129 docker-test-build:
130         docker build --target test_unit ${DCKR_BUILD_OPTS} -t ${DCKR_NAME}-test_unit -f $(DCKR_FILE) .
131         docker build --target test_sanity ${DCKR_BUILD_OPTS} -t ${DCKR_NAME}-test_sanity -f $(DCKR_FILE) .
132         docker build --target test_fmt ${DCKR_BUILD_OPTS} -t ${DCKR_NAME}-test_fmt -f $(DCKR_FILE) .
133
134 docker-test-run-unit:
135         @( \
136                 RETVAL=0;\
137                 docker network create --driver bridge ${DCKR_NAME}-test_unit_network;\
138                 docker run ${DCKR_RUN_OPTS} -d --name ${DCKR_NAME}-test_unit_redis --network ${DCKR_NAME}-test_unit_network redis;\
139                 docker run ${DCKR_RUN_OPTS} --name ${DCKR_NAME}-test_unit_run --network ${DCKR_NAME}-test_unit_network -e DBAAS_SERVICE_HOST=${DCKR_NAME}-test_unit_redis ${DCKR_NAME}-test_unit;\
140                 RETVAL=$$?;\
141                 docker stop ${DCKR_NAME}-test_unit_redis;\
142                 docker network rm ${DCKR_NAME}-test_unit_network;\
143                 exit $${RETVAL};\
144         )
145
146
147 docker-test-run-fmt:
148         docker run ${DCKR_RUN_OPTS} ${DCKR_NAME}-test_fmt
149
150 docker-test-run-sanity:
151         docker run ${DCKR_RUN_OPTS} ${DCKR_NAME}-test_sanity
152
153 docker-test-clean:
154         docker rmi -f ${DCKR_NAME}-test_unit
155         docker rmi -f ${DCKR_NAME}-test_sanity
156         docker rmi -f ${DCKR_NAME}-test_fmt
157