reference implementation of go app
This commit is contained in:
63
Makefile
Normal file
63
Makefile
Normal file
@ -0,0 +1,63 @@
|
||||
CMD_NAME := demo-app # TODO: Update app name
|
||||
|
||||
.PHONY: all test build docker install clean proto check_protoc
|
||||
|
||||
VERSION ?= development # Default to "development" if VERSION is not set
|
||||
APIVERSION := v1alpha1
|
||||
API_DIR := api/$(APIVERSION)
|
||||
PROTO_DIRS := $(wildcard proto/demo/app/*) # TODO: Update path (probably not demo)
|
||||
PLATFORMS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
|
||||
OUTPUT_DIR := bin
|
||||
VER_PKG := gitea.libretechconsulting.com/rmcguire/go-app/pkg/config.Version
|
||||
DOCKER_IMG := gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel
|
||||
|
||||
all: proto test build docker
|
||||
|
||||
proto: check_protoc $(API_DIR)
|
||||
protoc --proto_path=proto --proto_path=proto/google \
|
||||
--go_out=$(API_DIR) --go_opt=paths=source_relative \
|
||||
--go-grpc_out=$(API_DIR) --go-grpc_opt=paths=source_relative \
|
||||
--grpc-gateway_out=$(API_DIR) --grpc-gateway_opt=paths=source_relative \
|
||||
--openapiv2_out=$(API_DIR) \
|
||||
$(foreach dir, $(PROTO_DIRS), $(wildcard $(dir)/*.proto))
|
||||
|
||||
test:
|
||||
go test -v ./...
|
||||
|
||||
build: test
|
||||
@echo "Building for platforms: $(PLATFORMS)"
|
||||
@for platform in $(PLATFORMS); do \
|
||||
OS=$$(echo $$platform | cut -d/ -f1); \
|
||||
ARCH=$$(echo $$platform | cut -d/ -f2); \
|
||||
OUTPUT="$(OUTPUT_DIR)/$(CMD_NAME)-$$OS-$$ARCH"; \
|
||||
GOOS=$$OS GOARCH=$$ARCH go build -ldflags "-X $(VER_PKG)=$(VERSION)" -o $$OUTPUT; \
|
||||
echo "Built $$OUTPUT"; \
|
||||
done
|
||||
go build -ldflags "-X $(VER_PKG)=$(VERSION)" -o bin/${CMD_NAME}
|
||||
|
||||
schema:
|
||||
go run . -schema > contrib/schema.json
|
||||
|
||||
docker:
|
||||
@echo "Building Docker image $(DOCKER_IMG):$(VERSION)"
|
||||
docker build \
|
||||
--build-arg VER_PKG=$(VER_PKG) \
|
||||
--build-arg VERSION=$(VERSION) \
|
||||
-t $(DOCKER_IMG):$(VERSION) .
|
||||
docker push $(DOCKER_IMG):$(VERSION)
|
||||
|
||||
install:
|
||||
go install -v -ldflags "-X $(VER_PKG)=$(VERSION)" .
|
||||
|
||||
clean:
|
||||
rm -rf bin/${CMD_NAME}
|
||||
|
||||
check_protoc:
|
||||
@if ! command -v protoc-gen-go > /dev/null; then \
|
||||
echo "Error: protoc-gen-go not found in PATH"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@if ! command -v protoc-gen-go-grpc > /dev/null; then \
|
||||
echo "Error: protoc-gen-go-grpc not found in PATH"; \
|
||||
exit 1; \
|
||||
fi
|
Reference in New Issue
Block a user