-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
190 lines (141 loc) · 5.93 KB
/
Copy pathMakefile
File metadata and controls
190 lines (141 loc) · 5.93 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
SERVER_IMAGE := ghcr.io/cloudoperators/heureka
VERSION ?= $(shell git log -1 --pretty=format:"%H")
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
SHELL=/bin/bash
MIGRATIONS_DIR=internal/database/mariadb/migrations/
.PHONY: all test doc gqlgen mockery test-all test-e2e test-app test-db lint fmt pre-commit-prepare compose-prepare compose-up compose-down compose-restart compose-build check-call-cached check-migration-files
# Source the .env file to use the env vars with make
-include .env
ifeq ($(wildcard .env),.env)
$(info .env file found, exporting variables)
export $(shell sed 's/=.*//' .env)
endif
all: build-binary test-all
build-binary: mockery gqlgen
GO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o build/heureka cmd/heureka/main.go
# Build the binary and execute it
run-%: mockery gqlgen
GOOS=$(OS) GOARCH=$(ARCH) go build -ldflags="$(LDFLAGS)" -o build/$* cmd/$*/main.go
DB_SCHEMA=./internal/database/mariadb/init/schema.sql ./build/$*
# Start ONLY the database container and replace the pg_hba_conf.sh created by `create-pg-hba-conf`
start: stop
docker-compose --profile db up
# Start all container. This expects the heureka bin to be amd64 because the image in the docker-compose is amd64
start-all-%: stop
docker-compose --profile db --profile heureka up --build --force-recreate
stop:
@rm -rf ./.db/data
docker-compose --profile db --profile heureka down
clean:
docker-compose down --rmi all --volumes --remove-orphans
echo:
echo "version:" $(VERSION)
build-image:
docker buildx build -t $(SERVER_IMAGE):$(VERSION) -t $(SERVER_IMAGE):latest . --load
build-scanner-images: build-scanner-k8s-assets-image build-scanner-keppel-image build-scanner-nvd-image
build-scanner-k8s-assets-image:
docker buildx build -t $(SERVER_IMAGE)-scanner-k8s-assets:$(VERSION) -t $(SERVER_IMAGE)-scanner-k8s-assets:latest -f ./scanner/k8s-assets/Dockerfile . --load
build-scanner-keppel-image:
docker buildx build -t $(SERVER_IMAGE)-scanner-keppel:$(VERSION) -t $(SERVER_IMAGE)-scanner-keppel:latest -f ./scanner/keppel/Dockerfile . --load
build-scanner-nvd-image:
docker buildx build -t $(SERVER_IMAGE)-scanner-nvd:$(VERSION) -t $(SERVER_IMAGE)-scanner-nvd:latest -f ./scanner/nvd/Dockerfile . --load
push:
docker push $(SERVER_IMAGE):$(VERSION)
docker push $(SERVER_IMAGE):latest
run:
go run cmd/heureka/main.go
gqlgen: install-build-dependencies gqlclient
cd internal/api/graphql && gqlgen generate
gqlclient:
cd scanner/k8s-assets/client && go run github.com/Khan/genqlient
mockery: install-build-dependencies
mockery
install-build-dependencies:
go install github.com/vektra/mockery/v2@v2.52.2
go install github.com/onsi/ginkgo/v2/ginkgo
go install github.com/99designs/gqlgen
test-all: mockery gqlgen install-build-dependencies
ginkgo -r
test-e2e: gqlgen install-build-dependencies
ginkgo -r internal/e2e
test-app: gqlgen install-build-dependencies
ginkgo -r internal/app
test-access: gqlgen install-build-dependencies
ginkgo -r internal/api/graphql/access
test-authorization: gqlgen install-build-dependencies
ginkgo -r internal/openfga
test-db: gqlgen install-build-dependencies
ginkgo -r internal/database/mariadb
install-gofumpt:
go install mvdan.cc/gofumpt@latest
fmt: install-gofumpt
gofumpt -l -w internal/
install-golangci-lint:
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.8.0
lint: install-golangci-lint
golangci-lint run
lint-fix: install-golangci-lint
golangci-lint run --fix
install-pre-commit:
@echo "Checking pre-commit installation..."
@if command -v pre-commit >/dev/null 2>&1; then \
echo "pre-commit already installed"; \
else \
echo "Installing pre-commit..."; \
if [ "$$(uname)" = "Darwin" ]; then \
if command -v brew >/dev/null 2>&1; then \
brew install pre-commit; \
else \
pip3 install pre-commit; \
fi; \
elif [ "$$(uname)" = "Linux" ]; then \
if command -v pip3 >/dev/null 2>&1; then \
pip3 install pre-commit; \
else \
echo "pip3 not found, please install Python/pip"; \
exit 1; \
fi; \
elif echo "$$(uname)" | grep -qi "mingw\\|msys\\|cygwin"; then \
pip install pre-commit; \
else \
echo "Unknown OS, please install pre-commit manually"; \
exit 1; \
fi; \
fi
pre-commit-prepare: install-pre-commit
pre-commit install
pre-commit install --hook-type pre-push
DOCKER_COMPOSE := docker-compose -f docker-compose.yaml
DOCKER_COMPOSE_SERVICES := heureka-app heureka-db valkey
compose-prepare:
sed 's/^SEED_MODE=false/SEED_MODE=true/g' .test.env > .env
compose-up:
$(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_SERVICES)
compose-down:
$(DOCKER_COMPOSE) down $(DOCKER_COMPOSE_SERVICES)
compose-restart: compose-down compose-up
compose-build:
$(DOCKER_COMPOSE) build $(DOCKER_COMPOSE_SERVICES)
install-migrate:
go install -tags 'heureka-migration' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
create-migration:
@(test -v MIGRATION_NAME && migrate create -ext sql -dir internal/database/mariadb/migrations ${MIGRATION_NAME}) || echo MIGRATION_NAME not specified >&2
check-call-cached:
go generate ./internal/cache
# check-migration-files target:
# First check if '!checkexistingmigration' smart commit tag is not used in any commit on your branch
# if it is used, then skip further check
# if smart commit was not found, check for modification of any migration file existing in main branch
# NOTE: new files created in your branch will not be checked for modification/creation
check-migration-files:
@git log origin/main..HEAD --pretty=%B | grep -Eq "[!]changeexistingmigration" || \
(comm -12 <(git diff --name-only origin/main...HEAD | grep '^$(MIGRATIONS_DIR)' | sort) <(git ls-tree -r --name-only origin/main | grep '^$(MIGRATIONS_DIR)' | sort) | grep -q . && { echo "Forbidden change detected!"; exit 1; } || echo "No forbidden changes.")
ui-up:
$(DOCKER_COMPOSE) --profile ui up -d
ui-down:
$(DOCKER_COMPOSE) --profile ui down
openfga-up:
$(DOCKER_COMPOSE) --profile openfga up
openfga-down:
$(DOCKER_COMPOSE) --profile openfga down