forked from leg100/otf
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
159 lines (130 loc) · 4.59 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
155
156
157
158
159
VERSION ?= $(shell git describe --tags --dirty --always)
GIT_COMMIT = $(shell git rev-parse HEAD)
RANDOM_SUFFIX := $(shell cat /dev/urandom | tr -dc 'a-z0-9' | head -c5)
# Provide some sane defaults for connecting to postgres.
PGPASSWORD ?= $(shell kubectl get secrets postgres-postgresql -oyaml | yq '.data["password"]' -r | base64 -d)
PGUSER ?= tofutf
DBSTRING ?= postgres://$(PGUSER):$(PGPASSWORD)@localhost:5432/postgres
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
.PHONY: dev
dev:
./hack/dev.sh
.PHONY: go-tfe-tests
go-tfe-tests: image compose-up
./hack/go-tfe-tests.bash
.PHONY: watch
watch: tailwind-watch
.PHONY: tailwind
tailwind:
pnpm exec tailwindcss -i ./internal/http/html/static/css/input.css -o ./internal/http/html/static/css/output.css
.PHONY: tailwind-watch
tailwind-watch:
+pnpm exec tailwindcss -i ./internal/http/html/static/css/input.css -o ./internal/http/html/static/css/output.css --watch
.PHONY: test
test:
go test -short ./...
.PHONY: k3d-up
k3d-up:
k3d cluster create --config=./hack/k3d.yaml
.PHONY: k3d-down
k3d-down:
k3d cluster delete tofutf
# Run staticcheck metalinter recursively against code
.PHONY: lint
lint:
golangci-lint run ./...
# Run go fmt against code
.PHONY: fmt
fmt:
go fmt ./...
# Run go vet against code
.PHONY: vet
vet:
go vet ./...
# Install sql code generator
.PHONY: install-pggen
install-pggen:
@sh -c "which pggen > /dev/null || go install github.com/robbert229/pggen/cmd/pggen@latest"
.PHONY: install-air
install-air:
@sh -c "which air > /dev/null || go install github.com/cosmtrek/air@latest"
# Generate sql code
.PHONY: sql
sql: install-pggen
pggen gen go \
--postgres-connection $(DBSTRING) \
--query-glob 'internal/sql/queries/*.sql' \
--output-dir ./internal/sql/pggen \
--go-type 'inet=net.IPNet' \
--go-type 'text=github.com/jackc/pgx/v5/pgtype.Text' \
--go-type 'int4=github.com/jackc/pgx/v5/pgtype.Int4' \
--go-type 'int8=github.com/jackc/pgx/v5/pgtype.Int8' \
--go-type 'bool=github.com/jackc/pgx/v5/pgtype.Bool' \
--go-type 'bytea=[]byte' \
--acronym url \
--acronym cli \
--acronym sha \
--acronym json \
--acronym vcs \
--acronym html \
--acronym http \
--acronym tls \
--acronym sso \
--acronym hcl \
--acronym ip \
--acronym gpg
goimports -w ./internal/sql/pggen
go fmt ./internal/sql/pggen
# Install DB migration tool
.PHONY: install-goose
install-goose:
@sh -c "which goose > /dev/null || go install github.com/pressly/goose/v3/cmd/goose@latest"
.PHONY: install-gowrap
install-gowrap:
@sh -c "which goose > /dev/null || go install github.com/hexdigest/gowrap/cmd/gowrap@latest"
# Migrate SQL schema to latest version
.PHONY: migrate
migrate: install-goose
GOOSE_DBSTRING=$(DBSTRING) GOOSE_DRIVER=postgres goose -dir ./internal/sql/migrations up
# Redo SQL schema migration
.PHONY: migrate-redo
migrate-redo: install-goose
GOOSE_DBSTRING=$(DBSTRING) GOOSE_DRIVER=postgres goose -dir ./internal/sql/migrations redo
# Rollback SQL schema by one version
.PHONY: migrate-rollback
migrate-rollback: install-goose
GOOSE_DBSTRING=$(DBSTRING) GOOSE_DRIVER=postgres goose -dir ./internal/sql/migrations down
# Get SQL schema migration status
.PHONY: migrate-status
migrate-status: install-goose
GOOSE_DBSTRING=$(DBSTRING) GOOSE_DRIVER=postgres goose -dir ./internal/sql/migrations status
.PHONY: doc-screenshots
doc-screenshots: # update documentation screenshots
OTF_DOC_SCREENSHOTS=true go test ./internal/integration/... -count 1
# serve the docs
.PHONY: serve-docs
serve-docs:
cd ./docs && pnpm dev
# Generate path helpers
.PHONY: paths
paths:
go generate ./internal/http/html/paths
goimports -w ./internal/http/html/paths
# Re-generate RBAC action strings
.PHONY: actions
actions:
stringer -type Action ./internal/rbac
.PHONY: publish
publish:
VERSION=$(VERSION) KO_DOCKER_REPO=ghcr.io/tofutf/tofutf/ ko resolve --base-import-paths -t $(VERSION) -f ./charts/tofutf/values.yaml.tmpl > ./charts/tofutf/values.yaml
yq 'select(di == 0) | .image.tag = .image.override | del(.image.override) | del(.agent) | .image.tag |= sub("ghcr.io/tofutf/tofutf/tofutfd:", "")' -i ./charts/tofutf/values.yaml
yq ".version=\"$(VERSION)\" | .appVersion=\"$(VERSION)\"" -i ./charts/tofutf/Chart.yaml
helm package ./charts/tofutf --app-version $(VERSION) --version $(VERSION) --destination=./hack/charts/
helm push ./hack/charts/tofutf-$(VERSION).tgz oci://ghcr.io/tofutf/tofutf/charts
publish-dev:
VERSION=$(VERSION) KO_DOCKER_REPO=ghcr.io/tofutf/tofutf/ ko build --base-import-paths -t dev ./cmd/tofutfd