-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
298 lines (259 loc) · 9.77 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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
## FastTrackML
## For best results, run these make targets inside the devcontainer
#
# Project-specific variables
#
# App name.
APP=fml
ifeq ($(shell go env GOOS),windows)
APP:=$(APP).exe
endif
# Version.
# Use git describe to get the version.
# If the git describe fails, fallback to a version based on the git commit.
VERSION?=$(shell git describe --tags --dirty --match='v*' 2> /dev/null | sed 's/^v//')
ifeq ($(VERSION),)
VERSION=0.0.0-g$(shell git describe --always --dirty 2> /dev/null)
endif
# Go ldflags.
# Strip debug symbols and disable DWARF generation.
# Build static binaries on Linux.
GO_LDFLAGS=-s -w -X github.com/G-Research/fasttrackml/pkg/version.Version=$(VERSION)
ifeq ($(shell go env GOOS),linux)
GO_LDFLAGS+=-linkmode external -extldflags -static
endif
# Go build tags.
GO_BUILDTAGS=$(shell cat .go-build-tags 2> /dev/null)
# Archive information.
# Use zip on Windows, tar.gz on Linux and macOS.
# Use GNU tar on macOS if available, to avoid issues with BSD tar.
ifeq ($(shell go env GOOS),windows)
ARCHIVE_EXT=zip
ARCHIVE_CMD=zip -r
else
ARCHIVE_EXT=tar.gz
ARCHIVE_CMD=tar -czf
ifeq ($(shell which gtar >/dev/null 2>/dev/null; echo $$?),0)
ARCHIVE_CMD:=g$(ARCHIVE_CMD)
endif
endif
ARCHIVE_NAME=dist/fasttrackml_$(shell go env GOOS | sed s/darwin/macos/)_$(shell go env GOARCH | sed s/amd64/x86_64/).$(ARCHIVE_EXT)
ARCHIVE_FILES=$(APP) LICENSE README.md
# Docker compose file.
COMPOSE_FILE=tests/integration/docker-compose.yml
# Docker compose project name.
COMPOSE_PROJECT_NAME=$(APP)-integration-tests
AIM_BUILD_LOCATION=$(HOME)/fasttrackml-ui-aim
MLFLOW_BUILD_LOCATION=$(HOME)/fasttrackml-ui-mlflow
#
# Default target (help).
#
.PHONY: help
help: ## display this help.
@echo "Please use \`make <target>' where <target> is one of:"
@echo
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-30s\033[0m - %s\n", $$1, $$2}'
@echo
#
# Tools targets.
# This needs to be kept in sync with .devcontainer/Dockerfile.
#
.PHONY: install-tools
install-tools: ## install tools.
@echo '>>> Installing tools.'
@go install github.com/vektra/mockery/[email protected]
@go install github.com/golangci/golangci-lint/cmd/[email protected]
@go install golang.org/x/tools/cmd/[email protected]
@go install mvdan.cc/[email protected]
#
# Linter targets.
#
.PHONY: lint
lint: go-lint python-lint ## run set of linters over the code.
#
# Go targets.
#
.PHONY: go-get
go-get: ## get go modules.
@echo '>>> Getting go modules.'
@go mod download
.PHONY: go-build
go-build: ## build app binary.
@echo '>>> Building go binary.'
@CGO_ENABLED=1 go build -ldflags="$(GO_LDFLAGS)" -tags="$(GO_BUILDTAGS)" -o $(APP) ./main.go
.PHONY: go-format
go-format: ## format go code.
@echo '>>> Formatting go code.'
@gofumpt -w .
@goimports -w -local github.com/G-Research/fasttrackml $(shell find . -type f -name '*.go' -not -name 'mock_*.go')
.PHONY: go-lint
go-lint: ## run go linters.
@echo '>>> Running go linters.'
@golangci-lint run -v --build-tags $(GO_BUILDTAGS)
.PHONY: go-dist
go-dist: go-build ## archive app binary.
@echo '>>> Archiving go binary.'
@dir=$$(dirname $(ARCHIVE_NAME)); if [ ! -d $$dir ]; then mkdir -p $$dir; fi
@if [ -f $(ARCHIVE_NAME) ]; then rm -f $(ARCHIVE_NAME); fi
@$(ARCHIVE_CMD) $(ARCHIVE_NAME) $(ARCHIVE_FILES)
#
# Python targets.
#
.PHONY: python-env
python-env: ## create python virtual environment.
@echo '>>> Creating python virtual environment.'
@pipenv sync
.PHONY: python-dist
python-dist: go-build python-env ## build python wheels.
@echo '>>> Building Python Wheels.'
@VERSION=$(VERSION) pipenv run python3 -m pip wheel ./python --wheel-dir=wheelhouse --no-deps
.PHONY: python-format
python-format: python-env ## format python code.
@echo '>>> Formatting python code.'
@pipenv run black --line-length 120 .
@pipenv run isort --profile black .
.PHONY: python-lint
python-lint: python-env ## check python code formatting.
@echo '>>> Checking python code formatting.'
@pipenv run black --check --line-length 120 .
@pipenv run isort --check-only --profile black .
#
# Tests targets.
#
.PHONY: test
test: test-go-unit container-test test-python-integration ## run all the tests.
.PHONY: test-go-unit
test-go-unit: ## run go unit tests.
@echo ">>> Running unit tests."
@go test -tags="$(GO_BUILDTAGS)" ./pkg/...
.PHONY: test-go-integration
test-go-integration: ## run go integration tests.
@echo ">>> Running integration tests."
@go test -tags="$(GO_BUILDTAGS)" ./tests/integration/golang/...
.PHONY: test-go-compatibility
test-go-compatibility: ## run go compatibility tests.
@echo ">>> Running compatibility tests."
@go test -tags="$(GO_BUILDTAGS),compatibility" ./tests/integration/golang/compatibility
.PHONY: test-python-integration
test-python-integration: ## run all the python integration tests.
@echo ">>> Running all python integration tests."
@go run tests/integration/python/main.go
.PHONY: test-python-integration-mlflow
test-python-integration-mlflow: ## run the MLFlow python integration tests.
@echo ">>> Running MLFlow python integration tests."
@go run tests/integration/python/main.go -targets mlflow
.PHONY: test-python-integration-aim
test-python-integration-aim: ## run the Aim python integration tests.
@echo ">>> Running Aim python integration tests."
@go run tests/integration/python/main.go -targets aim
.PHONY: test-python-integration-client
test-python-integration-client: ## run the FML Client python integration tests.
@echo ">>> Running FasttrackmlClient python integration tests."
@go run tests/integration/python/main.go -targets fml_client
#
# Container test targets.
#
.PHONY: container-test
container-test: ## run integration tests in container.
@echo ">>> Running integration tests in container."
@COMPOSE_FILE=$(COMPOSE_FILE) COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) \
docker compose run -e FML_SLOW_TESTS_ENABLED integration-tests
.PHONY: container-compatibility-test
container-compatibility-test: ## run compatibility tests in container.
@echo ">>> Running compatibility tests in container."
@COMPOSE_FILE=$(COMPOSE_FILE) COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) \
docker compose run -e MLFLOW_VERSION -e DATABASE_URI mlflow-setup
@COMPOSE_FILE=$(COMPOSE_FILE) COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) \
docker compose run -e MLFLOW_VERSION -e DATABASE_URI compatibility-tests
.PHONY: container-clean
container-clean: ## clean containers.
@echo ">>> Cleaning containers."
@COMPOSE_FILE=$(COMPOSE_FILE) COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) \
docker compose down -v --remove-orphans
#
# Mockery targets.
#
.PHONY: mocks-clean
mocks-clean: ## cleans mocks.
@echo ">>> Cleaning mocks."
@find ./pkg -name 'mock_*.go' -type f -delete
.PHONY: mocks-generate
mocks-generate: mocks-clean ## generate mock based on all project interfaces.
@echo ">>> Generating mocks."
@mockery
#
# Docker targets (Only available on Linux).
#
ifeq ($(shell go env GOOS),linux)
# Load into the Docker daemon by default.
DOCKER_OUTPUT?=type=docker
ifneq ($(origin DOCKER_METADATA), undefined)
# If DOCKER_METADATA is defined, use it to set the tags and labels.
# DOCKER_METADATA should be a JSON object with the following structure:
# {
# "tags": ["image:tag1", "image:tag2"],
# "labels": {
# "label1": "value1",
# "label2": "value2"
# }
# }
DOCKER_TAGS=$(shell echo $$DOCKER_METADATA | jq -r '.tags | map("--tag \(.)") | join(" ")')
DOCKER_LABELS=$(shell echo $$DOCKER_METADATA | jq -r '.labels | to_entries | map("--label \(.key)=\"\(.value)\"") | join(" ")')
else
# Otherwise, use DOCKER_TAGS if defined, otherwise use the default.
# DOCKER_TAGS should be a space-separated list of tags.
# e.g. DOCKER_TAGS="image:tag1 image:tag2"
# We do not set DOCKER_LABELS because of the way make handles spaces
# in variable values. Use DOCKER_METADATA if you need to set labels.
DOCKER_TAGS?=fasttrackml:$(VERSION) fasttrackml:latest
DOCKER_TAGS:=$(addprefix --tag ,$(DOCKER_TAGS))
endif
.PHONY: docker-dist
docker-dist: go-build ## build docker image.
@echo ">>> Building Docker image."
@docker buildx build --provenance false --sbom false --platform linux/$(shell go env GOARCH) --output $(DOCKER_OUTPUT) $(DOCKER_TAGS) $(DOCKER_LABELS) .
endif
#
# Build targets.
#
.PHONY: clean
clean: ## clean build artifacts.
@echo ">>> Cleaning build artifacts."
@rm -rf $(APP) dist wheelhouse
.PHONY: build
build: go-build ## build the app.
.PHONY: dist
dist: go-dist python-dist ## build the software archives.
ifeq ($(shell go env GOOS),linux)
dist: docker-dist
endif
.PHONY: format
format: go-format python-format ## format the code.
.PHONY: run
run: build ## run the FastTrackML server.
@echo ">>> Running the FasttrackML server."
@./$(APP) server
.PHONY: migrations-create
migrations-create: ## generate a new database migration.
@echo ">>> Running FastTrackML migrations create."
@go run main.go migrations create
.PHONY: migrations-rebuild
migrations-rebuild: ## rebuild the migrations script to detect new migrations.
@echo ">>> Running FastTrackML migrations rebuild."
@go run main.go migrations rebuild
.PHONY: ui-aim-sync
ui-aim-sync: ## copy Aim UI files to docker volume.
@echo ">>> Syncing the Aim UI."
@rsync -rvu --exclude node_modules --exclude .git ui/fasttrackml-ui-aim/ $(AIM_BUILD_LOCATION)
.PHONY: ui-aim-start
ui-aim-start: ui-aim-sync ## start the Aim UI for development.
@echo ">>> Starting the Aim UI."
@cd $(AIM_BUILD_LOCATION)/src && npm ci --legacy-peer-deps && npm start
.PHONY: ui-mlflow-sync
ui-mlflow-sync: ## copy MLflow UI files to docker volume.
@echo ">>> Syncing the MLflow UI."
@rsync -rvu --exclude node_modules --exclude .git ui/fasttrackml-ui-mlflow/ $(MLFLOW_BUILD_LOCATION)
.PHONY: ui-mlflow-start
ui-mlflow-start: ui-mlflow-sync ## start the MLflow UI for development.
@echo ">>> Starting the MLflow UI."
@cd $(MLFLOW_BUILD_LOCATION)/src && yarn install --immutable && yarn start