Skip to content

Commit

Permalink
Merge pull request #256 from Nordix/makefile
Browse files Browse the repository at this point in the history
Make tools, Proto generator updated
  • Loading branch information
LionelJouin authored Aug 3, 2022
2 parents 1068b0d + 0e89e4e commit 61c9766
Show file tree
Hide file tree
Showing 15 changed files with 1,217 additions and 1,046 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
# vendor/

_output/
bin/
147 changes: 113 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@

.PHONY: default
default: base-image load-balancer proxy tapa ipam nsp ctraffic frontend

############################################################################
# Variables
############################################################################

# Versions
VERSION ?= latest
VERSION_LOAD_BALANCER ?= $(VERSION)
VERSION_PROXY ?= $(VERSION)
Expand All @@ -7,26 +16,49 @@ VERSION_NSP ?= $(VERSION)
VERSION_CTRAFFIC ?= $(VERSION)
VERSION_FRONTEND ?= $(VERSION)

# E2E tests
E2E_FOCUS ?= ""
TRAFFIC_GENERATOR_CMD ?= "docker exec -i {trench}"
NAMESPACE ?= red

# Contrainer Registry
REGISTRY ?= localhost:5000/meridio
BASE_IMAGE ?= $(REGISTRY)/base:latest
DEBUG_IMAGE ?= $(REGISTRY)/debug:$(VERSION)

# Tools
export PATH := $(shell pwd)/bin:$(PATH)
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
GINKGO = $(shell pwd)/bin/ginkgo
MOCKGEN = $(shell pwd)/bin/mockgen
PROTOC_GEN_GO = $(shell pwd)/bin/protoc-gen-go
PROTOC_GEN_GO_GRPC = $(shell pwd)/bin/protoc-gen-go-grpc
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))

BUILD_DIR ?= build
BUILD_STEPS ?= build tag push

#############################################################################
# Container: Build, tag, push
#############################################################################

.PHONY: all
all: default

.PHONY: build
build:
docker build -t $(IMAGE) --build-arg meridio_version=$(shell git describe --dirty --tags) --build-arg base_image=$(BASE_IMAGE) -f ./build/$(IMAGE)/Dockerfile .
docker build -t $(IMAGE) --build-arg meridio_version=$(shell git describe --dirty --tags) --build-arg base_image=$(BASE_IMAGE) -f ./$(BUILD_DIR)/$(IMAGE)/Dockerfile .
.PHONY: tag
tag:
docker tag $(IMAGE) $(REGISTRY)/$(IMAGE):$(VERSION)
.PHONY: push
push:
docker push $(REGISTRY)/$(IMAGE):$(VERSION)

#############################################################################
# Component (Build, tag, push): base, debug, load-balancer, proxy, tapa, ipam, nsp, ctraffic, frontend
#############################################################################

.PHONY: base-image
base-image:
docker build -t $(BASE_IMAGE) -f ./build/base/Dockerfile .
Expand All @@ -37,61 +69,43 @@ debug-image:

.PHONY: load-balancer
load-balancer:
VERSION=$(VERSION_LOAD_BALANCER) IMAGE=load-balancer $(MAKE) build tag push
VERSION=$(VERSION_LOAD_BALANCER) IMAGE=load-balancer $(MAKE) $(BUILD_STEPS)

.PHONY: proxy
proxy:
VERSION=$(VERSION_PROXY) IMAGE=proxy $(MAKE) build tag push
VERSION=$(VERSION_PROXY) IMAGE=proxy $(MAKE) $(BUILD_STEPS)

.PHONY: tapa
tapa:
VERSION=$(VERSION_TAPA) IMAGE=tapa $(MAKE) build tag push
VERSION=$(VERSION_TAPA) IMAGE=tapa $(MAKE) $(BUILD_STEPS)

.PHONY: ipam
ipam:
VERSION=$(VERSION_IPAM) IMAGE=ipam $(MAKE) build tag push
VERSION=$(VERSION_IPAM) IMAGE=ipam $(MAKE) $(BUILD_STEPS)

