summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-31 16:09:12 -0600
committermo khan <mo@mokhan.ca>2025-07-31 16:09:12 -0600
commit311603d0c0b04d451e9fb8e5e8335dca8425e2c4 (patch)
treef38db8e10c4b55aef21c96c30fc71278c6e3d5c6 /Makefile
parentebb003ef2beaeee61104d6b88a342c5c9fa73b51 (diff)
Connect to postgresql
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile39
1 files changed, 30 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index ee81a5e..f50bc8d 100644
--- a/Makefile
+++ b/Makefile
@@ -3,9 +3,10 @@ GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD | sed 's/\//_/g')
IMAGE_TAG := $(PROJECT_NAME):$(GIT_BRANCH)
AUTHZD_BIN := bin/authzd
SPARKLED_BIN := bin/sparkled
+TOOL := bin/tool
ZED := bin/zed
-.PHONY: clean setup build test run db-setup
+.PHONY: clean setup build test run db-setup db-create db-stop db-reset
$(AUTHZD_BIN): $(shell find . -name "*.go" 2>/dev/null) go.sum
@go build -o $(AUTHZD_BIN) ./cmd/authzd/main.go
@@ -13,13 +14,15 @@ $(AUTHZD_BIN): $(shell find . -name "*.go" 2>/dev/null) go.sum
$(SPARKLED_BIN): $(shell find . -name "*.go" 2>/dev/null) go.sum
@go build -o $(SPARKLED_BIN) ./cmd/sparkled/main.go
-clean:
+db-clean:
+ @rm -rf tmp/postgres tmp/postgres.log
+
+clean: db-clean
@rm -f $(AUTHZD_BIN) $(SPARKLED_BIN)
@go clean -testcache
setup:
@mise install
- @mise exec go -- go install github.com/xlgmokha/minit@latest
@mise exec go -- go mod tidy
@mise exec go -- go mod vendor
@mise exec go -- go tool
@@ -28,6 +31,12 @@ setup:
fi
@mise exec python -- pip install dumb-init
+Procfile: Procfile.template
+ @grep -v "# DEV_ONLY:" Procfile.template > Procfile
+
+Procfile.dev: Procfile.template
+ @sed 's/# DEV_ONLY: //' Procfile.template > Procfile.dev
+
build: $(AUTHZD_BIN) $(SPARKLED_BIN)
test-schema:
@@ -44,24 +53,25 @@ test-integration: build-image
test: clean test-unit test-schema test-integration
-build-image:
+build-image: Procfile
@docker build --network=host --no-cache --tag $(IMAGE_TAG) .
-run: clean build
- @go tool godotenv -f .env.local,.env minit
+run: clean build Procfile.dev db-init
+ @$(TOOL) godotenv -f .env.local,.env $(TOOL) minit -f Procfile.dev
run-image: clean build-image
- @docker run --rm --network host --env-file .env.local -p 10000:10000 -p 9901:9901 -p 8080:8080 -it $(IMAGE_TAG)
+ @docker run --rm --network host --env-file .env.local -p 10000:10000 -it $(IMAGE_TAG)
lint:
- @go tool yamlfmt -lint -exclude vendor .
+ @$(TOOL) yamlfmt -lint -exclude vendor .
@$(ZED) validate etc/authzd/*
tidy:
@go get -u ./...
+ @go tool | grep github | awk '{print $1}' | xargs -I {} go get -tool {}@latest
@go mod tidy
@go mod vendor
- @go tool yamlfmt -exclude vendor .
+ @$(TOOL) yamlfmt -exclude vendor .
db-schema-load:
@$(ZED) schema write etc/authzd/schema.zed
@@ -69,4 +79,15 @@ db-schema-load:
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-setup: db-schema-load db-seed