-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
108 lines (75 loc) · 3.51 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
.PHONY: install-tools dev-server dev-tailwind dev-templ dev build-server build-tailwind build-templ build launch deploy clean test
BINARY_NAME = soarca-gui
DIRECTORY = $(sort $(dir $(wildcard ./test/*/)))
VERSION = $(shell git describe --tags --dirty)
BUILDTIME := $(shell date '+%Y-%m-%dT%T%z')
GOLDFLAGS += -X main.Version=$(VERSION)
GOLDFLAGS += -X main.Buildtime=$(BUILDTIME)
GOFLAGS = -ldflags "$(GOLDFLAGS)"
#-----------------------------------------------------
# install
#-----------------------------------------------------
install-tools:
bash build/dependencies.sh
#-----------------------------------------------------
# DEV
#-----------------------------------------------------
dev:
@make -j dev-templ dev-tailwind dev-server
dev-server:
# run air to detect any go file changes to re-build and re-run the server.
@go run github.com/air-verse/air@v1.52.3 \
--build.cmd "templ generate && go build -ldflags \"-X main.Version=$(VERSION)\" --tags dev -o tmp/bin/main ./server/" --build.bin "tmp/bin/main" --build.delay "100" \
--build.exclude_dir "node_modules" \
--build.exclude_regex ".*_templ.go" \
--build.include_ext "go,templ" \
--build.stop_on_error "false" \
--build.exclude_regex ".*_templ.go" \
--build.poll "true" \
--misc.clean_on_exit true
# watch for any js or css change in the assets/ folder, then reload the browser via templ proxy.
sync_assets:
go run github.com/air-verse/air@latest \
--build.cmd "go run github.com/a-h/templ/cmd/templ@latest generate --notify-proxy" \
--build.bin "true" \
--build.delay "100" \
--build.exclude_dir "" \
--build.include_dir "public" \
--build.include_ext "js,css"
dev-templ:
@go run github.com/a-h/templ/cmd/templ@latest generate --watch --proxy="http://localhost:8081" --open-browser=false -v
dev-tailwind:
@make ARGS="--watch" build-tailwind
#-----------------------------------------------------
# BUILD
#-----------------------------------------------------
build: build-templ build-tailwind build-server
build-server:
echo "Compiling for every OS and Platform"
CGO_ENABLED=0 go build -o build/${BINARY_NAME} $(GOFLAGS) ./server/main.go
docker:
docker build --no-cache -t soarca-gui:${VERSION} --build-arg="VERSION=${VERSION}" .
build-templ:
@templ generate
build-tailwind:
@npx tailwindcss -m -i ./views/assets/app.css -o ./public/public/styles.css $(ARGS)
lint: build-templ
GOFLAGS=-buildvcs=false golangci-lint run --timeout 5m0s -v
clean:
rm -rf build/soarca* build/main
rm -rf bin/*
find . -type f -name "*_templ.go" -delete
run: docker
GIT_VERSION=${VERSION} docker compose up --build --force-recreate -d
test: build-templ
go test ./... -v
.DEFAULT_GOAL := build
# release
compile: build-templ build-tailwind
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-linux-amd64 $(GOFLAGS) server/main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/${BINARY_NAME}-${VERSION}-darwin-arm64 $(GOFLAGS) server/main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-windows-amd64 $(GOFLAGS) server/main.go
sbom: build-templ compile
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 cyclonedx-gomod app -main server -json -licenses -output bin/${BINARY_NAME}-${VERSION}-linux-amd64.bom.json
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 cyclonedx-gomod app -main server -json -licenses -output bin/${BINARY_NAME}-${VERSION}-darwin-amd64.bom.json
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 cyclonedx-gomod app -main server -json -licenses -output bin/${BINARY_NAME}-${VERSION}-windows-amd64.bom.json