Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
241 lines (212 loc) · 7.85 KB
/
Copy pathMakefile
File metadata and controls
241 lines (212 loc) · 7.85 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
# This file is part of Dependency-Track.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) OWASP Foundation. All Rights Reserved.
DEFAULT_BASE_REF := $(shell git rev-parse --verify --quiet upstream/main >/dev/null 2>&1 && echo upstream/main || echo origin/main)
BASE_REF ?= $(DEFAULT_BASE_REF)
BUF_DOCKER := docker run --rm --user "$(shell id -u):$(shell id -g)" -e BUF_CACHE_DIR=/tmp/buf-cache -v "$(CURDIR):/workspace" -w /workspace
BUF_FORMAT_FLAGS := --exclude-path support/cyclonedx-proto/src/main/proto/org/cyclonedx/v1_7/cyclonedx.proto
BUF_IMAGE := bufbuild/buf:1.75.0@sha256:adf82c7170be6629ec81dc907921ac1699407cd11c4f7fd7521b13c74152f849
MIGRATION_DIR := migration/src/main/resources/org/dependencytrack/migration
DEX_MIGRATION_DIR := dex/engine-migration/src/main/resources/org/dependencytrack/dex/engine/migration
OASDIFF_IMAGE := tufin/oasdiff:v1.37.0@sha256:ff02af37a254b5199b9d72e7bba93dae5837a9119d59459168d1398893b47aea
SPECTRAL_IMAGE := stoplight/spectral:6.16.3@sha256:a07aa4455367b9501b574423b684ab0ef3ee42556089013583318ec015249050
SQUAWK_IMAGE := ghcr.io/sbdchd/squawk:2.63.0@sha256:e3b8e534994ad714ec3ca1017f7e80ecb8f8a15b161b8c6eb25303eced5da3ab
MVN := $(shell command -v mvn 2>/dev/null)
MVND := $(shell command -v mvnd 2>/dev/null)
ifeq ($(MVND),)
MVND := $(MVN)
endif
MVN_NO_BUILDCACHE := -Dmaven.build.cache.enabled=false
ifdef CI
MVN_FLAGS := -B
else
MVN_FLAGS :=
endif
ifdef AGENT
MVN_FLAGS += -B -q -Dsurefire.useFile=false
endif
build:
$(MVND) $(MVN_FLAGS) -Pquick package
.PHONY: build
build-dist:
$(MVND) $(MVN_FLAGS) -Pdist,quick package
.PHONY: build-dist
build-image: build
docker build \
-t ghcr.io/dependencytrack/apiserver:local \
-f apiserver/src/main/docker/Dockerfile \
apiserver
.PHONY: build-image
build-v4-migrator-image: build
docker build \
-t ghcr.io/dependencytrack/v4-migrator:local \
-f support/v4-migrator/src/main/docker/Dockerfile \
support/v4-migrator
.PHONY: build-v4-migrator-image
datanucleus-enhance:
$(MVND) $(MVN_FLAGS) \
-Pquick \
-Dresolve.skip \
-pl alpine/alpine-model,apiserver \
process-classes
.PHONY: datanucleus-enhance
install:
$(MVND) $(MVN_FLAGS) -Pquick install
.PHONY: install
lint-java:
$(MVND) $(MVN_FLAGS) $(MVN_NO_BUILDCACHE) -q validate
.PHONY: lint-java
format-java:
$(MVND) $(MVN_FLAGS) $(MVN_NO_BUILDCACHE) -q spotless:apply
.PHONY: format-java
lint-migrations:
@if ! git rev-parse --verify --quiet "$(BASE_REF)" >/dev/null; then \
echo "BASE_REF '$(BASE_REF)' does not resolve to a git ref."; \
echo "Override on the command line, e.g.: make lint-migrations BASE_REF=upstream/main"; \
exit 1; \
fi; \
changed=$$( \
{ \
git diff --name-only --diff-filter=AM "$(BASE_REF)...HEAD" -- '$(MIGRATION_DIR)/*.sql'; \
git diff --name-only --diff-filter=AM -- '$(MIGRATION_DIR)/*.sql'; \
git ls-files --others --exclude-standard -- '$(MIGRATION_DIR)/*.sql'; \
} | sort -u); \
if [ -z "$$changed" ]; then \
echo "No migration changes to lint in $(MIGRATION_DIR) (BASE_REF=$(BASE_REF))."; \
exit 0; \
fi; \
echo "Linting migrations:"; \
echo "$$changed" | sed 's/^/ /'; \
docker run --rm -i \
--platform linux/amd64 \
-v "$(CURDIR):/work" \
-w /work \
$(SQUAWK_IMAGE) \
lint $$changed
.PHONY: lint-migrations
lint-dex-migration:
@$(MAKE) lint-migrations MIGRATION_DIR="$(DEX_MIGRATION_DIR)"
.PHONY: lint-dex-migration
lint-openapi:
@dups=$$(find api/src/main/openapi -path '*/schemas/*.yaml' -exec basename {} \; \
| sort | uniq -d); \
if [ -n "$$dups" ]; then \
echo "Duplicate schema basenames (must be globally unique):"; \
echo "$$dups"; \
exit 1; \
fi
docker run --rm -i -w /work \
--platform linux/amd64 \
-v "$(CURDIR)/api:/work" \
$(SPECTRAL_IMAGE) lint \
--ruleset src/main/spectral/ruleset.yaml \
src/main/openapi/openapi.yaml
.PHONY: lint-openapi
lint-openapi-breaking:
@base_commit=$$(git merge-base "$(BASE_REF)" HEAD) || exit 1; \
base=$$(mktemp -d); \
trap 'rm -rf "$$base"' EXIT; \
git archive "$$base_commit" api/src/main/openapi | tar -x -C "$$base" || exit 1; \
docker run --rm \
-v "$$base/api/src/main/openapi:/base:ro" \
-v "$(CURDIR)/api/src/main/openapi:/revision:ro" \
$(OASDIFF_IMAGE) breaking \
--fail-on ERR \
/base/openapi.yaml \
/revision/openapi.yaml
.PHONY: lint-openapi-breaking
lint-proto:
$(BUF_DOCKER) $(BUF_IMAGE) lint
$(BUF_DOCKER) $(BUF_IMAGE) format --diff --exit-code $(BUF_FORMAT_FLAGS)
.PHONY: lint-proto
lint-proto-breaking:
@base_commit=$$(git merge-base "$(BASE_REF)" HEAD) || exit 1; \
against=$$(mktemp -d); \
trap 'rm -rf "$$against"' EXIT; \
git archive "$$base_commit" buf.yaml ':(glob)**/*.proto' | tar -x -C "$$against" || exit 1; \
$(BUF_DOCKER) -v "$$against:/against:ro" $(BUF_IMAGE) breaking --against /against
.PHONY: lint-proto-breaking
format-proto:
$(BUF_DOCKER) $(BUF_IMAGE) format --write $(BUF_FORMAT_FLAGS)
.PHONY: format-proto
lint: lint-java lint-migrations lint-dex-migration lint-openapi lint-openapi-breaking lint-proto lint-proto-breaking
.PHONY: lint
test:
$(MVND) $(MVN_FLAGS) -Dspotless.check.skip -Dcyclonedx.skip verify
.PHONY: test
test-single:
@rm -rf "$(MODULE)/target/surefire-reports"
$(MVND) $(MVN_FLAGS) test \
$(MVN_NO_BUILDCACHE) \
-Dspotless.check.skip \
-Dcyclonedx.skip \
-pl "$(MODULE)" \
-am \
-Dtest="$(TEST)"
@if ! ls "$(MODULE)"/target/surefire-reports/TEST-*.xml >/dev/null 2>&1; then \
echo "No tests in $(MODULE) matched TEST=$(TEST)"; \
exit 1; \
fi
.PHONY: test-single
new-migration:
@if [ -z "$(NAME)" ]; then \
echo "Usage: make new-migration NAME=\"short description\""; \
exit 1; \
fi; \
slug=$$(printf '%s' "$(NAME)" | tr '[:upper:]' '[:lower:]' \
| sed -e 's/[^a-z0-9]\{1,\}/_/g' -e 's/^_//' -e 's/_$$//'); \
if [ -z "$$slug" ]; then \
echo "NAME must contain at least one alphanumeric character"; \
exit 1; \
fi; \
ts=$$(date -u +%Y%m%d%H%M); \
dir="migration/src/main/resources/org/dependencytrack/migration"; \
if ls "$$dir"/V$${ts}__*.sql >/dev/null 2>&1; then \
echo "A migration with version $$ts already exists; wait a minute and retry"; \
exit 1; \
fi; \
path="$$dir/V$${ts}__$${slug}.sql"; \
: > "$$path"; \
echo "$$path"
.PHONY: new-migration
apiserver-dev:
$(MVN) $(MVN_FLAGS) -q -Pquick,dev-services -pl apiserver -am verify
.PHONY: apiserver-dev
apiserver-dev-remove-containers:
@ids=$$(docker ps -aq --filter label=org.dependencytrack.dev-services); \
if [ -n "$$ids" ]; then \
docker rm -f $$ids; \
else \
echo "No dev services containers to remove"; \
fi
.PHONY: apiserver-dev-remove-containers
test-e2e: build-image
$(MVND) $(MVN_FLAGS) $(MVN_NO_BUILDCACHE) -pl e2e -am -DskipE2E=false verify
.PHONY: test-e2e
clean:
$(MVND) $(MVN_FLAGS) $(MVN_NO_BUILDCACHE) -q clean
.PHONY: clean
clean-build-cache:
rm -rf "$${HOME}"/.m2/build-cache/*/org.dependencytrack/
.PHONY: clean-build-cache
update-distro-info:
curl -fsSL -o support/os-distro-metadata/src/main/resources/org/dependencytrack/support/distrometadata/debian.csv \
https://debian.pages.debian.net/distro-info-data/debian.csv
curl -fsSL -o support/os-distro-metadata/src/main/resources/org/dependencytrack/support/distrometadata/ubuntu.csv \
https://debian.pages.debian.net/distro-info-data/ubuntu.csv
curl -fsSL -o support/os-distro-metadata/src/main/resources/org/dependencytrack/support/distrometadata/LICENSE \
https://salsa.debian.org/debian/distro-info-data/-/raw/main/debian/copyright
.PHONY: update-distro-info