Files
go-server-with-otel/Makefile
2025-07-20 11:38:17 -04:00

91 lines
2.7 KiB
Makefile

.PHONY: all test build docker install clean proto check_protoc
CMD_NAME := go-server-with-otel
VERSION ?= development
API_DIR := api/
SCHEMA_DIR := contrib/
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
GIT_REPO := gitea.libretechconsulting.com/rmcguire/go-server-with-otel
all: proto test build docker
proto: check_buf
buf dep update
buf generate
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"; \
mkdir -vp $(OUTPUT_DIR); \
echo "Building for $$platform into $$OUTPUT"; \
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 $(GIT_REPO):$(VERSION)"
docker build \
--build-arg VER_PKG=$(VER_PKG) \
--build-arg VERSION=$(VERSION) \
--build-arg APP_NAME=$(CMD_NAME) \
-t $(GIT_REPO):$(VERSION) .
docker push $(GIT_REPO):$(VERSION)
install:
go install -v -ldflags "-X $(VER_PKG)=$(VERSION)" .
clean:
rm -rf bin/${CMD_NAME}
check_buf:
@if ! command -v buf > /dev/null; then \
echo "Error: buf not found in PATH"; \
exit 1; \
fi
rename:
@echo "Current module path: $(GIT_REPO)"
@echo "Usage: make rename NAME=your/new/module/name APP=your-app-name"
@if [ -z "$(NAME)" ]; then \
echo "No package name provided. Aborting."; \
exit 1; \
fi
@if [ -z "$(APP)" ]; then \
echo "No app name provided. Aborting."; \
exit 1; \
fi
@echo "New name: app=$(APP) pkg=$(NAME)"
@echo "Are you sure you want to proceed? (y/N): " && read CONFIRM && if [ "$$CONFIRM" != "y" ] && [ "$$CONFIRM" != "Y" ]; then \
echo "Aborted."; \
exit 1; \
fi
@sed -i "s|APP_NAME=.*|APP_NAME=$(APP)|g" Dockerfile
@sed -i "s|^CMD_NAME := .*|CMD_NAME := $(APP)|g" Makefile
@sed -i "s|merge_file_name=.*|merge_file_name=$(APP)|g" buf.gen.yaml
@sed -i "s|^name: .*|name: $(APP)|g" helm/Chart.yaml
@sed -i "s|otelServiceName: .*|otelServiceName: $(APP)|g" helm/values.yaml
@sed -i "s|app=.*|app=$(APP)|g" helm/values.yaml
@sed -i "s|$(CMD_NAME)|$(APP)|g" README.md
@find . -type f -a \
\( -name '*.go' -o -name 'go.mod' \
-o -name 'go.sum' -o -name '*.proto' \
-o -name 'Makefile' \
-o -name '*.yml' -o -name '*.yaml' \
\) \
-not -path './.git' -not -path './.git/*' \
-exec sed -i "s|$(GIT_REPO)|$(NAME)|g" {} +
@echo "Project renamed to $(NAME)"