Skip to content

Commit 4bc75a6

Browse files
committed
Update Makefile
1 parent 4eea6ce commit 4bc75a6

1 file changed

Lines changed: 190 additions & 4 deletions

File tree

Makefile

Lines changed: 190 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ BUILDTAGS = "netgo containers_image_ostree_stub exclude_graphdriver_devicemapper
3838
BUILDFLAGS = -tags ${BUILDTAGS} -installsuffix netgo
3939
BUILDPATHS = ./pkg/... ./cmd/... ./internal/...
4040
E2EPATHS = ./test/e2e/...
41-
TESTFLAGS ?=
41+
TESTFLAGS ?= -v -coverprofile cover.out
4242

4343
.DEFAULT_GOAL := all
4444
all: clean build test
4545

46+
.PHONY: ffi
47+
ffi: fmt vet
48+
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/troubleshoot.so -buildmode=c-shared ffi/main.go
49+
4650
.PHONY: test
47-
test: fmt vet
51+
test: generate fmt vet
4852
if [ -n $(RUN) ]; then \
4953
go test ${BUILDFLAGS} ${BUILDPATHS} ${TESTFLAGS} -run $(RUN); \
5054
else \
@@ -54,13 +58,17 @@ test: fmt vet
5458
# Go tests that require a K8s instance
5559
# TODOLATER: merge with test, so we get unified coverage reports? it'll add 21~sec to the test job though...
5660
.PHONY: test-integration
57-
test-integration: fmt vet
61+
test-integration: generate fmt vet
5862
go test -v --tags="integration exclude_graphdriver_devicemapper exclude_graphdriver_btrfs" ${BUILDPATHS}
5963

6064
.PHONY: preflight-e2e-test
6165
preflight-e2e-test:
6266
./test/validate-preflight-e2e.sh
6367

68+
.PHONY: run-examples
69+
run-examples:
70+
./test/run-examples.sh
71+
6472
.PHONY: support-bundle-e2e-test
6573
support-bundle-e2e-test:
6674
./test/validate-support-bundle-e2e.sh
@@ -75,19 +83,31 @@ support-bundle-e2e-go-test:
7583

7684
rebuild: clean build
7785

86+
# Build all binaries in parallel ( -j )
7887
build: tidy
7988
@echo "Build cli binaries"
80-
$(MAKE) bin/support-bundle bin/preflight
89+
$(MAKE) -j bin/support-bundle bin/preflight bin/analyze bin/collect
8190

8291
.PHONY: clean
8392
clean:
93+
@rm -f bin/analyze
8494
@rm -f bin/support-bundle
95+
@rm -f bin/collect
8596
@rm -f bin/preflight
97+
@rm -f bin/troubleshoot.h
98+
@rm -f bin/troubleshoot.so
99+
@rm -f bin/schemagen
100+
@rm -f bin/docsgen
86101

87102
.PHONY: tidy
88103
tidy:
89104
go mod tidy
90105

106+
# Prints the diff of the changes that would be made by `go mod tidy`. Used in CI
107+
.PHONY: tidy-diff
108+
tidy-diff:
109+
go mod tidy -diff
110+
91111
# Only build when any of the files in SOURCES changes, or if bin/<file> is absent
92112
MAKEFILE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
93113
SOURCES := $(shell find $(MAKEFILE_DIR) -type f \( -name "*.go" -o -name "go.mod" -o -name "go.sum" \))
@@ -97,16 +117,182 @@ bin/support-bundle: $(SOURCES)
97117
bin/preflight: $(SOURCES)
98118
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/preflight github.com/replicatedhq/troubleshoot/cmd/preflight
99119

120+
bin/analyze: $(SOURCES)
121+
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/analyze github.com/replicatedhq/troubleshoot/cmd/analyze
122+
123+
bin/collect: $(SOURCES)
124+
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/collect github.com/replicatedhq/troubleshoot/cmd/collect
125+
100126
.PHONY: support-bundle
101127
support-bundle: bin/support-bundle
102128

103129
.PHONY: preflight
104130
preflight: bin/preflight
105131

