forked from creativeprojects/resticprofile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
300 lines (247 loc) · 10.4 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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#
# Makefile for resticprofile
#
GOCMD=go
GOBUILD=$(GOCMD) build
GOINSTALL=$(GOCMD) install
GORUN=$(GOCMD) run
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOTOOL=$(GOCMD) tool
GOMOD=$(GOCMD) mod
GOPATH=$(shell $(GOCMD) env GOPATH)
GOBIN=$(shell $(GOCMD) env GOBIN)
ifeq ($(GOBIN),)
GOBIN := $(GOPATH)/bin
endif
BINARY=resticprofile
BINARY_DARWIN_AMD64=$(BINARY)_darwin
BINARY_DARWIN_ARM64=$(BINARY)_darwin_arm64
BINARY_LINUX_AMD64=$(BINARY)_linux
BINARY_LINUX_ARM64=$(BINARY)_linux_arm64
BINARY_PI=$(BINARY)_pi
BINARY_WINDOWS_AMD64=$(BINARY).exe
BINARY_WINDOWS_ARM64=$(BINARY)_arm64.exe
README=README.md
TESTS=./...
COVERAGE_FILE=coverage.out
BUILD=build/
RESTIC_GEN=$(BUILD)restic-generator
RESTIC_DIR=$(BUILD)restic-
RESTIC_CMD=$(BUILD)restic-commands.json
JSONSCHEMA_DIR=docs/static/jsonschema
CONFIG_REFERENCE_DIR=docs/content/configuration/reference
BUILD_DATE=`date`
BUILD_COMMIT=`git rev-parse HEAD`
CURRENT_DIR = $(shell pwd)
TMP_MOUNT_LINUX=/tmp/backup
TMP_MOUNT_DARWIN=/Volumes/RAMDisk
TMP_MOUNT=
UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
TMP_MOUNT=${TMP_MOUNT_LINUX}
endif
ifeq ($(UNAME),Darwin)
TMP_MOUNT=${TMP_MOUNT_DARWIN}
endif
TOC_START=<\!--ts-->
TOC_END=<\!--te-->
TOC_PATH=toc.md
all: prepare_test test build
.PHONY: test test-ci coverage
.PHONY: download download-restic-key
.PHONY: build build-mac build-linux build-pi build-windows build-no-selfupdate build-all
.PHONY: generate-config-reference generate-jsonschema generate-install generate-restic
.PHONY: all verify prepare_test prepare_build install clean ramdisk rest-server nightly toc syslog checkdoc
verify:
ifeq ($(wildcard $(GOPATH)/.),)
@echo "GOPATH not found, please check your go installation"
exit 1
endif
$(GOBIN)/eget: verify
@echo "[*] $@"
GOBIN="$(GOBIN)" \
$(GOCMD) install -v github.com/zyedidia/eget@latest
$(GOBIN)/goreleaser: verify $(GOBIN)/eget
@echo "[*] $@"
"$(GOBIN)/eget" goreleaser/goreleaser --upgrade-only --to '$(GOBIN)'
$(GOBIN)/github-markdown-toc.go: verify $(GOBIN)/eget
@echo "[*] $@"
"$(GOBIN)/eget" ekalinin/github-markdown-toc.go --upgrade-only --file gh-md-toc --to '$(GOBIN)'
$(GOBIN)/mockery: verify $(GOBIN)/eget
@echo "[*] $@"
"$(GOBIN)/eget" vektra/mockery --upgrade-only --to '$(GOBIN)'
prepare_build: verify download
@echo "[*] $@"
prepare_test: verify download $(GOBIN)/mockery
@echo "[*] $@"
find . -path "*/mocks/*" -exec rm {} \;
"$(GOBIN)/mockery" --config .mockery.yaml
download: verify
@echo "[*] $@"
GOPATH="$(GOPATH)" \
$(GOMOD) download
download-restic-key:
@echo "[*] $@"
KEY_FILE=$(abspath restic/gpg-key.asc)
curl https://restic.net/gpg-key-alex.asc > $(KEY_FILE)
install: prepare_build
@echo "[*] $@"
GOBIN="$(GOBIN)" \
$(GOINSTALL) -v -ldflags "-X 'main.commit=${BUILD_COMMIT}' -X 'main.date=${BUILD_DATE}' -X 'main.builtBy=make'"
build: prepare_build
@echo "[*] $@"
GOPATH="$(GOPATH)" \
$(GOBUILD) -o $(BINARY) -v -ldflags "-X 'main.commit=${BUILD_COMMIT}' -X 'main.date=${BUILD_DATE}' -X 'main.builtBy=make'"
build-no-selfupdate: prepare_build
@echo "[*] $@"
GOPATH="$(GOPATH)" \
$(GOBUILD) -o $(BINARY) -v -tags no_self_update -ldflags "-X 'main.commit=${BUILD_COMMIT}' -X 'main.date=${BUILD_DATE}' -X 'main.builtBy=make'"
build-mac: prepare_build
@echo "[*] $@"
GOPATH="$(GOPATH)" \
GOOS="darwin" GOARCH="amd64" $(GOBUILD) -o $(BINARY_DARWIN_AMD64) -v -ldflags "-X 'main.commit=${BUILD_COMMIT}' -X 'main.date=${BUILD_DATE}' -X 'main.builtBy=make'"
GOPATH="$(GOPATH)" \
GOOS="darwin" GOARCH="arm64" $(GOBUILD) -o $(BINARY_DARWIN_ARM64) -v -ldflags "-X 'main.commit=${BUILD_COMMIT}' -X 'main.date=${BUILD_DATE}' -X 'main.builtBy=make'"
build-linux: prepare_build
@echo "[*] $@"
GOPATH="$(GOPATH)" \
GOOS="linux" GOARCH="amd64" $(GOBUILD) -o $(BINARY_LINUX_AMD64) -v -ldflags "-X 'main.commit=${BUILD_COMMIT}' -X 'main.date=${BUILD_DATE}' -X 'main.builtBy=make'"
GOPATH="$(GOPATH)" \
GOOS="linux" GOARCH="arm64" $(GOBUILD) -o $(BINARY_LINUX_ARM64) -v -ldflags "-X 'main.commit=${BUILD_COMMIT}' -X 'main.date=${BUILD_DATE}' -X 'main.builtBy=make'"
build-pi: prepare_build
@echo "[*] $@"
GOPATH="$(GOPATH)" \
GOOS="linux" GOARCH="arm" GOARM="6" $(GOBUILD) -o $(BINARY_PI) -v -ldflags "-X 'main.commit=${BUILD_COMMIT}' -X 'main.date=${BUILD_DATE}' -X 'main.builtBy=make'"
build-windows: prepare_build
@echo "[*] $@"
GOPATH="$(GOPATH)" \
GOOS="windows" GOARCH="amd64" $(GOBUILD) -o $(BINARY_WINDOWS_AMD64) -v -ldflags "-X 'main.commit=${BUILD_COMMIT}' -X 'main.date=${BUILD_DATE}' -X 'main.builtBy=make'"
GOPATH="$(GOPATH)" \
GOOS="windows" GOARCH="arm64" $(GOBUILD) -o $(BINARY_WINDOWS_ARM64) -v -ldflags "-X 'main.commit=${BUILD_COMMIT}' -X 'main.date=${BUILD_DATE}' -X 'main.builtBy=make'"
build-all: build-mac build-linux build-pi build-windows
test: prepare_test
@echo "[*] $@"
$(GOTEST) $(TESTS)
test-ci: prepare_test
@echo "[*] $@"
$(GOTEST) -v -race -short -coverprofile='coverage.out' ./...
coverage:
@echo "[*] $@"
$(GOTEST) -coverprofile=$(COVERAGE_FILE) $(TESTS)
$(GOTOOL) cover -html=$(COVERAGE_FILE)
clean:
@echo "[*] $@"
$(GOCLEAN)
rm -rf $(BINARY) \
$(BINARY_DARWIN_AMD64) \
$(BINARY_DARWIN_ARM64) \
$(BINARY_LINUX_AMD64) \
$(BINARY_LINUX_ARM64) \
$(BINARY_PI) \
$(BINARY_WINDOWS_AMD64) \
$(BINARY_WINDOWS_ARM64) \
$(COVERAGE_FILE) \
restic_*_linux_amd64* \
${BUILD}restic* \
${BUILD}rclone* \
dist/*
find . -path "*/mocks/*" -exec rm {} \;
restic cache --cleanup
ramdisk: ${TMP_MOUNT}
# Fixed size ramdisk for mac OS X
${TMP_MOUNT_DARWIN}:
# blocks = 512B so it's creating a 2GB fixed size disk image
diskutil erasevolume HFS+ RAMDisk `hdiutil attach -nomount ram://4194304`
# Mount tmpfs on linux
${TMP_MOUNT_LINUX}:
mkdir -p ${TMP_MOUNT_LINUX}
sudo mount -t tmpfs -o "rw,relatime,size=2097152k" tmpfs ${TMP_MOUNT_LINUX}
rest-server:
@echo "[*] $@"
REST_IMAGE=restic/rest-server
REST_CONTAINER=rest_server
REST_DATA=/tmp/restic
REST_OPTIONS=""
docker pull ${REST_IMAGE}
docker run -d -p 8000:8000 -v ${REST_DATA}:/data --name ${REST_CONTAINER} --restart always -e "OPTIONS=${REST_OPTIONS}" ${REST_IMAGE}
nightly: $(GOBIN)/goreleaser
@echo "[*] $@"
GITLAB_TOKEN= goreleaser --snapshot --skip-publish --clean --debug
toc: $(GOBIN)/github-markdown-toc.go
@echo "[*] $@"
cat ${README} | gh-md-toc --hide-footer > ${TOC_PATH}
sed -i ".1" "/${TOC_START}/,/${TOC_END}/{//!d;}" "${README}"
sed -i ".2" "/${TOC_START}/r ${TOC_PATH}" "${README}"
rm ${README}.1 ${README}.2 ${TOC_PATH}
generate-install:
@echo "[*] $@"
godownloader .godownloader.yml -r creativeprojects/resticprofile -o install.sh
generate-restic:
@echo "[*] $@"
$(GOBUILD) -o $(RESTIC_GEN) $(abspath restic/generator)
rm $(RESTIC_CMD) || echo "clean $(RESTIC_CMD)"
$(RESTIC_GEN) --install $(RESTIC_DIR)0.9.4 --version=0.9.4 --base-version --commands $(RESTIC_CMD)
$(RESTIC_GEN) --install $(RESTIC_DIR)0.10.0 --version=0.10.0 --commands $(RESTIC_CMD)
$(RESTIC_GEN) --install $(RESTIC_DIR)0.11.0 --version=0.11.0 --commands $(RESTIC_CMD)
$(RESTIC_GEN) --install $(RESTIC_DIR)0.12.0 --version=0.12.0 --commands $(RESTIC_CMD)
$(RESTIC_GEN) --install $(RESTIC_DIR)0.13.0 --version=0.13.0 --commands $(RESTIC_CMD)
$(RESTIC_GEN) --install $(RESTIC_DIR)0.14.0 --version=0.14.0 --commands $(RESTIC_CMD)
$(RESTIC_GEN) --install $(RESTIC_DIR)0.15.0 --version=0.15.0 --commands $(RESTIC_CMD)
$(RESTIC_GEN) --install $(RESTIC_DIR)0.16.0 --version=0.16.0 --commands $(RESTIC_CMD)
cp $(RESTIC_CMD) restic/commands.json
generate-jsonschema: build
@echo "[*] $@"
mkdir -p $(JSONSCHEMA_DIR) || echo "$(JSONSCHEMA_DIR) exists"
$(abspath $(BINARY)) generate --json-schema v1 > $(JSONSCHEMA_DIR)/config-1.json
$(abspath $(BINARY)) generate --json-schema v2 > $(JSONSCHEMA_DIR)/config-2.json
$(abspath $(BINARY)) generate --json-schema --version 0.9 v1 > $(JSONSCHEMA_DIR)/config-1-restic-0-9.json
$(abspath $(BINARY)) generate --json-schema --version 0.9 v2 > $(JSONSCHEMA_DIR)/config-2-restic-0-9.json
$(abspath $(BINARY)) generate --json-schema --version 0.10 v1 > $(JSONSCHEMA_DIR)/config-1-restic-0-10.json
$(abspath $(BINARY)) generate --json-schema --version 0.10 v2 > $(JSONSCHEMA_DIR)/config-2-restic-0-10.json
$(abspath $(BINARY)) generate --json-schema --version 0.11 v1 > $(JSONSCHEMA_DIR)/config-1-restic-0-11.json
$(abspath $(BINARY)) generate --json-schema --version 0.11 v2 > $(JSONSCHEMA_DIR)/config-2-restic-0-11.json
$(abspath $(BINARY)) generate --json-schema --version 0.12 v1 > $(JSONSCHEMA_DIR)/config-1-restic-0-12.json
$(abspath $(BINARY)) generate --json-schema --version 0.12 v2 > $(JSONSCHEMA_DIR)/config-2-restic-0-12.json
$(abspath $(BINARY)) generate --json-schema --version 0.13 v1 > $(JSONSCHEMA_DIR)/config-1-restic-0-13.json
$(abspath $(BINARY)) generate --json-schema --version 0.13 v2 > $(JSONSCHEMA_DIR)/config-2-restic-0-13.json
$(abspath $(BINARY)) generate --json-schema --version 0.14 v1 > $(JSONSCHEMA_DIR)/config-1-restic-0-14.json
$(abspath $(BINARY)) generate --json-schema --version 0.14 v2 > $(JSONSCHEMA_DIR)/config-2-restic-0-14.json
$(abspath $(BINARY)) generate --json-schema --version 0.15 v1 > $(JSONSCHEMA_DIR)/config-1-restic-0-15.json
$(abspath $(BINARY)) generate --json-schema --version 0.15 v2 > $(JSONSCHEMA_DIR)/config-2-restic-0-15.json
$(abspath $(BINARY)) generate --json-schema --version 0.16 v1 > $(JSONSCHEMA_DIR)/config-1-restic-0-16.json
$(abspath $(BINARY)) generate --json-schema --version 0.16 v2 > $(JSONSCHEMA_DIR)/config-2-restic-0-16.json
generate-config-reference: build
@echo "[*] $@"
META_TITLE="Reference" \
META_WEIGHT="50" \
LAYOUT_NO_HEADLINE="1" \
LAYOUT_HEADINGS_START="#" \
LAYOUT_NOTICE_START="{{% notice note %}}" \
LAYOUT_NOTICE_END="{{% /notice %}}" \
LAYOUT_HINT_START="{{% notice hint %}}" \
LAYOUT_HINT_END="{{% /notice %}}" \
LAYOUT_UPLINK="[go to top](#reference)" \
$(abspath $(BINARY)) generate --config-reference > $(CONFIG_REFERENCE_DIR)/index.md
documentation: generate-jsonschema generate-config-reference
@echo "[*] $@"
cd docs && hugo --minify
syslog-ng:
@echo "[*] $@"
docker run -d \
--name=syslog-ng \
--rm \
-e PUID=1000 \
-e PGID=1000 \
-e TZ=Etc/UTC \
-p 5514:5514/udp \
-p 5514:6601/tcp \
-v $(CURRENT_DIR)/examples/syslog-ng:/config \
-v $(CURRENT_DIR)/log:/var/log \
lscr.io/linuxserver/syslog-ng:latest
checkdoc:
@echo "[*] $@"
$(GOCMD) run ./config/checkdoc -r docs/content
checklinks:
@echo "[*] $@"
muffet -b 8192 --exclude="(linux.die.net|stackoverflow.com)" http://localhost:1313/resticprofile/