-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
531 lines (457 loc) · 20.5 KB
/
Copy pathMakefile
File metadata and controls
531 lines (457 loc) · 20.5 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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
SHELL := /bin/bash
DOCKER ?= docker
DOCKER_COMPOSE ?= $(DOCKER) compose
export PATH := ./venv/bin:$(PATH)
SHA := $(shell git rev-parse --short HEAD )
REPO := quay.io/quay/quay
TAG := $(REPO):$(SHA)
MODIFIED_FILES_COUNT = $(shell git diff --name-only origin/master | grep -E .+\.py$ | wc -l)
GIT_MERGE_BASED = $(shell git merge-base origin/master HEAD)
MODIFIED_FILES = $(shell git diff --name-only $(GIT_MERGE_BASED) | grep -E .+\.py$ | paste -sd ' ')
show-modified:
echo $(MODIFIED_FILES)
.PHONY: all unit-test registry-test registry-test-old buildman-test test build run clean
all: clean test build
unit-test:
TEST=true PYTHONPATH="." py.test \
--cov="." --cov-report=html --cov-report=term-missing \
-m 'not e2e' --timeout=3600 --verbose -x --ignore=buildman/ \
./
e2e-test:
TEST=true PYTHONPATH="." py.test \
--cov="." --cov-report=html --cov-report=term-missing \
-m 'e2e' --timeout=3600 --verbose -x --ignore=buildman/ \
./
integration-test:
TEST=true PYTHONPATH="." py.test \
--verbose --ignore=buildman/ \
test/integration/*
registry-test:
TEST=true PYTHONPATH="." py.test \
--cov="." --cov-report=html --cov-report=term-missing \
-n auto -m 'not e2e' --timeout=3600 --verbose -x \
test/registry/registry_tests.py
buildman-test:
TEST=true PYTHONPATH="." py.test \
--cov="." --cov-report=html --cov-report=term-missing \
-m 'not e2e' --timeout=3600 --verbose -x \
./buildman/
certs-test:
./test/test_certs_install.sh
full-db-test: ensure-test-db
TEST=true PYTHONPATH=. QUAY_OVERRIDE_CONFIG='{"DATABASE_SECRET_KEY": "anothercrazykey!"}' \
alembic upgrade head
TEST=true PYTHONPATH=. \
SKIP_DB_SCHEMA=true py.test -m 'not e2e' --timeout=7200 \
--verbose -x --ignore=endpoints/appr/test/ \
./
clients-test:
cd test/clients; python clients_test.py
types-test:
mypy .
test: unit-test registry-test registry-test-old certs-test
ensure-test-db:
@if [ -z $(TEST_DATABASE_URI) ]; then \
echo "TEST_DATABASE_URI is undefined"; \
exit 1; \
fi
install-pre-commit-hook:
pip install pre-commit==4.5.0
pre-commit install
PG_PASSWORD := quay
PG_USER := quay
PG_PORT := 5433
PG_HOST := postgresql://$(PG_USER):$(PG_PASSWORD)@localhost:$(PG_PORT)/quay
CONTAINER := postgres-testrunner
TESTS ?= ./
test_postgres : TEST_ENV := SKIP_DB_SCHEMA=true TEST=true \
TEST_DATABASE_URI=$(PG_HOST) PYTHONPATH=.
test_postgres:
$(DOCKER) rm -f $(CONTAINER) || true
$(DOCKER) run --name $(CONTAINER) \
-e POSTGRES_PASSWORD=$(PG_PASSWORD) -e POSTGRES_USER=$(PG_USER) \
-p $(PG_PORT):5432 -d postgres:18
$(DOCKER) exec -it $(CONTAINER) bash -c 'while ! pg_isready; do echo "waiting for postgres"; sleep 2; done'
$(DOCKER) exec -it $(CONTAINER) bash -c "psql -U $(PG_USER) -d quay -c 'CREATE EXTENSION pg_trgm;'"
$(TEST_ENV) alembic upgrade head
$(TEST_ENV) py.test --timeout=7200 --verbose --ignore=endpoints/appr/test/ -x $(TESTS)
$(DOCKER) rm -f $(CONTAINER) || true
WEBPACK := node_modules/.bin/webpack
$(WEBPACK): package.json
npm install webpack
npm install
BUNDLE := static/js/build/bundle.js
$(BUNDLE): $(WEBPACK) tsconfig.json webpack.config.js typings.json
$(WEBPACK)
GRUNT := grunt/node_modules/.bin/grunt
$(GRUNT): grunt/package.json
cd grunt && npm install
JS := quay-frontend.js quay-frontend.min.js template-cache.js
CSS := quay-frontend.css
DIST := $(addprefix static/dist/, $(JS) $(CSS) cachebusters.json)
$(DIST): $(GRUNT)
cd grunt && ../$(GRUNT)
build: $(WEBPACK) $(GRUNT)
docker-build: build
ifneq (0,$(shell git status --porcelain | awk 'BEGIN {print $N}'))
echo 'dirty build not supported - run `FORCE=true make clean` to remove'
exit 1
endif
# get named head (ex: branch, tag, etc..)
NAME = $(shell git rev-parse --abbrev-ref HEAD)
# checkout commit so .git/HEAD points to full sha (used in Dockerfile)
git checkout $(SHA)
$(DOCKER) build -t $(TAG) .
git checkout $(NAME)
echo $(TAG)
app-sre-docker-build:
$(BUILD_CMD) -t ${IMG} -f Dockerfile .
clean:
find . -name "*.pyc" -exec rm -rf {} \;
rm -rf node_modules 2> /dev/null
rm -rf grunt/node_modules 2> /dev/null
rm -rf dest 2> /dev/null
rm -rf dist 2> /dev/null
rm -rf .cache 2> /dev/null
rm -rf static/js/build
rm -rf static/build
rm -rf static/dist
rm -rf build
rm -rf conf/stack
rm -rf screenshots
generate-proto-py:
python -m grpc_tools.protoc -Ibuildman/buildman_pb --python_out=buildman/buildman_pb --grpc_python_out=buildman/buildman_pb buildman.proto
black:
black --line-length=100 --target-version=py312 --exclude "/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist)/" .
#################################
# Local Development Environment #
#################################
.PHONY: build-image-local-dev-frontend
build-images:: build-image-local-dev-frontend
build-image-local-dev-frontend:
# $(DOCKER)-compose run does not build images, so we need to build them if needed
test -n "$$($(DOCKER) images localhost/quay-build:latest -q)" || $(DOCKER_COMPOSE) build local-dev-frontend
.PHONY: build-image-quay
build-images:: build-image-quay
build-image-quay: .build-image-quay-stamp
.build-image-quay-stamp: Dockerfile requirements.txt
$(DOCKER_COMPOSE) build quay
touch $@
node_modules: node_modules/.npm-install-stamp
node_modules/.npm-install-stamp: package.json package-lock.json | build-image-local-dev-frontend
DOCKER_USER="$$(id -u):$$(id -g)" $(DOCKER_COMPOSE) run --rm --name quay-local-dev-frontend-install --entrypoint="npm install --ignore-engines" local-dev-frontend
# if npm install fails for some reason, it may have already created
# node_modules, so we cannot rely on the directory timestamps and should mark
# successfull runs of npm install with a stamp file.
touch $@
.PHONY: local-dev-clean
local-dev-clean:
rm -f ./conf/jwtproxy_conf.yaml ./conf/mitm.cert ./conf/mitm.key ./conf/quay.kid ./conf/quay.pem ./conf/supervisord.conf
rm -rf ./conf/__pycache__ ./static/build ./web/dist ./static/patternfly
.PHONY: local-dev-build-frontend
local-dev-build:: local-dev-build-frontend
local-dev-build-frontend: node_modules
DOCKER_USER="$$(id -u):$$(id -g)" $(DOCKER_COMPOSE) run --rm --name quay-local-dev-frontend-build --entrypoint="" local-dev-frontend npm run build
.PHONY: local-dev-build-images
local-dev-build:: local-dev-build-images
local-dev-build-images:
$(DOCKER_COMPOSE) build
.PHONY: local-dev-up
local-dev-up: local-dev-clean node_modules | build-image-quay
DOCKER_USER="$$(id -u):$$(id -g)" $(DOCKER_COMPOSE) up -d --force-recreate local-dev-frontend
$(DOCKER_COMPOSE) up -d redis quay-db
$(DOCKER) exec -it quay-db bash -c 'while ! pg_isready; do echo "waiting for postgres"; sleep 2; done'
DOCKER_USER="$$(id -u):0" $(DOCKER_COMPOSE) stop quay # we need to restart quay after local-dev-clean
DOCKER_USER="$$(id -u):0" $(DOCKER_COMPOSE) up -d quay
# Waiting until the frontend is built...
# Use '$(DOCKER_COMPOSE) logs -f local-dev-frontend' to see the progress
while ! test -e ./static/build/main-quay-frontend.bundle.js; do sleep 2; done
@echo "You can now access the frontend at http://localhost:8080"
QUAY_BUILDER_IMAGE ?= quay.io/projectquay/quay-builder:3.17-unstable
.PHONY: local-dev-extract-builder
local-dev-extract-builder:
@if [ ! -f ./local-dev/quay-builder ]; then \
echo "Extracting quay-builder binary from $(QUAY_BUILDER_IMAGE)..."; \
$(DOCKER) rm -f quay-builder-extract 2>/dev/null || true; \
$(DOCKER) create --name quay-builder-extract $(QUAY_BUILDER_IMAGE); \
$(DOCKER) cp quay-builder-extract:/usr/local/bin/quay-builder ./local-dev/quay-builder; \
$(DOCKER) rm -f quay-builder-extract; \
chmod +x ./local-dev/quay-builder; \
else \
echo "quay-builder binary already exists, skipping extraction"; \
fi
.PHONY: enable-builds
enable-builds: local-dev-extract-builder
@if ! command -v yq &> /dev/null; then \
echo "Error: yq is not installed"; \
echo "Install from: https://github.com/mikefarah/yq/#install"; \
exit 1; \
fi
@cp local-dev/stack/config.yaml local-dev/stack/config.yaml.backup
@yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' \
local-dev/stack/config.yaml local-dev/builds/builds-config.yaml > local-dev/stack/config.yaml.tmp
@mv local-dev/stack/config.yaml.tmp local-dev/stack/config.yaml
@echo "Build support enabled in local-dev/stack/config.yaml"
.PHONY: update-testdata
update-testdata: local-dev-clean node_modules | build-image-quay
$(DOCKER_COMPOSE) stop quay-db quay || true
$(DOCKER) rm -f quay-quay quay-db || true
$(DOCKER) volume rm -f quay_quay-db-data
$(DOCKER_COMPOSE) up -d redis quay-db
$(DOCKER) exec -it quay-db bash -c 'while ! pg_isready; do echo "waiting for postgres"; sleep 2; done'
cd ./web/ && npm run quay:seed-db
DOCKER_USER="$$(id -u):0" $(DOCKER_COMPOSE) up -d quay
cd ./web/ && npm run quay:seed-storage
while ! curl -fso /dev/null http://localhost:8080; do echo "waiting for quay"; sleep 2; done
$(DOCKER) exec -it quay-db psql quay -U quay -c " \
DELETE FROM servicekey; \
DELETE FROM servicekeyapproval; \
SELECT pg_catalog.setval('public.notification_id_seq', 1, false); \
SELECT pg_catalog.setval('public.servicekey_id_seq', 1, false); \
SELECT pg_catalog.setval('public.servicekeyapproval_id_seq', 1, false); \
"
cd ./web/ && npm run quay:dump
$(DOCKER_COMPOSE) down
.PHONY: local-dev-up-react
local-dev-up-react: local-dev-clean | build-image-quay
BUILD_ANGULAR=false DOCKER_USER="$$(id -u):$$(id -g)" $(DOCKER_COMPOSE) up -d --force-recreate local-dev-react
$(DOCKER_COMPOSE) up -d redis quay-db
$(DOCKER) exec -it quay-db bash -c 'while ! pg_isready; do echo "waiting for postgres"; sleep 2; done'
# Wait for React files to be copied
while ! test -e ./static/patternfly/index.html; do echo "Waiting for React files..."; sleep 2; done
BUILD_ANGULAR=false DOCKER_USER="$$(id -u):0" $(DOCKER_COMPOSE) stop quay
BUILD_ANGULAR=false DOCKER_USER="$$(id -u):0" $(DOCKER_COMPOSE) up -d quay
# Wait for backend to be ready
while ! $(DOCKER) exec quay-quay test -e /tmp/gunicorn_web.sock 2>/dev/null; do echo "Waiting for backend..."; sleep 3; done
@echo "You can now access the React frontend at http://localhost:8080"
local-docker-rebuild:
$(DOCKER_COMPOSE) up -d --build redis
$(DOCKER_COMPOSE) up -d --build quay-db
$(DOCKER) exec -it quay-db bash -c 'while ! pg_isready; do echo "waiting for postgres"; sleep 2; done'
DOCKER_USER="$$(id -u):0" $(DOCKER_COMPOSE) up -d --build quay
$(DOCKER_COMPOSE) restart quay
ifeq ($(CLAIR),true)
$(DOCKER_COMPOSE) up -d --build clair-db
$(DOCKER) exec -it clair-db bash -c 'while ! pg_isready; do echo "waiting for postgres"; sleep 2; done'
$(DOCKER_COMPOSE) up -d --build clair
$(DOCKER_COMPOSE) restart clair
else
@echo "Skipping Clair"
endif
.PHONY: local-dev-up-with-clair
local-dev-up-with-clair: local-dev-up
$(DOCKER_COMPOSE) up -d clair-db
$(DOCKER) exec -it clair-db bash -c 'while ! pg_isready; do echo "waiting for postgres"; sleep 2; done'
DOCKER_USER="$$(id -u):0" $(DOCKER_COMPOSE) up -d clair
.PHONY: local-dev-up-with-repomirror
local-dev-up-with-repomirror: local-dev-up
DOCKER_USER="$$(id -u):0" $(DOCKER_COMPOSE) up -d repomirror
.PHONY: local-dev-up-static
local-dev-up-static: local-dev-clean
$(DOCKER_COMPOSE) -f docker-compose.static up -d redis quay-db
$(DOCKER) exec -it quay-db bash -c 'while ! pg_isready; do echo "waiting for postgres"; sleep 2; done'
DOCKER_USER="$$(id -u):0" $(DOCKER_COMPOSE) -f docker-compose.static up -d --build quay
@echo "You can now access the frontend at http://localhost:8080"
$(DOCKER_COMPOSE) -f docker-compose.static up -d clair-db
$(DOCKER) exec -it clair-db bash -c 'while ! pg_isready; do echo "waiting for postgres"; sleep 2; done'
$(DOCKER_COMPOSE) -f docker-compose.static up -d clair
.PHONY: local-dev-down
local-dev-down:
$(DOCKER_COMPOSE) down
$(MAKE) local-dev-clean
.PHONY: local-dev-reset-db
local-dev-reset-db:
$(DOCKER_COMPOSE) stop quay-db quay || true
$(DOCKER) rm -f quay-quay quay-db || true
$(DOCKER) volume rm -f quay_quay-db-data
$(DOCKER_COMPOSE) up -d quay-db
$(DOCKER) exec -it quay-db bash -c 'while ! pg_isready; do echo "waiting for postgres"; sleep 2; done'
DOCKER_USER="$$(id -u):0" $(DOCKER_COMPOSE) up -d quay
@echo "Database has been reset. Quay will run migrations on startup."
.PHONY: enable-ldap
enable-ldap:
@echo "Merging LDAP config into local-dev/stack/config.yaml..."
@if ! command -v yq &> /dev/null; then \
echo "Error: yq is not installed"; \
echo "Install from: https://github.com/mikefarah/yq/#install"; \
exit 1; \
fi
@if ! $(DOCKER_COMPOSE) ps ldap 2>/dev/null | grep -q "Up"; then \
echo "⚠ Warning: LDAP container not running. Start with: docker-compose up -d ldap"; \
fi
@cp local-dev/stack/config.yaml local-dev/stack/config.yaml.backup
@yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' \
local-dev/stack/config.yaml local-dev/ldap/ldap-config.yaml > local-dev/stack/config.yaml.tmp
@mv local-dev/stack/config.yaml.tmp local-dev/stack/config.yaml
@echo "✓ LDAP configuration merged"
@echo " Backup: local-dev/stack/config.yaml.backup"
@echo " Apply changes: docker-compose restart quay"
.PHONY: enable-oidc
enable-oidc:
@echo "Merging Keycloak OIDC config into local-dev/stack/config.yaml..."
@if ! command -v yq &> /dev/null; then \
echo "Error: yq is not installed"; \
echo "Install from: https://github.com/mikefarah/yq/#install"; \
exit 1; \
fi
@cp local-dev/stack/config.yaml local-dev/stack/config.yaml.backup
@yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' \
local-dev/stack/config.yaml local-dev/keycloak/keycloak-config.yaml > local-dev/stack/config.yaml.tmp
@mv local-dev/stack/config.yaml.tmp local-dev/stack/config.yaml
@echo "Keycloak OIDC configuration merged"
@echo " Backup: local-dev/stack/config.yaml.backup"
@echo " Apply changes: $(DOCKER_COMPOSE) restart quay"
.PHONY: local-dev-up-with-keycloak
local-dev-up-with-keycloak: local-dev-up
$(DOCKER_COMPOSE) up -d keycloak
@echo "Waiting for Keycloak to be ready..."
@curl -sf --retry 30 --retry-delay 3 --retry-all-errors \
http://localhost:8081/realms/quay > /dev/null \
|| { echo "Keycloak failed to start. Recent logs:"; $(DOCKER_COMPOSE) logs --tail 50 keycloak; exit 1; }
@echo "Keycloak is ready. Merging OIDC config..."
@$(MAKE) enable-oidc
$(DOCKER_COMPOSE) restart quay
.PHONY: enable-jaeger
enable-jaeger:
@echo "Merging Jaeger tracing config into local-dev/stack/config.yaml..."
@if ! command -v yq &> /dev/null; then \
echo "Error: yq is not installed"; \
echo "Install from: https://github.com/mikefarah/yq/#install"; \
exit 1; \
fi
@if ! $(DOCKER_COMPOSE) ps jaeger 2>/dev/null | grep -q "Up"; then \
echo "⚠ Warning: Jaeger container not running. Start with: docker compose up -d jaeger"; \
fi
@cp local-dev/stack/config.yaml local-dev/stack/config.yaml.backup
@yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' \
local-dev/stack/config.yaml local-dev/jaeger/jaeger-config.yaml > local-dev/stack/config.yaml.tmp
@mv local-dev/stack/config.yaml.tmp local-dev/stack/config.yaml
@echo "✓ Jaeger tracing configuration merged"
@echo " Backup: local-dev/stack/config.yaml.backup"
@echo " Jaeger UI: http://localhost:16686"
@echo " Apply changes: $(DOCKER_COMPOSE) restart quay"
.PHONY: local-dev-up-with-jaeger
local-dev-up-with-jaeger: local-dev-up
$(DOCKER_COMPOSE) up -d jaeger
@echo "Waiting for Jaeger to be ready..."
@curl -sf --retry 30 --retry-delay 3 --retry-all-errors \
http://localhost:16686/api/services > /dev/null \
|| { echo "Jaeger failed to start. Recent logs:"; $(DOCKER_COMPOSE) logs --tail 50 jaeger; exit 1; }
@echo "Jaeger is ready. Merging tracing config..."
@$(MAKE) enable-jaeger
$(DOCKER_COMPOSE) restart quay
.PHONY: enable-splunk
enable-splunk:
@echo "Setting up Splunk for local development..."
@if ! command -v yq &> /dev/null; then \
echo "Error: yq is not installed"; \
echo "Install from: https://github.com/mikefarah/yq/#install"; \
exit 1; \
fi
@if ! $(DOCKER_COMPOSE) ps splunk 2>/dev/null | grep -q "Up"; then \
echo "Starting Splunk container..."; \
$(DOCKER_COMPOSE) up -d splunk; \
fi
@echo "Waiting for Splunk to be healthy (this may take 60-90 seconds)..."
@timeout=180; \
while [ $$timeout -gt 0 ]; do \
if $(DOCKER) inspect --format='{{.State.Health.Status}}' quay-splunk 2>/dev/null | grep -q "healthy"; then \
break; \
fi; \
sleep 5; \
timeout=$$((timeout - 5)); \
done; \
if [ $$timeout -le 0 ]; then \
echo "Error: Splunk did not become healthy in time"; \
exit 1; \
fi
@echo "Initializing Splunk (creating index and token)..."
@$(DOCKER) exec quay-splunk bash /tmp/init-splunk.sh
@echo "Merging Splunk config into local-dev/stack/config.yaml..."
@BEARER_TOKEN=$$($(DOCKER) exec quay-splunk cat /tmp/quay_splunk_bearer_token 2>/dev/null || echo ""); \
if [ -z "$$BEARER_TOKEN" ]; then \
echo "⚠ Warning: Could not retrieve bearer token."; \
echo " You may need to set bearer_token manually in config.yaml"; \
BEARER_TOKEN="REPLACE_WITH_BEARER_TOKEN"; \
fi; \
cp local-dev/stack/config.yaml local-dev/stack/config.yaml.backup; \
ESCAPED_TOKEN=$$(echo "$$BEARER_TOKEN" | sed 's/[\/&]/\\&/g'); \
sed "s/BEARER_TOKEN_PLACEHOLDER/$$ESCAPED_TOKEN/" \
local-dev/splunk/splunk-config.yaml > /tmp/splunk-config-resolved.yaml; \
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' \
local-dev/stack/config.yaml /tmp/splunk-config-resolved.yaml > local-dev/stack/config.yaml.tmp; \
mv local-dev/stack/config.yaml.tmp local-dev/stack/config.yaml; \
rm -f /tmp/splunk-config-resolved.yaml
@echo "✓ Splunk configuration merged"
@echo " Backup: local-dev/stack/config.yaml.backup"
@echo " Splunk UI: http://localhost:8000 (admin/changeme1)"
@echo " Apply changes: $(DOCKER_COMPOSE) restart quay"
##############
# Go targets #
##############
GO_BINARY_NAME = quay
GO_BUILD_DIR = bin
GO_CMD_DIR = cmd/quay
GO_VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null)
GO_LDFLAGS = $(if $(GO_VERSION),-ldflags "-X github.com/quay/quay/internal/cmd.version=$(GO_VERSION)")
SCHEMA_DIR := internal/dal/schema
SCHEMA_TMP := /tmp/quay-schema-tmp
.PHONY: go-schema go-schema-check
go-schema:
@echo "=== Running Alembic migrations against SQLite ==="
@rm -rf $(SCHEMA_TMP)
@mkdir -p $(SCHEMA_TMP)/stack $(SCHEMA_DIR)/sqlite
@echo 'DB_URI: sqlite:///$(SCHEMA_TMP)/quay.db' > $(SCHEMA_TMP)/stack/config.yaml
QUAYCONF=$(SCHEMA_TMP)/ PYTHONPATH="." alembic upgrade head
@echo "=== Extracting schema DDL ==="
sqlite3 $(SCHEMA_TMP)/quay.db .schema > $(SCHEMA_DIR)/sqlite/quay_schema.sql
@sed 's/[[:space:]]*$$//' $(SCHEMA_DIR)/sqlite/quay_schema.sql > $(SCHEMA_DIR)/sqlite/quay_schema.sql.tmp && mv $(SCHEMA_DIR)/sqlite/quay_schema.sql.tmp $(SCHEMA_DIR)/sqlite/quay_schema.sql
@echo "=== Extracting seed data ==="
@sqlite3 $(SCHEMA_TMP)/quay.db \
"SELECT name FROM sqlite_master WHERE type='table' AND name != 'sqlite_sequence' ORDER BY name;" \
| while read table; do \
count=$$(sqlite3 $(SCHEMA_TMP)/quay.db "SELECT COUNT(*) FROM \"$$table\";"); \
if [ "$$count" -gt 0 ]; then \
sqlite3 $(SCHEMA_TMP)/quay.db ".mode insert $$table" "SELECT * FROM \"$$table\" ORDER BY rowid;"; \
fi; \
done > $(SCHEMA_DIR)/sqlite/seed_data.sql
@sed 's/[[:space:]]*$$//' $(SCHEMA_DIR)/sqlite/seed_data.sql > $(SCHEMA_DIR)/sqlite/seed_data.sql.tmp && mv $(SCHEMA_DIR)/sqlite/seed_data.sql.tmp $(SCHEMA_DIR)/sqlite/seed_data.sql
@echo "=== Generating Go types ==="
sqlc generate
@echo "=== Cleanup ==="
@rm -rf $(SCHEMA_TMP)
@echo "Done."
go-schema-check:
@echo "=== Checking for schema drift ==="
$(MAKE) go-schema SCHEMA_DIR=/tmp/quay-schema-check
@echo "=== Comparing database structure ==="
@rm -f /tmp/quay-drift-committed.db /tmp/quay-drift-fresh.db
@sqlite3 /tmp/quay-drift-committed.db < $(SCHEMA_DIR)/sqlite/quay_schema.sql
@sqlite3 /tmp/quay-drift-committed.db < $(SCHEMA_DIR)/sqlite/seed_data.sql
@sqlite3 /tmp/quay-drift-fresh.db < /tmp/quay-schema-check/sqlite/quay_schema.sql
@sqlite3 /tmp/quay-drift-fresh.db < /tmp/quay-schema-check/sqlite/seed_data.sql
@diff \
<(python3 tools/schema_fingerprint.py /tmp/quay-drift-committed.db) \
<(python3 tools/schema_fingerprint.py /tmp/quay-drift-fresh.db) || \
(echo "ERROR: Schema drift detected. Run 'make go-schema' and commit." && exit 1)
@rm -f /tmp/quay-drift-committed.db /tmp/quay-drift-fresh.db
@rm -rf /tmp/quay-schema-check
@echo "=== Checking generated Go code ==="
@sqlc generate
@git diff --exit-code internal/dal/daldb/ || \
(echo "ERROR: Generated Go code is out of date. Run 'make go-schema' and commit." && exit 1)
@echo "All checks passed."
.PHONY: go-build go-test go-fmt go-vet go-clean
go-build:
@mkdir -p $(GO_BUILD_DIR)
go build $(GO_LDFLAGS) -o $(GO_BUILD_DIR)/$(GO_BINARY_NAME) ./$(GO_CMD_DIR)
go-test:
go test -cover -race ./...
go-fmt:
go fmt ./...
go-vet:
go vet ./...
golangci-lint ./...
go-clean:
rm -rf $(GO_BUILD_DIR)
go mod tidy