1 # Copyright (c) 2019 AT&T Intellectual Property.
2 # Copyright (c) 2019 Nokia.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 #------------------------------------------------------------------------------
19 #-------------------------------------------------------------------- ----------
20 ROOT_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
21 BUILD_DIR:=$(abspath $(ROOT_DIR)/build)
23 PACKAGEURL:="gerrit.oran-osc.org/r/ric-plt/appmgr"
24 HELMVERSION:=v2.13.0-rc.1
26 #------------------------------------------------------------------------------
28 #-------------------------------------------------------------------- ----------
29 COVEROUT := $(abspath $(BUILD_DIR)/cover.out)
30 COVERHTML := $(abspath $(BUILD_DIR)/cover.html)
32 GOOS=$(shell go env GOOS)
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)
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)
43 CMDS:=$(BUILD_DIR)/appmgr
45 #------------------------------------------------------------------------------
47 #-------------------------------------------------------------------- ----------
56 #------------------------------------------------------------------------------
58 #------------------------------------------------------------------------------
61 GO111MODULE=on GO_ENABLED=0 GOOS=linux $(GOBUILD) -o $@ ./cmd/$(shell basename "$@")
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)
73 test: $(addsuffix _test,$(CMDS))
76 test-fmt: $(GOFILES_NO_VENDOR)
77 @(RESULT="$$(gofmt -l $^)"; test -z "$${RESULT}" || (echo -e "gofmt failed:\n$${RESULT}" && false) )
80 fmt: $(GOFILES_NO_VENDOR)
85 @echo " > Cleaning build cache"
86 @-rm -rf $(CMDS)* 2> /dev/null
89 #------------------------------------------------------------------------------
91 #------------------------------------------------------------------------------
93 BUILD_PREFIX?="${USER}-"
95 DCKR_FILE:=docker/Dockerfile
97 DCKR_NAME:=${BUILD_PREFIX}appmgr
98 DCKR_NAME:=$(shell echo $(DCKR_NAME) | tr '[:upper:]' '[:lower:]')
99 DCKR_NAME:=$(subst /,_,${DCKR_NAME})
101 DCKR_BUILD_OPTS:=${DCKR_BUILD_OPTS} --network=host --build-arg HELMVERSION=${HELMVERSION} --build-arg PACKAGEURL=${PACKAGEURL}
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')
109 #------------------------------------------------------------------------------
111 #------------------------------------------------------------------------------
116 docker build --target release ${DCKR_BUILD_OPTS} -t $(DCKR_NAME) -f $(DCKR_FILE) .
119 docker run ${DCKR_RUN_OPTS} -v /opt/ric:/opt/ric -p 8080:8080 $(DCKR_NAME)
122 docker rmi $(DCKR_NAME)
125 #------------------------------------------------------------------------------
127 #------------------------------------------------------------------------------
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) .
134 docker-test-run-unit:
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;\
141 docker stop ${DCKR_NAME}-test_unit_redis;\
142 docker network rm ${DCKR_NAME}-test_unit_network;\
148 docker run ${DCKR_RUN_OPTS} ${DCKR_NAME}-test_fmt
150 docker-test-run-sanity:
151 docker run ${DCKR_RUN_OPTS} ${DCKR_NAME}-test_sanity
154 docker rmi -f ${DCKR_NAME}-test_unit
155 docker rmi -f ${DCKR_NAME}-test_sanity
156 docker rmi -f ${DCKR_NAME}-test_fmt