-
Notifications
You must be signed in to change notification settings - Fork 964
/
Makefile
184 lines (140 loc) · 6.16 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
DB := example
IPYTHON := no
# set environment variable WAREHOUSE_IPYTHON_SHELL=1 if IPython
# needed in development environment
ifeq ($(WAREHOUSE_IPYTHON_SHELL), 1)
IPYTHON = yes
endif
# Optimization: if the user explicitly passes tests via `T`,
# disable xdist (since the overhead of spawning workers is typically
# higher than running a small handful of specific tests).
# Only do this when the user doesn't set any explicit `TESTARGS` to avoid
# confusion.
COVERAGE := yes
ifneq ($(T),)
COVERAGE = no
ifeq ($(TESTARGS),)
TESTARGS = -n 0
endif
endif
# PEP 669 introduced sys.monitoring, a lighter-weight way to monitor
# the execution. While this introduces significant speed-up during test
# execution, coverage does not yet support dynamic contexts when enabled.
# This variable can be set to other tracers (ctrace, pytrace) to fall
# back use them.
# https://nedbatchelder.com/blog/202312/coveragepy_with_sysmonitoring.html
COVERAGE_CORE ?= sysmon
default:
@echo "Call a specific subcommand:"
@echo
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null\
| awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}'\
| sort\
| egrep -v -e '^[^[:alnum:]]' -e '^$@$$'
@echo
@exit 1
.state/docker-build-base: Dockerfile package.json package-lock.json requirements/main.txt requirements/deploy.txt requirements/lint.txt requirements/tests.txt requirements/dev.txt
# Build our base container for this project.
docker compose build --build-arg IPYTHON=$(IPYTHON) --force-rm base
# Mark the state so we don't rebuild this needlessly.
mkdir -p .state
touch .state/docker-build-base
.state/docker-build-static: Dockerfile package.json package-lock.json babel.config.js
# Build our static container for this project.
docker compose build --force-rm static
# Mark the state so we don't rebuild this needlessly.
mkdir -p .state
touch .state/docker-build-static
.state/docker-build-docs: Dockerfile requirements/docs-dev.txt requirements/docs-blog.txt requirements/docs-user.txt
# Build the worker container for this project
docker compose build --build-arg USER_ID=$(shell id -u) --build-arg GROUP_ID=$(shell id -g) --force-rm dev-docs
# Mark the state so we don't rebuild this needlessly.
mkdir -p .state
touch .state/docker-build-docs
.state/docker-build: .state/docker-build-base .state/docker-build-static .state/docker-build-docs
# Build the worker container for this project
docker compose build --force-rm worker
# Mark the state so we don't rebuild this needlessly.
mkdir -p .state
touch .state/docker-build
build:
@$(MAKE) .state/docker-build
docker system prune -f --filter "label=com.docker.compose.project=warehouse"
serve: .state/docker-build
$(MAKE) .state/db-populated
$(MAKE) .state/search-indexed
docker compose up --remove-orphans
debug: .state/docker-build-base
docker compose run --rm --service-ports web
tests: .state/docker-build-base
docker compose run --rm --env COVERAGE=$(COVERAGE) --env COVERAGE_CORE=$(COVERAGE_CORE) tests bin/tests --postgresql-host db $(T) $(TESTARGS)
static_tests: .state/docker-build-static
docker compose run --rm static bin/static_tests $(T) $(TESTARGS)
static_pipeline: .state/docker-build-static
docker compose run --rm static bin/static_pipeline $(T) $(TESTARGS)
reformat: .state/docker-build-base
docker compose run --rm base bin/reformat
lint: .state/docker-build-base .state/docker-build-static
docker compose run --rm base bin/lint
docker compose run --rm static bin/static_lint
dev-docs: .state/docker-build-docs
docker compose run --rm dev-docs bin/dev-docs
user-docs: .state/docker-build-docs
docker compose run --rm user-docs bin/user-docs
blog: .state/docker-build-docs
docker compose run --rm blog mkdocs build -f docs/mkdocs-blog.yml
licenses: .state/docker-build-base
docker compose run --rm base bin/licenses
deps: .state/docker-build-base
docker compose run --rm base bin/deps
translations: .state/docker-build-base
docker compose run --rm base bin/translations
requirements/%.txt: requirements/%.in
docker compose run --rm base bin/pip-compile --generate-hashes --output-file=$@ $<
resetdb: .state/docker-build-base
docker compose pause web worker
docker compose up -d db
docker compose exec --user postgres db /docker-entrypoint-initdb.d/init-dbs.sh
rm -f .state/db-populated .state/db-migrated
$(MAKE) initdb
docker compose unpause web worker
.state/search-indexed: .state/db-populated
$(MAKE) reindex
mkdir -p .state && touch .state/search-indexed
.state/db-populated: .state/db-migrated
docker compose run --rm web python -m warehouse sponsors populate-db
docker compose run --rm web python -m warehouse classifiers sync
docker compose exec --user postgres db psql -U postgres warehouse -f /post-migrations.sql
mkdir -p .state && touch .state/db-populated
.state/db-migrated: .state/docker-build-base
docker compose up -d db
docker compose exec db /usr/local/bin/wait-for-db
$(MAKE) runmigrations
mkdir -p .state && touch .state/db-migrated
initdb: .state/docker-build-base .state/db-populated
$(MAKE) reindex
inittuf: .state/db-migrated
docker compose up -d rstuf-api
docker compose up -d rstuf-worker
docker compose run --rm web python -m warehouse tuf bootstrap dev/rstuf/bootstrap.json --api-server http://rstuf-api
runmigrations: .state/docker-build-base
docker compose run --rm web python -m warehouse db upgrade head
checkdb: .state/docker-build-base
docker compose run --rm web bin/db-check
reindex: .state/docker-build-base
docker compose run --rm web python -m warehouse search reindex
shell: .state/docker-build-base
docker compose run --rm web python -m warehouse shell
totp: .state/docker-build-base
@docker compose run --rm base bin/devtotp
dbshell: .state/docker-build-base
docker compose run --rm web psql -h db -d warehouse -U postgres
clean:
rm -rf dev/*.sql
purge: stop clean
rm -rf .state dev/.coverage* dev/.mypy_cache dev/.pip-cache dev/.pip-tools-cache dev/.pytest_cache .state/db-populated .state/db-migrated
docker compose down -v --remove-orphans
docker compose rm --force
stop:
docker compose stop
.PHONY: default build serve resetdb initdb shell dbshell tests dev-docs user-docs deps clean purge debug stop compile-pot runmigrations checkdb