266ac05583d32f750ad8f579786aa98f5ab912ff
[ric-plt/appmgr.git] / build / 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 BUILD_DIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
17
18 ROOT_DIR:=$(abspath $(BUILD_DIR)/..)
19
20 BUILD_PREFIX?="${USER}-"
21
22 XAPP_MGR:=appmgr
23 XAPP_MGR_DOCKER:=${BUILD_PREFIX}appmgr
24
25 GOSRC := $(abspath $(BUILD_DIR)/../src)
26 GOFILES := $(GOSRC)/*.go
27 COVEROUT := $(abspath $(BUILD_DIR)/cover.out)
28 COVERHTML := $(abspath $(BUILD_DIR)/cover.html)
29
30 GOCMD=go
31 GOBUILD=$(GOCMD) build -a -installsuffix cgo
32 GORUN=$(GOCMD) run -a -installsuffix cgo
33 GOCLEAN=$(GOCMD) clean
34 GOTEST=$(GOCMD) test -v -coverprofile $(COVEROUT)
35 GOGET=$(GOCMD) get
36
37 HELMVERSION:=v2.13.0-rc.1
38
39 #------------------------------------------------------------------------------
40 #
41 #-------------------------------------------------------------------- ----------
42 .PHONY: FORCE build deps run unit-test test-pkg test clean docker-base-build docker-base-clean docker-build docker-run docker-clean docker-test-build docker-test-run-unittest docker-test-run-sanity docker-test-run docker-test-clean
43  
44 .DEFAULT: build
45
46 default: build
47
48 FORCE:
49
50 #------------------------------------------------------------------------------
51 #
52 #------------------------------------------------------------------------------
53
54 XAPP_MGR_DOCKER:=$(shell echo $(XAPP_MGR_DOCKER) | tr '[:upper:]' '[:lower:]')
55
56 #XAPP_MGR_DOCKER:=$(subst /,_,${XAPP_MGR_DOCKER})
57
58 #------------------------------------------------------------------------------
59 #
60 #------------------------------------------------------------------------------
61
62 $(BUILD_DIR)$(XAPP_MGR): deps ${wildcard $(GOFILES)}
63         GO_ENABLED=0 GOOS=linux $(GOBUILD) -o $(BUILD_DIR)$(XAPP_MGR) $(GOFILES)
64
65 build: $(BUILD_DIR)$(XAPP_MGR)
66
67 deps: ${wildcard $(GOFILES)}
68         cd $(GOSRC) && $(GOGET)
69
70 run: $(BUILD_DIR)$(XAPP_MGR)
71         $(BUILD_DIR)$(XAPP_MGR) -host-addr="localhost:8080" -helm-host="localhost:31807" -helm-chart="./"
72
73 unit-test:
74         cd $(GOSRC) && $(GOTEST)
75         go tool cover -html=$(COVEROUT) -o $(COVERHTML)
76
77 clean:
78         @echo "  >  Cleaning build cache"
79         @-rm -rf $(XAPP_MGR) 2> /dev/null
80         go clean 2> /dev/null
81
82 #------------------------------------------------------------------------------
83 #
84 #------------------------------------------------------------------------------
85
86 DCKR_BUILD_OPTS:=${DCKR_BUILD_OPTS} --network=host --build-arg HELMVERSION=${HELMVERSION}
87
88 DCKR_RUN_OPTS:=${DCKR_RUN_OPTS} --rm -i
89 DCKR_RUN_OPTS:=${DCKR_RUN_OPTS}$(shell test -t 0 && echo ' -t')
90 DCKR_RUN_OPTS:=${DCKR_RUN_OPTS}$(shell test -e /etc/localtime && echo ' -v /etc/localtime:/etc/localtime:ro')
91 DCKR_RUN_OPTS:=${DCKR_RUN_OPTS}$(shell test -e /var/run/docker.sock && echo ' -v /var/run/docker.sock:/var/run/docker.sock')
92
93
94 #------------------------------------------------------------------------------
95 #
96 #------------------------------------------------------------------------------
97 docker-name:
98         @echo $(XAPP_MGR_DOCKER)
99
100 docker-build:
101         docker build --target release ${DCKR_BUILD_OPTS} -t $(XAPP_MGR_DOCKER) -f Dockerfile ../.
102
103 docker-run:
104         docker run ${DCKR_RUN_OPTS} -v /opt/ric:/opt/ric -p 8080:8080 $(XAPP_MGR_DOCKER)
105
106 docker-clean:
107         docker rmi $(XAPP_MGR_DOCKER)
108
109
110 #------------------------------------------------------------------------------
111 #
112 #------------------------------------------------------------------------------
113
114 docker-test-build:
115         docker build --target test_unit ${DCKR_BUILD_OPTS} -t ${XAPP_MGR_DOCKER}-test_unit -f Dockerfile ../.
116         docker build --target test_sanity ${DCKR_BUILD_OPTS} -t ${XAPP_MGR_DOCKER}-test_sanity -f Dockerfile ../.
117
118 docker-test-run-unit:
119         docker run ${DCKR_RUN_OPTS} ${XAPP_MGR_DOCKER}-test_unit 
120
121 docker-test-run-sanity:
122         docker run ${DCKR_RUN_OPTS} ${XAPP_MGR_DOCKER}-test_sanity
123
124 docker-test-run: docker-test-run-sanity docker-test-run-unit
125
126 docker-test-clean:
127         docker rmi -f ${XAPP_MGR_DOCKER}-test_unit
128         docker rmi -f ${XAPP_MGR_DOCKER}-test_sanity
129