This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
154 lines (120 loc) · 4.51 KB
/
Makefile
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
VERSION := $(shell git describe --tags --always --dirty="-dev")a
DATE := $(shell date '+%Y-%m-%d-%H%M UTC')
VERSION_FLAGS := -ldflags='-X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
DSN := postgres://gourd:gourd@localhost:5555/food?sslmode=disable
.PHONY: all
all: bin/gourd
# general dev
test: unit-test-go lint-go test-rs
dev-env:
docker compose -f dockerfiles/docker-compose-deps.yml -f dockerfiles/docker-compose-devdeps.yml up -d db meilisearch meilisearch-ui jaeger collector
dev-air: bin/air
HTTP_HOST=127.0.0.1 ./bin/air -c tooling/dev/air.conf
install-deps:
go mod tidy
go mod vendor
go mod tidy
cd ui && yarn
# frontend dev
dev-ui:
cd ui && yarn run dev
cy:
cd ui && yarn run cy:open
# rust dev
dev-rs:
cd rust && RUST_BACKTRACE=1 RUST_LOG=html5ever=info,selectors=info,debug cargo watch -x 'run server'
test-rs:
cd rust && cargo test
# db
dev-db:
pgcli $(DSN)
dev-db-stats:
docker logs gourd_db_1 2>&1 | pgbadger - --prefix '%t [%p]:[%l] user=%u, db=%d'
new-migrate/%: bin/migrate
mkdir -p internal/db/migrations
./bin/migrate create -dir internal/db/migrations -ext sql $(@F)
migrate: bin/migrate
./bin/migrate -source file://internal/db/migrations -database $(DSN) up
migrate-down: bin/migrate
./bin/migrate -source file://internal/db/migrations -database $(DSN) down
# golang
bin/%: $(shell find . -type f -name '*.go' | grep -v '_test.go')
@mkdir -p $(dir $@)
CGO_ENABLED=0 go build $(VERSION_FLAGS) -o $@ ./internal/cmd/$(@F)
bin/air:
@mkdir -p $(dir $@)
go build -o $@ ./vendor/github.com/air-verse/air
bin/golangci-lint:
@mkdir -p $(dir $@)
go build -o $@ ./vendor/github.com/golangci/golangci-lint/cmd/golangci-lint
bin/migrate:
@mkdir -p $(dir $@)
go build -tags 'postgres' -o $@ ./vendor/github.com/golang-migrate/migrate/v4/cmd/migrate
bin/go-acc:
@mkdir -p $(dir $@)
go build -o $@ ./vendor/github.com/ory/go-acc
unit-test-go:
go test -v -race -cover ./...
integration-test-go: bin/go-acc
./bin/go-acc -o coverage-integration.txt ./... -- -race -tags integration -v
unit-cover-go: bin/go-acc
./bin/go-acc -o coverage-full.txt ./... -- -race
lint-go: bin/golangci-lint
bin/golangci-lint run || (echo "lint failed"; exit 1)
generate: wasm-dev openapi # gen-db
.PHONY: openapi
openapi: internal/api/openapi.yaml
internal/api/openapi.yaml: tooling/schemas/gourd.yaml tooling/schemas/usda.yaml
# generate merged bundle
npx @redocly/openapi-cli bundle tooling/schemas/gourd.yaml --output internal/api/openapi.yaml
# ui hooks 1
cd ui && npx openapi-codegen gen gourdApi
# rust
rm -rf rust/openapi/src/models
npx @openapitools/openapi-generator-cli generate -i internal/api/openapi.yaml \
-o rust/openapi -g rust --global-property models,supportingFiles,modelDocs=false
cd rust/openapi && cargo clippy --fix --allow-staged --allow-dirty
# go
go generate ./internal/api
openapi-docs:
npx @redocly/openapi-cli preview-docs internal/api/openapi.yaml -p 8081
# WASM generation
.PHONY: generate-wasm
generate-wasm: rust/wasm/pkg
rust/wasm/pkg: $(shell find rust/ -type f -name '*.rs')
cd rust && wasm-pack build wasm
ui/src/wasm/package.json: rust/wasm/pkg/package.json
cp -r rust/wasm/pkg/ ui/src/wasm/
wasm-dev: generate-wasm ui/src/wasm/package.json
# GO SQL GENERATION
gen-db:
rm -rf db/models/
sqlboiler psql --relation-tag rel --config ./tooling/sqlboiler.toml --output ./internal/db/models --add-soft-deletes
# misc dev
# https://jqplay.org/s/c1T3lLCJwH
get-detail/%:
curl -s http://localhost:4242/api/recipes/$(@F) | jq '.detail | del(.. | .id?)' > tmp1
dyff yaml tmp1 | pbcopy
rm tmp1
seed-testdata: bin/gourd
./tooling/testdata/seed.mjs
# todo import usda
devdata: seed-testdata sync
sync: bin/gourd
./bin/gourd sync
insert-album:
PGPASSWORD=gourd psql -Atx "$(DSN)" -h localhost -U gourd -d food -p 5555 -c "INSERT INTO "public"."gphotos_albums" ("id", "usecase") VALUES ('AIbigFomDsn4esVUopzvXsZ5GDjY3EDb7L_A8sf1Wf7-IWHxykoMjVy-KeCTHW7nVIaTkJ8CAV8i', 'food'), ('AIbigFobaVQFOEyoZk2TKEkCNS-ffzesGu7n-OZy6-YXnKLgrYE4ALSW-LknhcbttNNifPPCm7sY','plants');"
# GCP_PROJECT := cloudrun1-278204
# GCR_IMAGE := gcr.io/$(GCP_PROJECT)/gourd-backend:$(VERSION)
# IMAGE := nicky/gourd-backend
# deploy: deploy-image deploy-run
# deploy-image:
# echo "building $(GCR_IMAGE)"
# gcloud builds submit --tag $(GCR_IMAGE)
# deploy-run:
# echo "deploying $(GCR_IMAGE)"
# terraform apply -var-file="prod.tfvars" -var="image_name=$(GCR_IMAGE)" -var="project_id=$(GCP_PROJECT)"
# docker-build:
# docker build -t $(IMAGE) .
# docker-push: docker-build
# docker push $(IMAGE):latest