forked from skycoin/skywire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
392 lines (297 loc) · 16.8 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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
.PHONY : check lint install-linters dep test
.PHONY : build clean install format bin
.PHONY : host-apps bin
.PHONY : docker-image docker-clean docker-network
.PHONY : docker-apps docker-bin docker-volume
.PHONY : docker-run docker-stop
VERSION := $(shell git describe)
RFC_3339 := "+%Y-%m-%dT%H:%M:%SZ"
COMMIT := $(shell git rev-list -1 HEAD)
PROJECT_BASE := github.com/skycoin/skywire
SKYWIRE_UTILITIES_BASE := github.com/skycoin/skywire-utilities
ifeq ($(OS),Windows_NT)
SHELL := pwsh
OPTS?=powershell -Command setx GO111MODULE on;
DATE := $(shell powershell -Command date -u ${RFC_3339})
.DEFAULT_GOAL := help-windows
else
SHELL := /bin/bash
OPTS?=GO111MODULE=on
DATE := $(shell date -u $(RFC_3339))
.DEFAULT_GOAL := help
endif
ifeq ($(OS),Windows_NT)
SYSTRAY_CGO_ENABLED := 1
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
SYSTRAY_CGO_ENABLED := 0
endif
ifeq ($(UNAME_S),Darwin)
SYSTRAY_CGO_ENABLED := 1
endif
endif
ifeq ($(VERSION),)
VERSION = unknown
endif
ifeq ($(COMMIT),)
COMMIT = unknown
endif
ifeq ($(BUILDTAG),)
ifeq ($(OS),Windows_NT)
BUILDTAG = Windows
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
BUILDTAG = Linux
endif
ifeq ($(UNAME_S),Darwin)
BUILDTAG = Darwin
endif
endif
endif
STATIC_OPTS?= $(OPTS) CC=musl-gcc
MANAGER_UI_DIR = static/skywire-manager-src
GO_BUILDER_VERSION=v1.17
MANAGER_UI_BUILT_DIR=pkg/visor/static
TEST_OPTS:=-cover -timeout=5m -mod=vendor
GOARCH:=$(shell go env GOARCH)
ifneq (,$(findstring 64,$(GOARCH)))
TEST_OPTS:=$(TEST_OPTS) -race
endif
BUILDINFO_PATH := $(SKYWIRE_UTILITIES_BASE)/pkg/buildinfo
BUILD_PATH := ./build/
BUILDINFO_VERSION := -X $(BUILDINFO_PATH).version=$(VERSION)
BUILDINFO_DATE := -X $(BUILDINFO_PATH).date=$(DATE)
BUILDINFO_COMMIT := -X $(BUILDINFO_PATH).commit=$(COMMIT)
BUILDTAGINFO := -X $(PROJECT_BASE)/pkg/visor.BuildTag=$(BUILDTAG)
BUILDINFO?=$(BUILDINFO_VERSION) $(BUILDINFO_DATE) $(BUILDINFO_COMMIT) $(BUILDTAGINFO)
INFO?=$(VERSION) $(DATE) $(COMMIT) $(BUILDTAG)
BUILD_OPTS?="-ldflags=$(BUILDINFO)" -mod=vendor $(RACE_FLAG)
BUILD_OPTS_DEPLOY?="-ldflags=$(BUILDINFO) -w -s"
buildinfo:
@echo $(INFO)
version:
@echo $(VERSION)
date:
@echo $(DATE)
commit:
@echo $(COMMIT)
check: lint test ## Run linters and tests
check-windows: lint-windows test-windows ## Run linters and tests on windows image
build: host-apps bin ## Install dependencies, build apps and binaries. `go build` with ${OPTS}
build-windows: host-apps-windows bin-windows ## Install dependencies, build apps and binaries. `go build` with ${OPTS}
build-static: host-apps-static bin-static ## Build apps and binaries. `go build` with ${OPTS}
build-static-wos: host-apps-static bin-static-wos ## Build apps and binaries. `go build` with ${OPTS}
build-example: host-apps example-apps bin ## Build apps, example apps and binaries. `go build` with ${OPTS}
installer: mac-installer ## Builds MacOS installer for skywire-visor
install-system-linux: build ## Install apps and binaries over those provided by the linux package - linux package must be installed first!
sudo echo "sudo cache"
sudo install -Dm755 $(BUILD_PATH){skywire-cli,skywire-visor} /opt/skywire/bin/ & \
sudo install -Dm755 $(BUILD_PATH)apps/{vpn-server,vpn-client,skysocks-client,skysocks,skychat} /opt/skywire/apps/
install-generate: ## Installs required execs for go generate.
${OPTS} go install github.com/mjibson/esc github.com/vektra/mockery/v2@latest
generate: ## Generate mocks and config README's
go generate ./...
clean: ## Clean project: remove created binaries and apps
-rm -rf ./build ./local
clean-windows: ## Clean project: remove created binaries and apps
powershell -Command "If (Test-Path ./local) { Remove-Item -Path ./local -Force -Recurse }"
powershell -Command "If (Test-Path ./build) { Remove-Item -Path ./build -Force -Recurse }"
install: ## Install `skywire-visor`, `skywire-cli`, `setup-node`
${OPTS} go install ${BUILD_OPTS} ./cmd/skywire-visor ./cmd/skywire-cli ./cmd/setup-node
install-windows: ## Install `skywire-visor`, `skywire-cli`, `setup-node`
powershell 'Get-ChildItem .\cmd | % { ${OPTS} go install ${BUILD_OPTS} ./ $$_.FullName }'
install-static: ## Install `skywire-visor`, `skywire-cli`, `setup-node`
${STATIC_OPTS} go install -trimpath --ldflags '-linkmode external -extldflags "-static" -buildid=' ./cmd/skywire-visor ./cmd/skywire-cli ./cmd/setup-node
lint: ## Run linters. Use make install-linters first
golangci-lint --version
${OPTS} golangci-lint run -c .golangci.yml ./...
lint-windows: ## Run linters. Use make install-linters-windows first
powershell 'golangci-lint --version'
powershell 'golangci-lint run -c .golangci.yml ./...'
test: ## Run tests
-go clean -testcache &>/dev/null
${OPTS} go test ${TEST_OPTS} ./internal/... ./pkg/... ./cmd/...
${OPTS} go test ${TEST_OPTS}
test-windows: ## Run tests on windows
@go clean -testcache
${OPTS} go test ${TEST_OPTS} ./internal/... ./pkg/... ./cmd/...
install-linters: ## Install linters
- VERSION=latest ./ci_scripts/install-golangci-lint.sh
${OPTS} go install golang.org/x/tools/cmd/goimports@latest github.com/incu6us/goimports-reviser/v2@latest
install-linters-windows: ## Install linters
${OPTS} go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest golang.org/x/tools/cmd/goimports@latest
tidy: ## Tidies and vendors dependencies.
${OPTS} go mod tidy -v
format: tidy ## Formats the code. Must have goimports and goimports-reviser installed (use make install-linters).
${OPTS} goimports -w -local ${PROJECT_BASE} ./pkg ./cmd ./internal
find . -type f -name '*.go' -not -path "./.git/*" -not -path "./vendor/*" -exec goimports-reviser -project-name ${PROJECT_BASE} {} \;
format-windows: tidy ## Formats the code. Must have goimports and goimports-reviser installed (use make install-linters).
powershell 'Get-ChildItem -Directory | where Name -NotMatch vendor | % { Get-ChildItem $$_ -Recurse -Include *.go } | % {goimports -w -local ${PROJECT_BASE} $$_ }'
dep: tidy ## Sorts dependencies
${OPTS} go mod vendor -v
snapshot: ## goreleaser --snapshot --skip-publish --rm-dist
goreleaser --snapshot --skip-publish --rm-dist
snapshot-linux: ## goreleaser --snapshot --config .goreleaser-linux.yml --skip-publish --rm-dist
goreleaser --snapshot --config .goreleaser-linux.yml --skip-publish --rm-dist
snapshot-clean: ## Cleans snapshot / release
rm -rf ./dist
host-apps: ## Build app
test -d $(BUILD_PATH) && rm -r $(BUILD_PATH) || true
mkdir -p $(BUILD_PATH)apps
${OPTS} go build ${BUILD_OPTS} -o $(BUILD_PATH)apps/ ./cmd/apps/...
example-apps: ## Build example apps
${OPTS} go build ${BUILD_OPTS} -o $(BUILD_PATH)apps/ ./example/...
host-apps-windows: ## build apps on windows
powershell -Command new-item $(BUILD_PATH)apps -itemtype directory -force
powershell 'Get-ChildItem .\cmd\apps | % { ${OPTS} go build ${BUILD_OPTS} -o $(BUILD_PATH)apps $$_.FullName }'
# Static Apps
host-apps-static: ## Build app
test -d apps && rm -r apps || true
mkdir -p ./apps
${STATIC_OPTS} go build -trimpath --ldflags '-linkmode external -extldflags "-static" -buildid=' -o $(BUILD_PATH)apps/ ./cmd/apps/...
host-apps-deploy: ## Build app
test -d apps && rm -r apps || true
mkdir -p ./apps
${OPTS} go build ${BUILD_OPTS_DEPLOY} -o $(BUILD_PATH)apps/ ./cmd/apps/...
host-apps-race: ## Build app
test -d apps && rm -r apps || true
mkdir -p ./apps
CGO_ENABLED=1${OPTS} go build ${BUILD_OPTS} -race -o $(BUILD_PATH)apps/ ./cmd/apps/...
# Bin
bin: fix-systray-vendor bin-fix unfix-systray-vendor
bin-fix: ## Build `skywire-visor`, `skywire-cli`
${OPTS} go build ${BUILD_OPTS} -o $(BUILD_PATH) ./cmd/skywire-visor ./cmd/skywire-cli ./cmd/setup-node
fix-systray-vendor:
@if [ $(UNAME_S) = "Linux" ]; then\
sed -i '/go conn.handleCall(msg)/c\conn.handleCall(msg)' ./vendor/github.com/godbus/dbus/v5/conn.go ;\
fi
unfix-systray-vendor:
@if [ $(UNAME_S) = "Linux" ]; then\
sed -i '/conn.handleCall(msg)/c\ go conn.handleCall(msg)' ./vendor/github.com/godbus/dbus/v5/conn.go ;\
fi
bin-windows: ## Build `skywire-visor`, `skywire-cli`
powershell 'Get-ChildItem .\cmd | % { ${OPTS} go build ${BUILD_OPTS} -o $(BUILD_PATH) $$_.FullName }'
# Static Bin
bin-static: ## Build `skywire-visor`, `skywire-cli`
${STATIC_OPTS} go build 8 -trimpath --ldflags '-linkmode external -extldflags "-static" -buildid=' -o $(BUILD_PATH) ./cmd/skywire-visor ./cmd/skywire-cli ./cmd/setup-node
# Static Bin without Systray
bin-static-wos: ## Build `skywire-visor`, `skywire-cli`
${STATIC_OPTS} go build -tags withoutsystray -trimpath --ldflags '-linkmode external -extldflags "-static" -buildid=' -o $(BUILD_PATH)skywire-visor ./cmd/skywire-visor
${STATIC_OPTS} go build -trimpath --ldflags '-linkmode external -extldflags "-static" -buildid=' -o $(BUILD_PATH) ./cmd/skywire-cli ./cmd/setup-node
build-deploy: host-apps-deploy ## Build for deployment Docker images
${OPTS} go build -tags netgo ${BUILD_OPTS_DEPLOY} -o /release/skywire-visor ./cmd/skywire-visor
${OPTS} go build ${BUILD_OPTS_DEPLOY} -o /release/skywire-cli ./cmd/skywire-cli
build-race: host-apps-race ## Build for testing Docker images
CGO_ENABLED=1 ${OPTS} go build -tags netgo ${BUILD_OPTS} -race -o /release/skywire-visor ./cmd/skywire-visor
CGO_ENABLED=1 ${OPTS} go build ${BUILD_OPTS} -race -o /release/skywire-cli ./cmd/skywire-cli
github-prepare-release:
$(eval GITHUB_TAG=$(shell git describe --abbrev=0 --tags | cut -c 2-6))
sed '/^## ${GITHUB_TAG}$$/,/^## .*/!d;//d;/^$$/d' ./CHANGELOG.md > releaseChangelog.md
github-release: github-prepare-release
goreleaser --rm-dist --config .goreleaser-linux.yml --release-notes releaseChangelog.md
github-release-archlinux: github-prepare-release
goreleaser --rm-dist --config .goreleaser-archlinux.yml --release-notes releaseChangelog.md
github-release-darwin:
goreleaser --rm-dist --config .goreleaser-darwin.yml --skip-publish
$(eval GITHUB_TAG=$(shell git describe --abbrev=0 --tags))
gh release upload --repo skycoin/skywire ${GITHUB_TAG} ./dist/skywire-${GITHUB_TAG}-darwin-amd64.tar.gz
gh release upload --repo skycoin/skywire ${GITHUB_TAG} ./dist/skywire-${GITHUB_TAG}-darwin-arm64.tar.gz
gh release download ${GITHUB_TAG} --repo skycoin/skywire --pattern 'checksums*'
cat ./dist/checksums.txt >> ./checksums.txt
gh release upload --repo skycoin/skywire ${GITHUB_TAG} --clobber ./checksums.txt
github-release-windows:
.\goreleaser\goreleaser.exe --rm-dist --config .goreleaser-windows.yml --skip-publish
$(eval GITHUB_TAG=$(shell powershell git describe --abbrev=0 --tags))
gh release upload --repo skycoin/skywire ${GITHUB_TAG} ./dist/skywire-${GITHUB_TAG}-windows-amd64.zip
gh release upload --repo skycoin/skywire ${GITHUB_TAG} ./dist/skywire-${GITHUB_TAG}-windows-386.zip
gh release download ${GITHUB_TAG} --repo skycoin/skywire --pattern 'checksums*'
cat ./dist/checksums.txt >> ./checksums.txt
gh release upload --repo skycoin/skywire ${GITHUB_TAG} --clobber ./checksums.txt
dep-github-release:
mkdir musl-data
wget -c https://more.musl.cc/10/x86_64-linux-musl/aarch64-linux-musl-cross.tgz -O aarch64-linux-musl-cross.tgz
tar -xzf aarch64-linux-musl-cross.tgz -C ./musl-data && rm aarch64-linux-musl-cross.tgz
wget -c https://more.musl.cc/10/x86_64-linux-musl/arm-linux-musleabi-cross.tgz -O arm-linux-musleabi-cross.tgz
tar -xzf arm-linux-musleabi-cross.tgz -C ./musl-data && rm arm-linux-musleabi-cross.tgz
wget -c https://more.musl.cc/10/x86_64-linux-musl/arm-linux-musleabihf-cross.tgz -O arm-linux-musleabihf-cross.tgz
tar -xzf arm-linux-musleabihf-cross.tgz -C ./musl-data && rm arm-linux-musleabihf-cross.tgz
wget -c https://more.musl.cc/10/x86_64-linux-musl/x86_64-linux-musl-cross.tgz -O x86_64-linux-musl-cross.tgz
tar -xzf x86_64-linux-musl-cross.tgz -C ./musl-data && rm x86_64-linux-musl-cross.tgz
wget -c https://more.musl.cc/10/x86_64-linux-musl/riscv64-linux-musl-cross.tgz -O riscv64-linux-musl-cross.tgz
tar -xzf riscv64-linux-musl-cross.tgz -C ./musl-data && rm riscv64-linux-musl-cross.tgz
build-docker: ## Build docker image
./ci_scripts/docker-push.sh -t latest -b
# Manager UI
install-deps-ui: ## Install the UI dependencies
cd $(MANAGER_UI_DIR) && npm ci
config: ## Create or regenerate a config with correct default app bin_path for `make build`
$(BUILD_PATH)skywire-cli config gen -irx --binpath $(BUILD_PATH)apps
run: ## Run skywire visor with skywire-config.json, and start a browser if running a hypervisor
$(BUILD_PATH)skywire-visor -bc ./skywire-config.json
## Prepare to run skywire from source, without compiling binaries
prepare:
test -d apps && rm -r apps || true
mkdir -p apps
ln ./scripts/_apps/skychat ./apps/
ln ./scripts/_apps/skysocks ./apps/
ln ./scripts/_apps/skysocks-client ./apps/
ln ./scripts/_apps/vpn-server ./apps/
ln ./scripts/_apps/vpn-client ./apps/
chmod +x ./apps/*
sudo echo "sudo cache"
run-source: prepare ## Run skywire from source, without compiling binaries
go run ./cmd/skywire-cli/skywire-cli.go config gen -in | sudo go run ./cmd/skywire-visor/skywire-visor.go -n || true
run-systray: prepare ## Run skywire from source, with vpn server enabled
go run ./cmd/skywire-cli/skywire-cli.go config gen -ni | sudo go run ./cmd/skywire-visor/skywire-visor.go -n --systray || true
run-vpnsrv: prepare ## Run skywire from source, without compiling binaries
go run ./cmd/skywire-cli/skywire-cli.go config gen -in --servevpn | sudo go run ./cmd/skywire-visor/skywire-visor.go -n || true
run-source-test: prepare ## Run skywire from source with test endpoints
go run ./cmd/skywire-cli/skywire-cli.go config gen -nit | sudo go run ./cmd/skywire-visor/skywire-visor.go -n || true
run-vpnsrv-test: prepare ## Run skywire from source, with vpn server enabled
go run ./cmd/skywire-cli/skywire-cli.go config gen -nit --servevpn | sudo go run ./cmd/skywire-visor/skywire-visor.go -n || true
run-systray-test: prepare ## Run skywire from source, with vpn server enabled
go run ./cmd/skywire-cli/skywire-cli.go config gen -nit | sudo go run ./cmd/skywire-visor/skywire-visor.go --systray -n || true
run-source-dmsghttp: prepare ## Run skywire from source with dmsghttp config
go run ./cmd/skywire-cli/skywire-cli.go config gen -din | sudo go run ./cmd/skywire-visor/skywire-visor.go -n || true
run-vpnsrv-dmsghttp: prepare ## Run skywire from source with dmsghttp config and vpn server
go run ./cmd/skywire-cli/skywire-cli.go config gen -din --servevpn | sudo go run ./cmd/skywire-visor/skywire-visor.go -n || true
run-source-dmsghttp-test: prepare ## Run skywire from source with dmsghttp config and test endpoints
go run ./cmd/skywire-cli/skywire-cli.go config gen -dint | sudo go run ./cmd/skywire-visor/skywire-visor.go -n || true
run-vpnsrv-dmsghttp-test: prepare ## Run skywire from source with dmsghttp config, vpn server, and test endpoints
go run ./cmd/skywire-cli/skywire-cli.go config gen -dint --servevpn | sudo go run ./cmd/skywire-visor/skywire-visor.go -n || true
lint-ui: ## Lint the UI code
cd $(MANAGER_UI_DIR) && npm run lint
build-ui: install-deps-ui ## Builds the UI
cd $(MANAGER_UI_DIR) && npm run build
mkdir -p ${PWD}/bin
rm -rf ${MANAGER_UI_BUILT_DIR}
mkdir ${MANAGER_UI_BUILT_DIR}
cp -r ${MANAGER_UI_DIR}/dist/. ${MANAGER_UI_BUILT_DIR}
build-ui-windows: install-deps-ui ## Builds the UI on windows
cd $(MANAGER_UI_DIR) && npm run build
powershell 'Remove-Item -Recurse -Force -Path ${MANAGER_UI_BUILT_DIR}'
powershell 'New-Item -Path ${MANAGER_UI_BUILT_DIR} -ItemType Directory'
powershell 'Copy-Item -Recurse ${MANAGER_UI_DIR}\dist\* ${MANAGER_UI_BUILT_DIR}'
mac-installer: ## Create unsigned and not-notarized application, run make mac-installer-help for more
./scripts/mac_installer/create_installer.sh
mac-installer-help: ## Show installer creation help
./scripts/mac_installer/create_installer.sh -h
mac-installer-release: mac-installer ## Upload created signed and notarized applciation to github
$(eval GITHUB_TAG=$(shell git describe --abbrev=0 --tags))
gh release upload --repo skycoin/skywire ${GITHUB_TAG} ./skywire-installer-${GITHUB_TAG}-darwin-amd64.pkg
gh release upload --repo skycoin/skywire ${GITHUB_TAG} ./skywire-installer-${GITHUB_TAG}-darwin-arm64.pkg
win-installer-latest: ## Build the windows .msi (installer) latest version
@powershell '.\scripts\win_installer\script.ps1 latest'
win-installer: ## Build the windows .msi (installer) custom version
@powershell '.\scripts\win_installer\script.ps1 $(CUSTOM_VERSION)'
windows-installer-release:
$(eval GITHUB_TAG=$(shell git describe --abbrev=0 --tags))
make win-installer CUSTOM_VERSION=$(GITHUB_TAG)
gh release upload --repo skycoin/skywire ${GITHUB_TAG} ./skywire-installer-${GITHUB_TAG}-windows-amd64.msi
gh release upload --repo skycoin/skywire ${GITHUB_TAG} ./skywire-installer-${GITHUB_TAG}-windows-386.msi
help: ## `make help` menu
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
help-windows: ## Display help for windows
@powershell 'Select-String -Pattern "windows[a-zA-Z_-]*:.*## .*$$" $(MAKEFILE_LIST) | % { $$_.Line -split ":.*?## " -Join "`t:`t" } '