.PHONY: nsp
nsp:
VERSION=$(VERSION_NSP) IMAGE=nsp $(MAKE) build tag push
VERSION=$(VERSION_NSP) IMAGE=nsp $(MAKE) $(BUILD_STEPS)

.PHONY: ctraffic
ctraffic:
VERSION=$(VERSION_CTRAFFIC) IMAGE=ctraffic $(MAKE) build tag push
VERSION=$(VERSION_CTRAFFIC) IMAGE=ctraffic $(MAKE) $(BUILD_STEPS)

.PHONY: frontend
frontend:
VERSION=$(VERSION_FRONTEND) IMAGE=frontend $(MAKE) build tag push

.PHONY: ipam-proto
ipam-proto:
protoc --go_out=plugins=grpc:. --go_opt=paths=source_relative api/ipam/**/*.proto

.PHONY: nsp-proto
nsp-proto:
protoc --go_out=plugins=grpc:. --go_opt=paths=source_relative api/nsp/**/*.proto

.PHONY: ambassador-proto
ambassador-proto:
protoc --go_out=plugins=grpc:. --go_opt=paths=source_relative api/ambassador/**/*.proto

.PHONY: proto
proto: ipam-proto nsp-proto ambassador-proto

.PHONY: clear
clear:
VERSION=$(VERSION_FRONTEND) IMAGE=frontend $(MAKE) $(BUILD_STEPS)

.PHONY: default
default: base-image load-balancer proxy tapa ipam nsp ctraffic frontend
#############################################################################
# Testing & Code check
#############################################################################

.PHONY: lint
lint:
golangci-lint run ./...
lint: golangci-lint
$(GOLANGCI_LINT) run ./...

NAMESPACE ?= red
.PHONY: e2e
e2e:
ginkgo -v --focus=$(E2E_FOCUS) ./test/e2e/... -- -traffic-generator-cmd=$(TRAFFIC_GENERATOR_CMD) -namespace=${NAMESPACE}
e2e: ginkgo
$(GINKGO) -v --focus=$(E2E_FOCUS) ./test/e2e/... -- -traffic-generator-cmd=$(TRAFFIC_GENERATOR_CMD) -namespace=${NAMESPACE}

.PHONY: test
test:
Expand All @@ -105,6 +119,71 @@ cover:
.PHONY: check
check: lint test

#############################################################################
# Code generation
#############################################################################

.PHONY: generate
generate:
generate: mockgen
go generate ./...

.PHONY: ipam-proto
ipam-proto: proto-compiler
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative api/ipam/**/*.proto

.PHONY: nsp-proto
nsp-proto: proto-compiler
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative api/nsp/**/*.proto

.PHONY: ambassador-proto
ambassador-proto: proto-compiler
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative api/ambassador/**/*.proto

.PHONY: proto
proto: ipam-proto nsp-proto ambassador-proto

#############################################################################
# Tools
#############################################################################

.PHONY: golangci-lint
golangci-lint:
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.47.2)

.PHONY: proto-compiler
proto-compiler: protoc protoc-gen-go protoc-gen-go-grpc

.PHONY: protoc
protoc:
@if [ ! $(shell which protoc) ]; then\
echo "Protocol buffer compiler (protoc) must be installed: https://grpc.io/docs/protoc-installation/#install-pre-compiled-binaries-any-os";\
fi

.PHONY: protoc-gen-go
protoc-gen-go:
$(call go-get-tool,$(PROTOC_GEN_GO),google.golang.org/protobuf/cmd/protoc-gen-go@v1.28)

.PHONY: protoc-gen-go-grpc
protoc-gen-go-grpc:
$(call go-get-tool,$(PROTOC_GEN_GO_GRPC),google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2)

.PHONY: mockgen
mockgen:
$(call go-get-tool,$(MOCKGEN),github.com/golang/mock/mockgen@v1.6.0)

.PHONY: ginkgo
ginkgo:
$(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo@v2.1.4)

# go-get-tool will 'go get' any package $2 and install it to $1.
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
Loading

0 comments on commit 61c9766

Please sign in to comment.