132+
.PHONY: analyze
133+
analyze: bin/analyze
134+
135+
.PHONY: collect
136+
collect: bin/collect
137+
138+
build-linux: tidy
139+
@echo "Build cli binaries for Linux"
140+
GOOS=linux GOARCH=amd64 $(MAKE) -j bin/support-bundle bin/preflight bin/analyze bin/collect
141+
106142
.PHONY: fmt
107143
fmt:
108144
go fmt ${BUILDPATHS}
109145

110146
.PHONY: vet
111147
vet:
112148
go vet ${BUILDFLAGS} ${BUILDPATHS}
149+
150+
.PHONY: generate
151+
generate: controller-gen client-gen
152+
$(CONTROLLER_GEN) \
153+
object:headerFile=./hack/boilerplate.go.txt paths=./pkg/apis/...
154+
$(CLIENT_GEN) \
155+
--output-dir=. \
156+
--output-pkg=github.com/replicatedhq/troubleshoot/pkg/client \
157+
--clientset-name troubleshootclientset \
158+
--input-base github.com/replicatedhq/troubleshoot/pkg/apis \
159+
--input troubleshoot/v1beta1 \
160+
--input troubleshoot/v1beta2 \
161+
--go-header-file ./hack/boilerplate.go.txt
162+
cp -r troubleshootclientset pkg/client
163+
rm -rf troubleshootclientset
164+
165+
.PHONY: openapischema
166+
openapischema: controller-gen
167+
controller-gen crd +output:dir=./config/crds paths=./pkg/apis/troubleshoot/v1beta1
168+
controller-gen crd +output:dir=./config/crds paths=./pkg/apis/troubleshoot/v1beta2
169+
170+
check-schemas: generate schemas
171+
@if [ -n "$$(git status --short)" ]; then \
172+
echo -e "\033[31mThe git repo is dirty :( Ensure all generated files are committed e.g CRD schema files\033[0;m"; \
173+
git status --short; \
174+
exit 1; \
175+
fi
176+
177+
.PHONY: schemas
178+
schemas: openapischema bin/schemagen
179+
./bin/schemagen --output-dir ./schemas
180+
181+
bin/schemagen:
182+
go build ${LDFLAGS} -o bin/schemagen github.com/replicatedhq/troubleshoot/cmd/schemagen
183+
184+
.PHONY: docs
185+
docs: fmt vet bin/docsgen
186+
./bin/docsgen
187+
188+
bin/docsgen:
189+
go build ${LDFLAGS} -o bin/docsgen github.com/replicatedhq/troubleshoot/cmd/docsgen
190+
191+
controller-gen:
192+
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19.0
193+
CONTROLLER_GEN=$(shell which controller-gen)
194+
195+
.PHONY: client-gen
196+
client-gen:
197+
go install k8s.io/code-generator/cmd/client-gen@v0.34.0
198+
CLIENT_GEN=$(shell which client-gen)
199+
200+
.PHONY: release
201+
release: export GITHUB_TOKEN = $(shell echo ${GITHUB_TOKEN_TROUBLESHOOT})
202+
release:
203+
curl -sL https://git.io/goreleaser | bash -s -- --rm-dist --config deploy/.goreleaser.yml
204+
205+
.PHONY: snapshot-release
206+
snapshot-release:
207+
curl -sL https://git.io/goreleaser | bash -s -- --rm-dist --snapshot --config deploy/.goreleaser.snapshot.yml
208+
docker push replicated/troubleshoot:alpha
209+
docker push replicated/preflight:alpha
210+
211+
.PHONY: local-release
212+
local-release:
213+
curl -sL https://git.io/goreleaser | bash -s -- --rm-dist --snapshot --config deploy/.goreleaser.yaml
214+
docker tag replicated/troubleshoot:alpha localhost:32000/troubleshoot:alpha
215+
docker tag replicated/preflight:alpha localhost:32000/preflight:alpha
216+
docker push localhost:32000/troubleshoot:alpha
217+
docker push localhost:32000/preflight:alpha
218+
219+
.PHONY: run-preflight
220+
run-preflight: bin/preflight
221+
./bin/preflight ./examples/preflight/sample-preflight.yaml
222+
223+
.PHONY: run-support-bundle
224+
run-support-bundle: bin/support-bundle
225+
./bin/support-bundle ./examples/support-bundle/sample-supportbundle.yaml
226+
227+
.PHONY: run-analyze
228+
run-analyze: bin/analyze
229+
./bin/analyze --analyzers ./examples/support-bundle/sample-analyzers.yaml ./support-bundle.tar.gz
230+
231+
.PHONY: init-sbom
232+
init-sbom:
233+
mkdir -p sbom/spdx sbom/assets
234+
235+
.PHONY: install-spdx-sbom-generator
236+
install-spdx-sbom-generator: init-sbom
237+
./scripts/initialize-sbom-build.sh
238+
239+
SPDX_GENERATOR=./sbom/spdx-sbom-generator
240+
241+
.PHONY: generate-sbom
242+
generate-sbom: install-spdx-sbom-generator
243+
$(SPDX_GENERATOR) -o ./sbom/spdx
244+
245+
sbom/assets/troubleshoot-sbom.tgz: generate-sbom
246+
tar -czf sbom/assets/troubleshoot-sbom.tgz sbom/spdx/*.spdx
247+
248+
sbom: sbom/assets/troubleshoot-sbom.tgz
249+
cosign sign-blob \
250+
--key ./cosign.key \
251+
--tlog-upload \
252+
--yes \
253+
--rekor-url=https://rekor.sigstore.dev \
254+
sbom/assets/troubleshoot-sbom.tgz > sbom/assets/troubleshoot-sbom.tgz.sig
255+
cosign public-key --key cosign.key --outfile sbom/assets/key.pub
256+
257+
.PHONY: scan
258+
scan:
259+
trivy fs \
260+
--scanners vuln \
261+
--exit-code=1 \
262+
--severity="HIGH,CRITICAL" \
263+
--ignore-unfixed \
264+
./
265+
266+
.PHONY: watch
267+
watch: npm-install
268+
bin/watch.js
269+
270+
## Syncronize the code with a remote server. More info: CONTRIBUTING.md
271+
.PHONY: watchrsync
272+
watchrsync: npm-install
273+
bin/watchrsync.js
274+
275+
.PHONY: npm-install
276+
npm-install:
277+
npm --version 2>&1 >/dev/null || ( echo "npm not installed; install npm to set up watchrsync" && exit 1 )
278+
npm list gaze-run-interrupt || npm install install --no-save gaze-run-interrupt@~2.0.0
279+
280+
281+
######## Lagacy make targets ###########
282+
# Deprecated: These can be removed
283+
.PHONY: run-troubleshoot
284+
run-troubleshoot: run-support-bundle
285+
286+
longhorn:
287+
git clone https://github.com/longhorn/longhorn-manager.git
288+
cd longhorn-manager && git checkout v1.2.2 && cd ..
289+
rm -rf pkg/longhorn
290+
mv longhorn-manager/k8s/pkg pkg/longhorn
291+
mv longhorn-manager/types pkg/longhorn/types
292+
mv longhorn-manager/util pkg/longhorn/util
293+
rm -rf pkg/longhorn/util/daemon
294+
rm -rf pkg/longhorn/util/server
295+
find pkg/longhorn -type f | xargs sed -i "s/github.com\/longhorn\/longhorn-manager\/k8s\/pkg/github.com\/replicatedhq\/troubleshoot\/pkg\/longhorn/g"
296+
find pkg/longhorn -type f | xargs sed -i "s/github.com\/longhorn\/longhorn-manager\/types/github.com\/replicatedhq\/troubleshoot\/pkg\/longhorn\/types/g"
297+
find pkg/longhorn -type f | xargs sed -i "s/github.com\/longhorn\/longhorn-manager\/util/github.com\/replicatedhq\/troubleshoot\/pkg\/longhorn\/util/g"
298+
rm -rf longhorn-manager

0 commit comments

Comments
 (0)