forked from shieldproject/shield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
177 lines (142 loc) · 5.92 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
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
# 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
# Running Tests for race conditions
race:
ginkgo -race *
# Building Shield
shield: shieldd shield-agent shield-schema shield-crypt shield-report
shield-crypt:
go $(BUILD_TYPE) ./cmd/shield-crypt
shieldd:
go $(BUILD_TYPE) ./cmd/shieldd
shield-agent:
go $(BUILD_TYPE) ./cmd/shield-agent
shield-schema:
go $(BUILD_TYPE) ./cmd/shield-schema
shield-report:
go $(BUILD_TYPE) ./cmd/shield-report
shield: cmd/shield/help.go
go $(BUILD_TYPE) ./cmd/shield
help.all: cmd/shield/main.go
grep case $< | grep '{''{{' | cut -d\" -f 2 | sort | xargs -n1 -I@ ./shield @ -h > $@
# Building Plugins
plugin: plugins
plugins:
go $(BUILD_TYPE) ./plugin/dummy
@for plugin in $$(cat plugins); do \
echo building plugin $$plugin...; \
go $(BUILD_TYPE) ./plugin/$$plugin; \
done
demo: clean shield plugins
./demo/build
(cd demo && docker-compose up)
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
# Assemble the CLI help with some assistance from our friend, Perl
HELP := $(shell ls -1 cmd/shield/help/*)
cmd/shield/help.go: $(HELP) cmd/shield/help.pl
./cmd/shield/help.pl $(HELP) > $@
fixmes: fixme
fixme:
@grep -rn FIXME * | grep -v vendor/ | grep -v README.md | grep --color FIXME || echo "No FIXMES! YAY!"
dev:
./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 -ldflags="$(LDFLAGS)" -o "$(ARTIFACTS)/plugins/$$plugin" ./plugin/$$plugin; \
done; \
go build -ldflags="$(LDFLAGS)" -o "$(ARTIFACTS)/crypter/shield-crypt" ./cmd/shield-crypt; \
go build -ldflags="$(LDFLAGS)" -o "$(ARTIFACTS)/agent/shield-agent" ./cmd/shield-agent; \
go build -ldflags="$(LDFLAGS)" -o "$(ARTIFACTS)/agent/shield-report" ./cmd/shield-report; \
CGO_ENABLED=1 go build -ldflags="$(LDFLAGS)" -o "$(ARTIFACTS)/daemon/shield-schema" ./cmd/shield-schema; \
CGO_ENABLED=1 go build -ldflags="$(LDFLAGS)" -o "$(ARTIFACTS)/daemon/shieldd" ./cmd/shieldd; \
@echo "Compiling SHIELD CLI For Linux and macOS..."
GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o artifacts/shield-linux-amd64 ./cmd/shield
GOOS=darwin GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o artifacts/shield-darwin-amd64 ./cmd/shield
# GOOS=darwin GOARCH=arm64 go build -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 shieldproject/shield:$(DOCKER_TAG) . --build-arg VERSION=$(DOCKER_TAG)
docker-webdav:
docker build -t shieldproject/webdav:$(DOCKER_TAG) docker/webdav
docker-demo:
docker build -t 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 shieldproject/shield:$(EDGE) . --build-arg VERSION=$(VERSION)
docker push 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 shieldproject/shield:$(VERSION) . --build-arg VERSION=$(VERSION)
docker build -t shieldproject/webdav:$(VERSION) docker/webdav
docker build -t shieldproject/demo:$(VERSION) docker/demo
docker run --rm shieldproject/shield:$(VERSION) /shield/bin/shieldd --version
for I in shieldproject/shield shieldproject/webdav 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