Skip to content

Commit

Permalink
Update Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuka committed Mar 31, 2020
1 parent 6000cb8 commit 1042058
Showing 1 changed file with 36 additions and 49 deletions.
85 changes: 36 additions & 49 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CGO_ENABLED ?= 0
CGO_CFLAGS ?=
CGO_LDFLAGS ?=
BUILD_TAGS ?=
VERSION ?=
VERSION ?= $(shell git tag -l --sort=-v:refname | head -1)
BIN_EXT ?=
DOCKER_REPOSITORY ?= mosuka

Expand Down Expand Up @@ -38,111 +38,98 @@ GO := GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) CGO_CFLAGS=$(CGO_

.DEFAULT_GOAL := build

.PHONY: showenv
showenv:
@echo ">> show env"
@echo " GOOS = $(GOOS)"
@echo " GOARCH = $(GOARCH)"
@echo " GO111MODULE = $(GO111MODULE)"
@echo " CGO_ENABLED = $(CGO_ENABLED)"
@echo " CGO_CFLAGS = $(CGO_CFLAGS)"
@echo " CGO_LDFLAGS = $(CGO_LDFLAGS)"
@echo " BUILD_TAGS = $(BUILD_TAGS)"
@echo " VERSION = $(VERSION)"
@echo " BIN_EXT = $(BIN_EXT)"
@echo " DOCKER_REPOSITORY = $(DOCKER_REPOSITORY)"
@echo " LDFLAGS = $(LDFLAGS)"
@echo " PACKAGES = $(PACKAGES)"
@echo " PROTOBUFS = $(PROTOBUFS)"
@echo " TARGET_PACKAGES = $(TARGET_PACKAGES)"
@echo " GRPC_GATEWAY_PATH = $(GRPC_GATEWAY_PATH)"

.PHONY: protoc
protoc:
protoc: showenv
@echo ">> generating proto3 code"
for proto_dir in $(PROTOBUFS); do echo $$proto_dir; protoc --proto_path=. --proto_path=$$proto_dir --proto_path=${GRPC_GATEWAY_PATH} --proto_path=${GRPC_GATEWAY_PATH}/third_party/googleapis --go_out=plugins=grpc:$(GOPATH)/src $$proto_dir/*.proto || exit 1; done
for proto_dir in $(PROTOBUFS); do echo $$proto_dir; protoc --proto_path=. --proto_path=$$proto_dir --proto_path=${GRPC_GATEWAY_PATH} --proto_path=${GRPC_GATEWAY_PATH}/third_party/googleapis --grpc-gateway_out=logtostderr=true,allow_delete_body=true:$(GOPATH)/src $$proto_dir/*.proto || exit 1; done

.PHONY: format
format:
format: showenv
@echo ">> formatting code"
$(GO) fmt $(PACKAGES)

.PHONY: test
test:
test: showenv
@echo ">> testing all packages"
@echo " GOOS = $(GOOS)"
@echo " GOARCH = $(GOARCH)"
@echo " CGO_ENABLED = $(CGO_ENABLED)"
@echo " CGO_CFLAGS = $(CGO_CFLAGS)"
@echo " CGO_LDFLAGS = $(CGO_LDFLAGS)"
@echo " BUILD_TAGS = $(BUILD_TAGS)"
$(GO) test -v -tags="$(BUILD_TAGS)" $(PACKAGES)

.PHONY: coverage
coverage:
coverage: showenv
@echo ">> checking coverage of all packages"
$(GO) test -coverprofile=./cover.out -tags="$(BUILD_TAGS)" $(PACKAGES)
$(GO) tool cover -html=cover.out -o cover.html

.PHONY: clean
clean:
clean: showenv
@echo ">> cleaning binaries"
rm -rf ./bin
rm -rf ./data
rm -rf ./dist

.PHONY: build
build:
build: showenv
@echo ">> building binaries"
@echo " GOOS = $(GOOS)"
@echo " GOARCH = $(GOARCH)"
@echo " CGO_ENABLED = $(CGO_ENABLED)"
@echo " CGO_CFLAGS = $(CGO_CFLAGS)"
@echo " CGO_LDFLAGS = $(CGO_LDFLAGS)"
@echo " BUILD_TAGS = $(BUILD_TAGS)"
@echo " VERSION = $(VERSION)"
for target_pkg in $(TARGET_PACKAGES); do echo $$target_pkg; $(GO) build -tags="$(BUILD_TAGS)" $(LDFLAGS) -o ./bin/`basename $$target_pkg`$(BIN_EXT) $$target_pkg || exit 1; done

.PHONY: install
install:
install: showenv
@echo ">> installing binaries"
@echo " GOOS = $(GOOS)"
@echo " GOARCH = $(GOARCH)"
@echo " CGO_ENABLED = $(CGO_ENABLED)"
@echo " CGO_CFLAGS = $(CGO_CFLAGS)"
@echo " CGO_LDFLAGS = $(CGO_LDFLAGS)"
@echo " BUILD_TAGS = $(BUILD_TAGS)"
@echo " VERSION = $(VERSION)"
for target_pkg in $(TARGET_PACKAGES); do echo $$target_pkg; $(GO) install -tags="$(BUILD_TAGS)" $(LDFLAGS) $$target_pkg || exit 1; done

.PHONY: dist
dist:
dist: showenv
@echo ">> packaging binaries"
@echo " GOOS = $(GOOS)"
@echo " GOARCH = $(GOARCH)"
@echo " CGO_ENABLED = $(CGO_ENABLED)"
@echo " CGO_CFLAGS = $(CGO_CFLAGS)"
@echo " CGO_LDFLAGS = $(CGO_LDFLAGS)"
@echo " BUILD_TAGS = $(BUILD_TAGS)"
@echo " VERSION = $(VERSION)"
mkdir -p ./dist/$(GOOS)-$(GOARCH)/bin
for target_pkg in $(TARGET_PACKAGES); do echo $$target_pkg; $(GO) build -tags="$(BUILD_TAGS)" $(LDFLAGS) -o ./dist/$(GOOS)-$(GOARCH)/bin/`basename $$target_pkg`$(BIN_EXT) $$target_pkg || exit 1; done
(cd ./dist/$(GOOS)-$(GOARCH); tar zcfv ../cete-${VERSION}.$(GOOS)-$(GOARCH).tar.gz .)

.PHONY: tag
tag:
tag: showenv
@echo ">> tagging github"
@echo " VERSION = $(VERSION)"
ifeq ($(VERSION),$(filter $(VERSION),latest master ""))
@echo "please specify VERSION"
else
git tag -a $(VERSION) -m "Release $(VERSION)"
git push origin $(VERSION)
endif

.PHONY: build-docker
build-docker:
.PHONY: docker-build
docker-build: showenv
@echo ">> building docker container image"
@echo " DOCKER_REPOSITORY = $(DOCKER_REPOSITORY)"
@echo " VERSION = $(VERSION)"
docker build -t $(DOCKER_REPOSITORY)/cete:latest --build-arg VERSION=$(VERSION) .
docker tag $(DOCKER_REPOSITORY)/cete:latest $(DOCKER_REPOSITORY)/cete:$(VERSION)

.PHONY: push-docker
push-docker:
.PHONY: docker-push
docker-push: showenv
@echo ">> pushing docker container image"
@echo " DOCKER_REPOSITORY = $(DOCKER_REPOSITORY)"
@echo " VERSION = $(VERSION)"
docker push $(DOCKER_REPOSITORY)/cete:latest
docker push $(DOCKER_REPOSITORY)/cete:$(VERSION)

.PHONY: clean-docker
clean-docker:
.PHONY: docker-clean
docker-clean: showenv
docker rmi -f $(shell docker images --filter "dangling=true" -q --no-trunc)

.PHONY: cert
cert:
cert: showenv
@echo ">> generating certification"
openssl req -x509 -nodes -newkey rsa:4096 -keyout ./etc/cete-key.pem -out ./etc/cete-cert.pem -days 365 -subj '/CN=localhost'

0 comments on commit 1042058

Please sign in to comment.