github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/Makefile (about)

     1  PROJECT := BinkyNet
     2  ROOTDIR := $(shell pwd)
     3  VERSION := $(shell cat VERSION)
     4  COMMIT := $(shell git rev-parse --short HEAD)
     5  BUILDIMAGE := binkynet-apis-build
     6  CACHEVOL := binkynet-apis-gocache
     7  MODVOL := binkynet-apis-pkg-mod
     8  BINDIR := $(ROOTDIR)
     9  
    10  ORGPATH := github.com/binkynet
    11  REPONAME := $(PROJECT)
    12  REPOPATH := $(ORGPATH)/$(REPONAME)
    13  BINNAME := bnet
    14  BIN := $(BINDIR)/$(BINNAME)
    15  
    16  ifndef GOOS
    17  	GOOS := $(shell go env GOOS)
    18  endif
    19  ifndef GOARCH
    20  	GOARCH := $(shell go env GOARCH)
    21  endif
    22  
    23  DOCKERARGS := run -t --rm \
    24  	-u $(shell id -u):$(shell id -g) \
    25  	-v $(ROOTDIR):/go/src/$(REPOPATH) \
    26  	-v $(CACHEVOL):/usr/gocache \
    27  	-v $(MODVOL):/go/pkg/mod \
    28  	-e GOCACHE=/usr/gocache \
    29  	-e CGO_ENABLED=0 \
    30  	-e GO111MODULE=off \
    31  	-w /go/src/$(REPOPATH) \
    32  	$(BUILDIMAGE)
    33  
    34  DOCKERENV := docker $(DOCKERARGS)
    35  
    36  SOURCES := $(shell find . -name '*.go')
    37  APISOURCES := $(shell find apis -name '*.proto')
    38  APIGENSOURCES := $(shell find apis -name '*.go')
    39  
    40  .PHONY: all clean deps compile
    41  
    42  all: generate compile
    43  
    44  clean:
    45  	rm -Rf $(BIN) $(GOBUILDDIR)
    46  
    47  local:
    48  	@${MAKE} -B GOOS=$(shell go env GOHOSTOS) GOARCH=$(shell go env GOHOSTARCH) $(BIN)
    49  
    50  compile: $(SOURCES)
    51  	go build -mod=readonly github.com/binkynet/BinkyNet
    52  
    53  # Build docker builder image
    54  .PHONY: build-image
    55  build-image:
    56  	#docker buildx uninstall
    57  	docker build \
    58  		-t $(BUILDIMAGE) \
    59  		-f apis/Dockerfile.build apis 
    60  
    61  .PHONY: $(CACHEVOL)
    62  $(CACHEVOL):
    63  	@docker volume create $(CACHEVOL) || true
    64  	docker run -it 	--rm -v $(CACHEVOL):/usr/gocache \
    65  		$(BUILDIMAGE) \
    66  		chown -R $(shell id -u):$(shell id -g) /usr/gocache
    67  
    68  .PHONY: $(MODVOL)
    69  $(MODVOL):
    70  	@docker volume create $(MODVOL) || true
    71  	docker run -it 	--rm -v $(MODVOL):/go/pkg/mod \
    72  		$(BUILDIMAGE) \
    73  		chown -R $(shell id -u):$(shell id -g) /go/pkg/mod
    74  
    75  # Generate go code for k8s types & proto files
    76  .PHONY: generate
    77  generate: $(CACHEVOL) $(MODVOL)
    78  	$(DOCKERENV) go generate apis/v1/doc.go