97 lines
2.8 KiB
Makefile
97 lines
2.8 KiB
Makefile
SHELL := /bin/sh
|
|
|
|
GO_MODULE := git.toki-labs.com/toki/rara
|
|
PROTO_ROOT := api/proto
|
|
PROTO_FILE := $(PROTO_ROOT)/rara/v1/executor.proto
|
|
PYTHON_ROOT := packages/python
|
|
VENV := .venv
|
|
VENV_READY := $(VENV)/.ready
|
|
TOOLS_DIR := $(CURDIR)/.tools
|
|
PROTOC_GEN_GO := $(TOOLS_DIR)/protoc-gen-go
|
|
PROTOC_GEN_GO_GRPC := $(TOOLS_DIR)/protoc-gen-go-grpc
|
|
SQLC := $(TOOLS_DIR)/sqlc
|
|
DATABASE_URL ?= postgres://rara:rara@localhost:5432/rara?sslmode=disable
|
|
|
|
.PHONY: all setup tools generate proto sqlc fmt test test-go test-python build \
|
|
python-sync db-up db-down migrate-up migrate-down migrate-status
|
|
|
|
all: setup fmt test build
|
|
|
|
setup: generate
|
|
|
|
tools: $(PROTOC_GEN_GO) $(PROTOC_GEN_GO_GRPC) $(SQLC)
|
|
|
|
generate: proto sqlc
|
|
|
|
proto: $(VENV_READY) $(PROTOC_GEN_GO) $(PROTOC_GEN_GO_GRPC)
|
|
mkdir -p gen/go $(PYTHON_ROOT)/src
|
|
protoc -I $(PROTO_ROOT) \
|
|
--plugin=protoc-gen-go=$(PROTOC_GEN_GO) \
|
|
--plugin=protoc-gen-go-grpc=$(PROTOC_GEN_GO_GRPC) \
|
|
--go_out=gen/go --go_opt=paths=source_relative \
|
|
--go-grpc_out=gen/go --go-grpc_opt=paths=source_relative \
|
|
$(PROTO_FILE)
|
|
$(VENV)/bin/python -m grpc_tools.protoc -I $(PROTO_ROOT) \
|
|
--python_out=$(PYTHON_ROOT)/src \
|
|
--grpc_python_out=$(PYTHON_ROOT)/src \
|
|
$(PROTO_FILE)
|
|
|
|
sqlc: $(SQLC)
|
|
$(SQLC) generate
|
|
|
|
fmt: $(VENV_READY)
|
|
gofmt -w $$(find apps packages gen -name '*.go' -type f 2>/dev/null)
|
|
$(VENV)/bin/python -m ruff format $(PYTHON_ROOT)/src $(PYTHON_ROOT)/tests
|
|
$(VENV)/bin/python -m ruff check --fix $(PYTHON_ROOT)/src $(PYTHON_ROOT)/tests
|
|
|
|
test: test-go test-python
|
|
|
|
test-go:
|
|
go test ./...
|
|
|
|
test-python: $(VENV_READY)
|
|
PYTHONPATH=$(PYTHON_ROOT)/src $(VENV)/bin/python -m pytest $(PYTHON_ROOT)/tests
|
|
|
|
build:
|
|
mkdir -p bin
|
|
go build -o bin/rara-control-plane ./apps/control-plane/cmd/control-plane
|
|
go build -o bin/rara-rag-api ./apps/rag-api/cmd/rag-api
|
|
go build -o bin/rara-worker ./apps/worker/cmd/worker
|
|
|
|
python-sync: $(VENV_READY)
|
|
|
|
$(VENV_READY): $(PYTHON_ROOT)/pyproject.toml
|
|
python3 -m venv $(VENV)
|
|
$(VENV)/bin/pip install --upgrade pip
|
|
$(VENV)/bin/pip install -e '$(PYTHON_ROOT)[dev]'
|
|
touch $(VENV_READY)
|
|
|
|
$(PROTOC_GEN_GO):
|
|
mkdir -p $(TOOLS_DIR)
|
|
GOBIN=$(TOOLS_DIR) go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.11
|
|
|
|
$(PROTOC_GEN_GO_GRPC):
|
|
mkdir -p $(TOOLS_DIR)
|
|
GOBIN=$(TOOLS_DIR) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.6.1
|
|
|
|
$(SQLC):
|
|
mkdir -p $(TOOLS_DIR)
|
|
GOBIN=$(TOOLS_DIR) go install github.com/sqlc-dev/sqlc/cmd/sqlc@v1.31.1
|
|
|
|
db-up:
|
|
docker compose -f deploy/compose.yaml up -d postgres
|
|
|
|
db-down:
|
|
docker compose -f deploy/compose.yaml down
|
|
|
|
migrate-up:
|
|
go run github.com/pressly/goose/v3/cmd/goose@v3.24.1 \
|
|
-dir db/migrations postgres '$(DATABASE_URL)' up
|
|
|
|
migrate-down:
|
|
go run github.com/pressly/goose/v3/cmd/goose@v3.24.1 \
|
|
-dir db/migrations postgres '$(DATABASE_URL)' down
|
|
|
|
migrate-status:
|
|
go run github.com/pressly/goose/v3/cmd/goose@v3.24.1 \
|
|
-dir db/migrations postgres '$(DATABASE_URL)' status
|