forked from openfoodfacts/robotoff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
232 lines (185 loc) · 6.73 KB
/
Makefile
File metadata and controls
232 lines (185 loc) · 6.73 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
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
#!/usr/bin/make
# nice way to have our .env in environment for use in makefile
# see https://lithic.tech/blog/2020-05/makefile-dot-env
# Note: this will mask environment variable as opposed to docker-compose priority
# yet most developper should'nt bump into this
ifneq (,$(wildcard ./.env))
-include .env
-include .envrc
export
endif
NAME = "robotoff"
ENV_FILE ?= .env
MOUNT_POINT ?= /mnt
HOSTS=127.0.0.1 robotoff.openfoodfacts.localhost
DOCKER_COMPOSE=docker-compose --env-file=${ENV_FILE}
DOCKER_COMPOSE_TEST=COMPOSE_PROJECT_NAME=robotoff_test PO_LOCAL_NET=po_test docker-compose --env-file=${ENV_FILE}
ML_OBJECT_DETECTION_MODELS := tf-universal-logo-detector tf-nutrition-table tf-nutriscore
.DEFAULT_GOAL := dev
# avoid target corresponding to file names, to depends on them
.PHONY: *
#------#
# Info #
#------#
info:
@echo "${NAME} version: ${VERSION}"
hello:
@echo "🥫 Welcome to the Robotoff dev environment setup!"
@echo "🥫 Note that the first installation might take a while to run, depending on your machine specs."
@echo "🥫 Typical installation time on 8GB RAM, 4-core CPU, and decent network bandwith is about 2 min."
@echo "🥫 Thanks for contributing to Robotoff!"
@echo ""
goodbye:
@echo "🥫 Cleaning up dev environment (remove containers, remove local folder binds, prune Docker system) …"
#-------#
# Local #
#-------#
dev: hello build up create_external_networks
@echo "🥫 You should be able to access your local install of Robotoff at http://localhost:5500"
edit_etc_hosts:
@grep -qxF -- "${HOSTS}" /etc/hosts || echo "${HOSTS}" >> /etc/hosts
#----------------#
# Docker Compose #
#----------------#
up:
# creates a docker network and runs docker-compose
@echo "🥫 Building and starting containers …"
docker network create po_default || true
ifdef service
${DOCKER_COMPOSE} up -d ${service} 2>&1
else
${DOCKER_COMPOSE} up -d 2>&1
endif
build:
${DOCKER_COMPOSE} build api 2>&1
down:
@echo "🥫 Bringing down containers …"
${DOCKER_COMPOSE} down
hdown:
@echo "🥫 Bringing down containers and associated volumes …"
${DOCKER_COMPOSE} down -v
restart:
@echo "🥫 Restarting containers …"
${DOCKER_COMPOSE} restart
status:
@echo "🥫 Getting container status …"
${DOCKER_COMPOSE} ps
livecheck:
@echo "🥫 Running livecheck …"
docker/docker-livecheck.sh
log:
@echo "🥫 Reading logs (docker-compose) …"
${DOCKER_COMPOSE} logs -f
#------------#
# Management #
#------------#
dl-models: dl-model-archives dl-model-categorizer
dl-model-archives:
@echo "🥫 Downloading model archive files …"
cd models; \
for asset_name in ${ML_OBJECT_DETECTION_MODELS}; \
do \
dir=`echo $${asset_name} | sed 's/tf-//g'`; \
mkdir -p $${dir} $${dir}/1; \
wget -cO - https://github.com/openfoodfacts/robotoff-models/releases/download/$${asset_name}-1.0/model.onnx > $${dir}/1/model.onnx; \
done; \
mkdir -p clip clip/1; \
wget -cO - https://github.com/openfoodfacts/robotoff-models/releases/download/clip-vit-base-patch32/model.onnx > clip/1/model.onnx;
dl-model-categorizer:
@echo "🥫 Downloading categorizer model …"
cd tf_models; \
dir=category-classifier; \
mkdir -p $${dir} $${dir}/1; \
wget -cO - https://github.com/openfoodfacts/robotoff-models/releases/download/keras-category-classifier-xx-2.0/serving_model.tar.gz > $${dir}/1/saved_model.tar.gz; \
cd $${dir}/1; \
tar -xzvf saved_model.tar.gz --strip-component=1; \
rm saved_model.tar.gz
lauch-burst-worker:
ifdef queues
${DOCKER_COMPOSE} run --rm -d --no-deps worker_low python -m robotoff run-worker ${queues} --burst
else
${DOCKER_COMPOSE} run --rm -d --no-deps worker_low python -m robotoff run-worker robotoff-high robotoff-low --burst
endif
#------------#
# Quality #
#------------#
toml-check:
${DOCKER_COMPOSE} run --rm --no-deps api poetry run toml-sort --check poetry.toml pyproject.toml
toml-lint:
${DOCKER_COMPOSE} run --rm --no-deps api poetry run toml-sort --in-place poetry.toml pyproject.toml
flake8:
${DOCKER_COMPOSE} run --rm --no-deps api flake8
black-check:
${DOCKER_COMPOSE} run --rm --no-deps api black --check .
black:
${DOCKER_COMPOSE} run --rm --no-deps api black .
mypy:
${DOCKER_COMPOSE} run --rm --no-deps api mypy .
isort-check:
${DOCKER_COMPOSE} run --rm --no-deps api isort --check .
isort:
${DOCKER_COMPOSE} run --rm --no-deps api isort .
docs:
@echo "🥫 Generationg doc…"
${DOCKER_COMPOSE} run --rm --no-deps api ./build_mkdocs.sh
checks: toml-check flake8 black-check mypy isort-check docs
lint: toml-lint isort black
tests: create_external_networks i18n-compile unit-tests integration-tests
quality: lint checks tests
health:
@echo "🥫 Running health tests …"
@curl --fail --fail-early 127.0.0.1:5500/api/v1/health
i18n-compile:
@echo "🥫 Compiling translations …"
# Note it's important to have --no-deps, to avoid launching a concurrent postgres instance
${DOCKER_COMPOSE} run --rm --entrypoint bash --no-deps worker_high -c "cd i18n && . compile.sh"
unit-tests:
@echo "🥫 Running tests …"
# run tests in worker to have more memory
# also, change project name to run in isolation
${DOCKER_COMPOSE_TEST} run --rm worker_high poetry run pytest --cov-report xml --cov=robotoff tests/unit
integration-tests:
@echo "🥫 Running integration tests …"
# run tests in worker to have more memory
# also, change project name to run in isolation
${DOCKER_COMPOSE_TEST} run --rm worker_high poetry run pytest -vv --cov-report xml --cov=robotoff --cov-append tests/integration
( ${DOCKER_COMPOSE_TEST} down -v || true )
# interactive testings
# usage: make pytest args='test/unit/my-test.py --pdb'
pytest: guard-args
@echo "🥫 Running test: ${args} …"
${DOCKER_COMPOSE_TEST} run --rm worker_high poetry run pytest ${args}
#------------#
# Production #
#------------#
create_external_volumes:
@echo "🥫 Creating external volumes (production only) …"
docker volume create api-dataset
docker volume create postgres-data
docker volume create es-data
create_external_networks:
@echo "🥫 Creating external networks if needed … (dev only)"
( docker network create ${PO_LOCAL_NET} || true )
# for tests
( docker network create po_test || true )
#---------#
# Cleanup #
#---------#
prune:
@echo "🥫 Pruning unused Docker artifacts (save space) …"
docker system prune -af
prune_cache:
@echo "🥫 Pruning Docker builder cache …"
docker builder prune -f
clean: goodbye hdown prune prune_cache
#-----------#
# Utilities #
#-----------#
guard-%: # guard clause for targets that require an environment variable (usually used as an argument)
@ if [ "${${*}}" = "" ]; then \
echo "Environment variable '$*' is mandatory"; \
echo use "make ${MAKECMDGOALS} $*=you-args"; \
exit 1; \
fi;
robotoff-cli: guard-args
${DOCKER_COMPOSE} run --rm --no-deps api python -m robotoff ${args}