-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathMakefile
More file actions
204 lines (163 loc) · 7.23 KB
/
Copy pathMakefile
File metadata and controls
204 lines (163 loc) · 7.23 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
# Run me to verify that all tests pass and all binaries are buildable before pushing!
# If you do not, then Travis will be sad.
BUILD_TYPE ?= build
DOCKER_TAG ?= dev
EDGE ?= edge
# Everything; this is the default behavior
LDFLAGS := -X main.Version=$(VERSION)
all: build test
build: format shieldd shield shield-agent shield-schema shield-crypt shield-report plugins
# go fmt ftw
format:
go list ./... | grep -v vendor | xargs go fmt
# Running Tests
test: go-tests api-tests plugin-tests
plugin-tests: plugins
go build ./plugin/mock
./t/plugins
@rm -f mock
go-tests: shield
go list ./... | grep -v vendor/ | PATH=$$PWD:$$PWD/bin:$$PWD/test/bin:$$PATH xargs go test -race
api-tests: shieldd shield-schema shield-crypt shield-agent shield-report
./t/api
# The db package's PostgreSQL and MySQL specs skip themselves unless a DSN is
# exported, so that `make test` needs nothing but SQLite. This target stands
# the servers up and runs them for real.
test-databases:
docker compose -f docker-compose.test-databases.yml up -d --wait
SHIELD_TEST_PG_DSN='postgres://shield:shield@127.0.0.1:15432/shield?sslmode=disable' \
SHIELD_TEST_MYSQL_DSN='root:shield@tcp(127.0.0.1:13306)/shield?parseTime=true' \
go test -count=1 ./db/
test-databases-down:
docker compose -f docker-compose.test-databases.yml down -v
# Running Tests for race conditions
race:
go run github.com/onsi/ginkgo/v2/ginkgo run -race ./...
# Building Shield
shield: shieldd shield-cli shield-agent shield-schema shield-crypt shield-report
shield-crypt:
go $(BUILD_TYPE) -mod vendor ./cmd/shield-crypt
shieldd:
go $(BUILD_TYPE) -mod vendor ./cmd/shieldd
shield-agent:
go $(BUILD_TYPE) -mod vendor ./cmd/shield-agent
shield-schema:
go $(BUILD_TYPE) -mod vendor ./cmd/shield-schema
shield-report:
go $(BUILD_TYPE) -mod vendor ./cmd/shield-report
shield-cli:
go $(BUILD_TYPE) -mod vendor -ldflags "$(LDFLAGS)" ./cmd/shield
# Building Plugins
JOBS ?= $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)
plugin: plugins
plugins:
@echo "Building dummy plugin..."
@go $(BUILD_TYPE) -mod vendor ./plugin/dummy || go $(BUILD_TYPE) ./plugin/dummy
@for plugin in $$(cat plugins); do \
echo "building plugin $$plugin..."; \
if ! go $(BUILD_TYPE) -mod vendor ./plugin/$$plugin; then \
GOFLAGS=-mod=mod go $(BUILD_TYPE) ./plugin/$$plugin; \
fi; \
done
demo: clean shield plugins
@if [ -x ./demo/build ]; then \
./demo/build; \
else \
echo "(warning) ./demo/build not found; skipping demo build"; \
fi
(cd docker/demo && docker compose up)
# Local build stack (core/agent/demo/webdav from local source build)
demo-local:
docker compose -f docker-compose.local.yml up --build
dev-local: demo-local
docs: docs/dev/API.md
./bin/mkdocs --version latest --docroot /docs --output tmp/docs --style basic
gow -r tmp/docs
docs/dev/API.md: docs/dev/API.yml
perl ./docs/regen.pl <$+ >$@~
mv $@~ $@
clean:
rm -f shield shieldd shield-agent shield-schema shield-crypt shield-report
rm -f $$(cat plugins) dummy
fixmes: fixme
fixme:
@grep -rn FIXME * | grep -v vendor/ | grep -v README.md | grep --color FIXME || echo "No FIXMES! YAY!"
# Quick local development mode (UI + API) using docker-compose
# Usage: make dev
# then open http://localhost:9009
dev: demo
# Keep legacy testdev flow for deeper local test sandbox
dev-test:
./bin/testdev
# Deferred: Naming plugins individually, e.g. make plugin dummy
init:
go get github.com/kardianos/govendor
go install github.com/kardianos/govendor
save-deps:
govendor add +external
ARTIFACTS := artifacts/shield-server-linux-amd64
LDFLAGS := -X main.Version=$(VERSION)
shipit: release
release:
@echo "Checking that VERSION was defined in the calling environment"
@test -n "$(VERSION)"
@echo "OK. VERSION=$(VERSION)"
@echo "Compiling SHIELD Linux Server Distribution..."
export GOOS=linux GOARCH=amd64; \
for plugin in $$(cat plugins); do \
go build -mod vendor -ldflags="$(LDFLAGS)" -o "$(ARTIFACTS)/plugins/$$plugin" ./plugin/$$plugin; \
done; \
go build -mod vendor -ldflags="$(LDFLAGS)" -o "$(ARTIFACTS)/crypter/shield-crypt" ./cmd/shield-crypt; \
go build -mod vendor -ldflags="$(LDFLAGS)" -o "$(ARTIFACTS)/agent/shield-agent" ./cmd/shield-agent; \
go build -mod vendor -ldflags="$(LDFLAGS)" -o "$(ARTIFACTS)/agent/shield-report" ./cmd/shield-report; \
CGO_ENABLED=1 go build -mod vendor -ldflags="$(LDFLAGS)" -o "$(ARTIFACTS)/daemon/shield-schema" ./cmd/shield-schema; \
CGO_ENABLED=1 go build -mod vendor -ldflags="$(LDFLAGS)" -o "$(ARTIFACTS)/daemon/shieldd" ./cmd/shieldd; \
@echo "Compiling SHIELD CLI For Linux and macOS..."
GOOS=linux GOARCH=amd64 go build -mod vendor -ldflags="$(LDFLAGS)" -o artifacts/shield-linux-amd64 ./cmd/shield
GOOS=darwin GOARCH=amd64 go build -mod vendor -ldflags="$(LDFLAGS)" -o artifacts/shield-darwin-amd64 ./cmd/shield
GOOS=darwin GOARCH=arm64 go build -mod vendor -ldflags="$(LDFLAGS)" -o artifacts/shield-darwin-arm64 ./cmd/shield
mkdir -p "$(ARTIFACTS)/cli"
cp artifacts/shield-linux-amd64 "$(ARTIFACTS)/cli/shield"
@echo "Assembling Linux Server Distribution..."
rm -f artifacts/*.tar.gz
cd artifacts && for x in shield-server-*; do \
cp -a ../web/htdocs $$x/webui; \
mkdir -p $$x/webui/cli/linux; cp ../artifacts/shield-linux-amd64 $$x/webui/cli/linux/shield; \
mkdir -p $$x/webui/cli/darwin/amd64; cp ../artifacts/shield-darwin-amd64 $$x/webui/cli/darwin/amd64/shield; \
mkdir -p $$x/webui/cli/darwin/arm64; cp ../artifacts/shield-darwin-arm64 $$x/webui/cli/darwin/arm64/shield; \
cp ../bin/shield-pipe $$x/daemon; \
cp ../bin/shield-recover $$x/daemon; \
cp ../bin/shield-restarter $$x/daemon; \
tar -czvf $$x.tar.gz $$x; \
rm -r $$x; \
done
docker: docker-shield docker-webdav docker-demo
docker-shield:
docker build -t quay.io/shieldproject/shield:$(DOCKER_TAG) . --build-arg VERSION=$(DOCKER_TAG)
docker-webdav:
docker build -t quay.io/shieldproject/webdav:$(DOCKER_TAG) docker/webdav
docker-demo:
docker build -t quay.io/shieldproject/demo:$(DOCKER_TAG) docker/demo
docker-edge:
@echo "Checking that VERSION was defined in the calling environment"
@test -n "$(VERSION)"
@echo "OK. VERSION=$(VERSION)"
docker build -t quay.io/shieldproject/shield:$(EDGE) . --build-arg VERSION=$(VERSION)
docker push quay.io/shieldproject/shield:$(EDGE)
docker-release:
@echo "Checking that VERSION was defined in the calling environment"
@test -n "$(VERSION)"
@echo "OK. VERSION=$(VERSION)"
docker build -t quay.io/shieldproject/shield:$(VERSION) . --build-arg VERSION=$(VERSION)
docker build -t quay.io/shieldproject/webdav:$(VERSION) docker/webdav
docker build -t quay.io/shieldproject/demo:$(VERSION) docker/demo
docker run --rm quay.io/shieldproject/shield:$(VERSION) /shield/bin/shieldd --version
for I in quay.io/shieldproject/shield quay.io/shieldproject/webdav quay.io/shieldproject/demo; do \
docker tag $$I:$(VERSION) $$I:latest; \
docker push $$I:latest; \
for V in $(VERSION) $(shell echo "$(VERSION)" | sed -e 's/\.[^.]*$$//') $(shell echo "$(VERSION)" | sed -e 's/\..*$$//'); do \
docker tag $$I:$(VERSION) $$I:$$V; \
docker push $$I:$$V; \
done \
done
.PHONY: plugins dev shield shieldd shield-schema shield-agent shield-crypt shield-report demo docs test-databases test-databases-down