This repository has been archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
199 lines (173 loc) · 7.91 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
GO_VERSION ?= 1.15.7
GOOS ?= linux
GOARCH ?= amd64
GOPATH ?= $(shell go env GOPATH)
COMPOSE_PROJECT_NAME := ${TAG}-$(shell git rev-parse --abbrev-ref HEAD)
BRANCH_NAME ?= $(shell git rev-parse --abbrev-ref HEAD | sed "s!/!-!g")
ifeq (${BRANCH_NAME},main)
TAG := $(shell git rev-parse --short HEAD)-go${GO_VERSION}
TRACKED_BRANCH := true
LATEST_TAG := latest
else
TAG := $(shell git rev-parse --short HEAD)-${BRANCH_NAME}-go${GO_VERSION}
ifneq (,$(findstring release-,$(BRANCH_NAME)))
TRACKED_BRANCH := true
LATEST_TAG := ${BRANCH_NAME}-latest
endif
endif
CUSTOMTAG ?=
FILEEXT :=
ifeq (${GOOS},windows)
FILEEXT := .exe
endif
DOCKER_BUILD := docker build \
--build-arg TAG=${TAG}
.DEFAULT_GOAL := help
.PHONY: help
help:
@awk 'BEGIN { \
FS = ":.*##"; \
printf "\nUsage:\n make \033[36m<target>\033[0m\n"\
} \
/^[a-zA-Z_-]+:.*?##/ { \
printf " \033[36m%-17s\033[0m %s\n", $$1, $$2 \
} \
/^##@/ { \
printf "\n\033[1m%s\033[0m\n", substr($$0, 5) \
} ' $(MAKEFILE_LIST)
##@ Dependencies
.PHONY: build-dev-deps
build-dev-deps: ## Install dependencies for builds
go get golang.org/x/tools/cover
go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
.PHONY: lint
lint: ## Analyze and find programs in source code
@echo "Running ${@}"
@golangci-lint run
.PHONY: goimports-fix
goimports-fix: ## Applies goimports to every go file (excluding vendored files)
goimports -w -local storj.io $$(find . -type f -name '*.go' -not -path "*/vendor/*")
.PHONY: goimports-st
goimports-st: ## Applies goimports to every go file in `git status` (ignores untracked files)
@git status --porcelain -uno|grep .go|grep -v "^D"|sed -E 's,\w+\s+(.+->\s+)?,,g'|xargs -I {} goimports -w -local storj.io {}
.PHONY: build-packages
build-packages: build-packages-normal build-packages-race ## Test docker images locally
build-packages-normal:
go build -v ./...
build-packages-race:
go build -v -race ./...
##@ Test
.PHONY: test
test: ## Run tests on source code (jenkins)
go test -race -v -cover -coverprofile=.coverprofile ./...
@echo done
##@ Build
.PHONY: images
images: linksharing-image ## Build linksharing Docker images
echo Built version: ${TAG}
.PHONY: linksharing-image
linksharing-image: linksharing_linux_arm64 linksharing_linux_amd64 ## Build linksharing Docker image
${DOCKER_BUILD} --pull=true -t storjlabs/linksharing:${TAG}-amd64 \
-f Dockerfile .
${DOCKER_BUILD} --pull=true -t storjlabs/linksharing:${TAG}-arm32v6 \
--build-arg=GOARCH=arm --build-arg=DOCKER_ARCH=arm32v6 \
-f Dockerfile .
${DOCKER_BUILD} --pull=true -t storjlabs/linksharing:${TAG}-aarch64 \
--build-arg=GOARCH=arm64 --build-arg=DOCKER_ARCH=aarch64 \
-f Dockerfile .
.PHONY: binary
binary: CUSTOMTAG = -${GOOS}-${GOARCH}
binary:
@if [ -z "${COMPONENT}" ]; then echo "Try one of the following targets instead:" \
&& for b in binaries ${BINARIES}; do echo "- $$b"; done && exit 1; fi
mkdir -p release/${TAG}
mkdir -p /tmp/go-cache /tmp/go-pkg
rm -f private/cmd/resource.syso
if [ "${GOARCH}" = "amd64" ]; then sixtyfour="-64"; fi; \
[ "${GOOS}" = "windows" ] && [ "${GOARCH}" = "amd64" ] && goversioninfo $$sixtyfour -o private/cmd/resource.syso \
-original-name ${COMPONENT}_${GOOS}_${GOARCH}${FILEEXT} \
-description "${COMPONENT} program for Storj" \
-product-ver-major "$(shell git describe --tags --exact-match --match "v[0-9]*\.[0-9]*\.[0-9]*" | awk -F'.' 'BEGIN {v=0} {gsub("v", "", $$0); v=$$1} END {print v}' )" \
-ver-major "$(shell git describe --tags --exact-match --match "v[0-9]*\.[0-9]*\.[0-9]*" | awk -F'.' 'BEGIN {v=0} {gsub("v", "", $$0); v=$$1} END {print v}' )" \
-product-ver-minor "$(shell git describe --tags --exact-match --match "v[0-9]*\.[0-9]*\.[0-9]*" | awk -F'.' 'BEGIN {v=0} {v=$$2} END {print v}')" \
-ver-minor "$(shell git describe --tags --exact-match --match "v[0-9]*\.[0-9]*\.[0-9]*" | awk -F'.' 'BEGIN {v=0} {v=$$2} END {print v}')" \
-product-ver-patch "$(shell git describe --tags --exact-match --match "v[0-9]*\.[0-9]*\.[0-9]*" | awk -F'.' 'BEGIN {v=0} {v=$$3} END {print v}' | awk -F'-' 'BEGIN {v=0} {v=$$1} END {print v}')" \
-ver-patch "$(shell git describe --tags --exact-match --match "v[0-9]*\.[0-9]*\.[0-9]*" | awk -F'.' 'BEGIN {v=0} {v=$$3} END {print v}' | awk -F'-' 'BEGIN {v=0} {v=$$1} END {print v}')" \
-product-version "$(shell git describe --tags --exact-match --match "v[0-9]*\.[0-9]*\.[0-9]*" | awk -F'-' 'BEGIN {v=0} {v=$$1} END {print v}' || echo "dev" )" \
-special-build "$(shell git describe --tags --exact-match --match "v[0-9]*\.[0-9]*\.[0-9]*" | awk -F'-' 'BEGIN {v=0} {v=$$2} END {print v}' )" \
resources/versioninfo.json || echo "goversioninfo is not installed, metadata will not be created"
docker run --rm -i -v "${PWD}":/go/src/storj.io/storj -e GO111MODULE=on \
-e GOOS=${GOOS} -e GOARCH=${GOARCH} -e GOARM=6 -e CGO_ENABLED=1 \
-v /tmp/go-cache:/tmp/.cache/go-build -v /tmp/go-pkg:/go/pkg \
-w /go/src/storj.io/storj -e GOPROXY -u $(shell id -u):$(shell id -g) storjlabs/golang:${GO_VERSION} \
scripts/release.sh build $(EXTRA_ARGS) -o release/${TAG}/$(COMPONENT)_${GOOS}_${GOARCH}${FILEEXT} ./cmd/linksharing
chmod 755 release/${TAG}/$(COMPONENT)_${GOOS}_${GOARCH}${FILEEXT}
[ "${FILEEXT}" = ".exe" ] && storj-sign release/${TAG}/$(COMPONENT)_${GOOS}_${GOARCH}${FILEEXT} || echo "Skipping signing"
rm -f release/${TAG}/${COMPONENT}_${GOOS}_${GOARCH}.zip
.PHONY: binary-check
binary-check:
@if [ -f release/${TAG}/${COMPONENT}_${GOOS}_${GOARCH} ] || [ -f release/${TAG}/${COMPONENT}_${GOOS}_${GOARCH}.exe ]; \
then \
echo "release/${TAG}/${COMPONENT}_${GOOS}_${GOARCH} exists"; \
else \
echo "Making ${COMPONENT}"; \
$(MAKE) binary; \
fi
.PHONY: linksharing_%
linksharing_%:
$(MAKE) binary-check COMPONENT=linksharing GOARCH=$(word 3, $(subst _, ,$@)) GOOS=$(word 2, $(subst _, ,$@))
COMPONENTLIST := linksharing
OSARCHLIST := darwin_amd64 linux_amd64 linux_arm linux_arm64 windows_amd64 freebsd_amd64
BINARIES := $(foreach C,$(COMPONENTLIST),$(foreach O,$(OSARCHLIST),$C_$O))
.PHONY: binaries
binaries: ${BINARIES} ## Build linksharing binaries (jenkins)
##@ Deploy
.PHONY: push-images
push-images: ## Push Docker images to Docker Hub (jenkins)
# images have to be pushed before a manifest can be created
for c in linksharing; do \
docker push storjlabs/$$c:${TAG}-amd64 \
&& docker push storjlabs/$$c:${TAG}-arm32v6 \
&& docker push storjlabs/$$c:${TAG}-aarch64 \
&& for t in ${TAG} ${LATEST_TAG}; do \
docker manifest create storjlabs/$$c:$$t \
storjlabs/$$c:${TAG}-amd64 \
storjlabs/$$c:${TAG}-arm32v6 \
storjlabs/$$c:${TAG}-aarch64 \
&& docker manifest annotate storjlabs/$$c:$$t storjlabs/$$c:${TAG}-amd64 --os linux --arch amd64 \
&& docker manifest annotate storjlabs/$$c:$$t storjlabs/$$c:${TAG}-arm32v6 --os linux --arch arm --variant v6 \
&& docker manifest annotate storjlabs/$$c:$$t storjlabs/$$c:${TAG}-aarch64 --os linux --arch arm64 \
&& docker manifest push --purge storjlabs/$$c:$$t \
; done \
; done
.PHONY: binaries-upload
binaries-upload: ## Upload binaries to Google Storage (jenkins)
cd "release/${TAG}"; for f in *; do \
c="$${f%%_*}" \
&& if [ "$${f##*.}" != "$${f}" ]; then \
ln -s "$${f}" "$${f%%_*}.$${f##*.}" \
&& zip "$${f}.zip" "$${f%%_*}.$${f##*.}" \
&& rm "$${f%%_*}.$${f##*.}" \
; else \
ln -sf "$${f}" "$${f%%_*}" \
&& zip "$${f}.zip" "$${f%%_*}" \
&& rm "$${f%%_*}" \
; fi \
; done
cd "release/${TAG}"; gsutil -m cp -r *.zip "gs://storj-v3-alpha-builds/${TAG}/"
##@ Clean
.PHONY: clean
clean: binaries-clean clean-images ## Clean local release binaries, and local Docker images
.PHONY: binaries-clean
binaries-clean: ## Remove all local release binaries (jenkins)
rm -rf release
.PHONY: clean-images
clean-images:
-docker rmi storjlabs/linksharing:${TAG}
.PHONY: bump-dependencies
bump-dependencies:
go get storj.io/common@main storj.io/private@main storj.io/uplink@main
go mod tidy
cd testsuite;\
go get storj.io/common@main storj.io/storj@main;\
go mod tidy