-
Notifications
You must be signed in to change notification settings - Fork 39
/
Makefile
76 lines (66 loc) · 3 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
DEPS = $(wildcard */*/*/*.go)
VERSION = $(shell git describe --always --dirty)
COMMIT_SHA1 = $(shell git rev-parse HEAD)
BUILD_DATE = $(shell date +%Y-%m-%d)
GO_VERSION = 1.14
all: lint vet test bivac
bivac: main.go $(DEPS)
GO111MODULE=on CGO_ENABLED=0 GOARCH=$(GOARCH) GOOS=$(GOOS) GOARM=$(GOARM) \
go build \
-a -ldflags="-s -X main.version=$(VERSION) -X main.buildDate=$(BUILD_DATE) -X main.commitSha1=$(COMMIT_SHA1)" \
-installsuffix cgo -o $@ $<
@if [ "${GOOS}" = "linux" ] && [ "${GOARCH}" = "amd64" ]; then strip $@; fi
release: clean
GO_VERSION=$(GO_VERSION) ./scripts/build-release.sh
docker-images: clean
@if [ -z "$(IMAGE_NAME)" ]; then echo "IMAGE_NAME cannot be empty."; exit 1; fi
export IMAGE_NAME=$(IMAGE_NAME)
# Linux/amd64
docker build --no-cache --pull -t $(IMAGE_NAME)-linux-amd64:$(IMAGE_VERSION) \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GOOS=linux --build-arg GOARCH=amd64 .
docker push $(IMAGE_NAME)-linux-amd64:$(IMAGE_VERSION)
# Linux/386
docker build --no-cache --pull -t $(IMAGE_NAME)-linux-386:$(IMAGE_VERSION) \
--build-arg GO_VERSION=${GO_VERSION} \
--build-arg GOOS=linux --build-arg GOARCH=386 .
docker push $(IMAGE_NAME)-linux-386:$(IMAGE_VERSION)
# Linux/arm
docker build --no-cache --pull -t $(IMAGE_NAME)-linux-arm:$(IMAGE_VERSION) \
--build-arg GO_VERSION=${GO_VERSION} \
--build-arg GOOS=linux --build-arg GOARCH=arm --build-arg GOARM=7 .
docker push $(IMAGE_NAME)-linux-arm:$(IMAGE_VERSION)
# Linux/arm64
docker build --no-cache --pull -t $(IMAGE_NAME)-linux-arm64:$(IMAGE_VERSION) \
--build-arg GO_VERSION=${GO_VERSION} \
--build-arg GOOS=linux --build-arg GOARCH=arm64 --build-arg GOARM=7 .
docker push $(IMAGE_NAME)-linux-arm64:$(IMAGE_VERSION)
# Manifest
docker manifest create $(IMAGE_NAME):$(IMAGE_VERSION) \
$(IMAGE_NAME)-linux-amd64:$(IMAGE_VERSION) \
$(IMAGE_NAME)-linux-386:$(IMAGE_VERSION) \
$(IMAGE_NAME)-linux-arm:$(IMAGE_VERSION) \
$(IMAGE_NAME)-linux-arm64:$(IMAGE_VERSION)
docker manifest annotate $(IMAGE_NAME):$(IMAGE_VERSION) \
$(IMAGE_NAME)-linux-amd64:$(IMAGE_VERSION) --os linux --arch amd64
docker manifest annotate $(IMAGE_NAME):$(IMAGE_VERSION) \
$(IMAGE_NAME)-linux-386:$(IMAGE_VERSION) --os linux --arch 386
docker manifest annotate $(IMAGE_NAME):$(IMAGE_VERSION) \
$(IMAGE_NAME)-linux-arm:$(IMAGE_VERSION) --os linux --arch arm
docker manifest annotate $(IMAGE_NAME):$(IMAGE_VERSION) \
$(IMAGE_NAME)-linux-arm64:$(IMAGE_VERSION) --os linux --arch arm64
docker manifest push $(IMAGE_NAME):$(IMAGE_VERSION)
lint:
@GO111MODULE=off go get -u -v golang.org/x/lint/golint
@for file in $$(go list ./... | grep -v '_workspace/' | grep -v 'vendor'); do \
export output="$$(golint $${file} | grep -v 'type name will be used as docker.DockerInfo')"; \
[ -n "$${output}" ] && echo "$${output}" && export status=1; \
done; \
exit $${status:-0}
vet: main.go
go vet $<
clean:
git clean -fXd -e \!vendor -e \!vendor/**/* && rm -f ./bivac
test:
go test -cover -coverprofile=coverage -v ./...
.PHONY: all lint vet clean test