summaryrefslogtreecommitdiff
path: root/Makefile
blob: dd34b0e6a6e6e0f9dfb4c2cb2ec9618cda663672 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
PROJECT_NAME := $(shell basename $(shell pwd))
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD | sed 's/\//_/g')
IMAGE_TAG := $(PROJECT_NAME):$(GIT_BRANCH)
AUTHZD_BIN := bin/authzd
DOCKER := docker
GO := mise exec go -- go
MISE := bin/mise
SPARKLED_BIN := bin/sparkled
SPICEDB := bin/spicedb
TOOL := bin/tool
ZED := bin/zed

.PHONY: db-clean clean setup build test-schema test-unit test-race test-integration test build-image run run-image lint tidy db-schema-load db-seed db-stop db-reset db-init db-create db-migrate db-console db-setup

$(AUTHZD_BIN): $(shell find . -name "*.go" 2>/dev/null) go.sum
	@$(GO) build -mod=vendor -o $(AUTHZD_BIN) ./cmd/authzd/main.go

$(SPARKLED_BIN): $(shell find . -name "*.go" 2>/dev/null) go.sum
	@$(GO) build -mod=vendor -o $(SPARKLED_BIN) ./cmd/sparkled/main.go

db-clean:
	@rm -rf tmp/postgres tmp/postgres.log

clean: db-clean
	@rm -f $(AUTHZD_BIN) $(SPARKLED_BIN)
	@$(GO) clean -testcache

setup:
	@$(MISE) install
	@if command -v brew >/dev/null 2>&1; then \
		brew bundle; \
	fi
	@$(MISE) exec python -- pip install dumb-init

build: $(AUTHZD_BIN) $(SPARKLED_BIN)

test-schema:
	@$(ZED) validate etc/authzd/*.yaml

test-unit:
	@$(GO) test -shuffle=on ./...

test-race:
	@CGO_ENABLED=1 $(GO) test -race -shuffle=on ./...

test-integration: build-image
	@IMAGE_TAG=$(IMAGE_TAG) $(GO) test -tags=integration ./test/integration/...

test: clean test-unit test-race test-integration test-schema

build-image:
	@$(DOCKER) build --network=host --tag $(IMAGE_TAG) .

run: clean build db-init
	@$(TOOL) godotenv -f .env.local,.env $(TOOL) minit -f Procfile.development

run-image: clean build-image
	@$(DOCKER) run --rm --network host --env-file .env.local -v $(PWD)/Procfile.development:/Procfile -p 10000:10000 -it $(IMAGE_TAG)

lint:
	@$(TOOL) yamlfmt -lint -exclude vendor .
	@$(ZED) validate etc/authzd/*

tidy:
	@$(GO) mod tidy
	@$(TOOL) yamlfmt -exclude vendor .

db-schema-load:
	@$(ZED) schema write etc/authzd/schema.zed

db-seed:
	@$(ZED) import etc/authzd/relationships.yaml

db-stop:
	@$(MISE) exec postgres -- pg_ctl -D tmp/postgres stop || true

db-reset: db-stop db-clean db-create

db-init:
	@[ ! -d tmp/postgres ] && $(MISE) exec postgres -- initdb -D tmp/postgres || true
	
db-create: db-init
	@$(MISE) exec postgres -- createdb -h /tmp sparkle_development || true

db-migrate:
	@$(TOOL) godotenv -f .env.local,.env -- sh -c '$(SPICEDB) datastore migrate head --datastore-engine postgres --datastore-conn-uri "$$DATABASE_URL" --log-level trace --skip-release-check'

db-console:
	@$(MISE) exec postgres -- psql -h /tmp sparkle_development

db-setup: db-create # db-schema-load db-seed