Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1 | # Copyright 2019-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | VERSION ?= $(shell cat ./VERSION) |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 16 | DIFF ?= $(git diff --shortstat 2> /dev/null | tail -n1) |
| 17 | GIT_STATUS ?= $(shell [[ $DIFF != "" ]] && echo "Dirty" || echo "Clean") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 18 | |
| 19 | ## Docker related |
| 20 | DOCKER_TAG ?= ${VERSION} |
Matteo Scandolo | 5daa2ab | 2019-10-08 08:27:18 -0700 | [diff] [blame] | 21 | DOCKER_REPOSITORY ?= "" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 22 | DOCKER_REGISTRY ?= "" |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 23 | DOCKER_RUN_ARGS ?= "" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 24 | |
| 25 | # Public targets |
| 26 | |
| 27 | all: help |
| 28 | |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 29 | protos: api/bbsim/bbsim.pb.go # @HELP Build proto files |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 30 | |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 31 | dep: # @HELP Download the dependencies to the vendor folder |
| 32 | GO111MODULE=on go mod vendor |
| 33 | |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 34 | _build: dep protos fmt build-bbsim build-bbsimctl build-bbr |
| 35 | |
Matteo Scandolo | 6866b8c | 2019-10-28 16:15:24 -0700 | [diff] [blame] | 36 | .PHONY: build |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 37 | build: # @HELP Build the binaries (it runs inside a docker container and output the built code on your local file system) |
| 38 | docker build -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim-builder:${DOCKER_TAG} -f build/ci/Dockerfile.builder . |
Matteo Scandolo | d49da29 | 2019-10-28 16:30:51 -0700 | [diff] [blame] | 39 | docker run --rm -v $(shell pwd):/bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim-builder:${DOCKER_TAG} /bin/sh -c "cd /bbsim; make _build" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 40 | |
William Kurkian | c7966c7 | 2019-10-16 14:00:00 -0400 | [diff] [blame] | 41 | test: dep protos fmt # @HELP Execute unit tests |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 42 | GO111MODULE=on go test -v -mod vendor ./... -covermode count -coverprofile ./tests/results/go-test-coverage.out 2>&1 | tee ./tests/results/go-test-results.out |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 43 | go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml |
| 44 | gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 45 | |
Matteo Scandolo | 3830549 | 2019-10-11 11:36:00 -0700 | [diff] [blame] | 46 | fmt: |
| 47 | go fmt ./... |
| 48 | |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 49 | docker-build: # @HELP Build the BBSim docker container (contains BBSimCtl too) |
Matteo Scandolo | 82c16d0 | 2019-09-24 09:34:32 -0700 | [diff] [blame] | 50 | docker build -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} -f build/package/Dockerfile . |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 51 | |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 52 | docker-push: # @HELP Push the docker container to a registry |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 53 | docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} |
| 54 | |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 55 | docker-run: # @HELP Runs the container locally (available options: DOCKER_RUN_ARGS="-pon 2 -onu 2" make docker-run) |
Matteo Scandolo | ecbd6a1 | 2019-10-21 10:51:03 -0700 | [diff] [blame] | 56 | docker run -d -p 50070:50070 -p 50060:50060 --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS} |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 57 | |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 58 | docker-run-dev: # @HELP Runs the container locally (intended for development purposes, not in detached mode) |
| 59 | docker run -p 50070:50070 -p 50060:50060 --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS} |
| 60 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 61 | .PHONY: docs |
Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 62 | docs: # @HELP Generate docs and opens them in the browser |
| 63 | pushd docs; make doc_venv; make html; popd |
| 64 | open docs/build/html/index.html |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 65 | |
Matteo Scandolo | 8dea399 | 2019-10-22 10:54:25 -0700 | [diff] [blame] | 66 | # Release related items |
| 67 | # Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH |
| 68 | # Inspired by: https://github.com/kubernetes/minikube/releases |
| 69 | RELEASE_DIR ?= release |
| 70 | RELEASE_OS_ARCH ?= linux-amd64 linux-arm64 windows-amd64 darwin-amd64 |
| 71 | |
| 72 | RELEASE_BBR_NAME ?= bbr |
| 73 | RELEASE_BBR_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_BBR_NAME)-$(rel)) |
| 74 | RELEASE_BBSIM_NAME ?= bbsimctl |
| 75 | RELEASE_BBSIM_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_BBSIM_NAME)-$(rel)) |
| 76 | |
| 77 | $(RELEASE_BBR_BINS): |
| 78 | export GOOS=$(rel_os) ;\ |
| 79 | export GOARCH=$(rel_arch) ;\ |
| 80 | GO111MODULE=on go build -i -v -mod vendor \ |
| 81 | -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \ |
| 82 | -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 83 | -X main.gitStatus=${GIT_STATUS} \ |
| 84 | -X main.version=${VERSION}" \ |
| 85 | -o "$@" ./cmd/bbr |
| 86 | |
| 87 | $(RELEASE_BBSIM_BINS): |
| 88 | export GOOS=$(rel_os) ;\ |
| 89 | export GOARCH=$(rel_arch) ;\ |
| 90 | GO111MODULE=on go build -i -v -mod vendor \ |
| 91 | -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \ |
| 92 | -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 93 | -X main.gitStatus=${GIT_STATUS} \ |
| 94 | -X main.version=${VERSION}" \ |
| 95 | -o "$@" ./cmd/bbsim |
| 96 | |
| 97 | .PHONY: release $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS) |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 98 | release: dep protos $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS) # @HELP Creates release ready bynaries for BBSimctl and BBR artifacts |
Matteo Scandolo | 8dea399 | 2019-10-22 10:54:25 -0700 | [diff] [blame] | 99 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 100 | help: # @HELP Print the command options |
| 101 | @echo |
| 102 | @echo "\033[0;31m BroadBand Simulator (BBSim) \033[0m" |
| 103 | @echo |
| 104 | @echo Emulates the control plane of an openolt compatible device |
| 105 | @echo Useful for development and scale testing |
| 106 | @echo |
| 107 | @grep -E '^.*: .* *# *@HELP' $(MAKEFILE_LIST) \ |
| 108 | | sort \ |
| 109 | | awk ' \ |
| 110 | BEGIN {FS = ": .* *# *@HELP"}; \ |
| 111 | {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}; \ |
| 112 | ' |
| 113 | |
| 114 | |
| 115 | # Internals |
Matteo Scandolo | 8dea399 | 2019-10-22 10:54:25 -0700 | [diff] [blame] | 116 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 117 | build-bbr: |
| 118 | GO111MODULE=on go build -i -v -mod vendor \ |
| 119 | -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \ |
| 120 | -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 121 | -X main.gitStatus=${GIT_STATUS} \ |
| 122 | -X main.version=${VERSION}" \ |
| 123 | ./cmd/bbr |
| 124 | |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 125 | build-bbsim: |
| 126 | GO111MODULE=on go build -i -v -mod vendor \ |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 127 | -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \ |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 128 | -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 129 | -X main.gitStatus=${GIT_STATUS} \ |
| 130 | -X main.version=${VERSION}" \ |
Matteo Scandolo | 82c16d0 | 2019-09-24 09:34:32 -0700 | [diff] [blame] | 131 | ./cmd/bbsim |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 132 | |
| 133 | build-bbsimctl: |
| 134 | GO111MODULE=on go build -i -v -mod vendor \ |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 135 | -ldflags "-w -X github.com/opencord/bbsim/internal/bbsimctl/config.BuildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \ |
Matteo Scandolo | 82c16d0 | 2019-09-24 09:34:32 -0700 | [diff] [blame] | 136 | -X github.com/opencord/bbsim/internal/bbsimctl/config.CommitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 137 | -X github.com/opencord/bbsim/internal/bbsimctl/config.GitStatus=${GIT_STATUS} \ |
| 138 | -X github.com/opencord/bbsim/internal/bbsimctl/config.Version=${VERSION}" \ |
| 139 | ./cmd/bbsimctl |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 140 | |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 141 | api/openolt/openolt.pb.go: api/openolt/openolt.proto |
| 142 | @protoc -I . \ |
| 143 | -I${GOPATH}/src \ |
| 144 | -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ |
| 145 | --go_out=plugins=grpc:./ \ |
| 146 | $< |
| 147 | |
| 148 | api/bbsim/bbsim.pb.go: api/bbsim/bbsim.proto |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 149 | @protoc -I . \ |
| 150 | -I${GOPATH}/src \ |
| 151 | -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ |
| 152 | --go_out=plugins=grpc:./ \ |
| 153 | $< |
| 154 | |