This repository was archived by the owner on Jul 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
121 lines (101 loc) · 4.06 KB
/
Makefile
File metadata and controls
121 lines (101 loc) · 4.06 KB
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
.PHONY: build proto
default: help
VERSION_TAG=0.1.0
BINARY_NAME=ct19
DOCKER_IMAGE_NAME=ct19
CI_REPO=bryk-io/ct19
# Linker tags
# https://golang.org/cmd/link/
LD_FLAGS += -s -w
LD_FLAGS += -X go.bryk.io/covid-tracking/cmd.coreVersion=$(VERSION_TAG)
LD_FLAGS += -X go.bryk.io/covid-tracking/cmd.buildTimestamp=$(shell date +'%s')
LD_FLAGS += -X go.bryk.io/covid-tracking/cmd.buildCode=$(shell git log --pretty=format:'%H' -n1)
## help: Prints this help message
help:
@echo "Commands available"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' | sort
## clean: Download and compile all dependencies and intermediary products
clean:
@-rm -rf vendor
go mod tidy
go mod verify
go mod download
go mod vendor
## updates: List available updates for direct dependencies
# https://github.com/golang/go/wiki/Modules#how-to-upgrade-and-downgrade-dependencies
updates:
@go list -mod=readonly -u -f '{{if (and (not (or .Main .Indirect)) .Update)}}{{.Path}}: {{.Version}} -> {{.Update.Version}}{{end}}' -m all 2> /dev/null
## scan: Look for knonwn vulnerabilities in the project dependencies
# https://github.com/sonatype-nexus-community/nancy
scan:
@nancy -quiet go.sum
## lint: Static analysis
lint:
# helm lint helm/*
golangci-lint run -v ./...
## test: Run unit tests excluding the vendor dependencies
test:
go test -race -cover -v -failfast ./...
## ca-roots: Generate the list of valid CA certificates
ca-roots:
@docker run -dit --rm --name ca-roots debian:stable-slim
@docker exec --privileged ca-roots sh -c "apt update"
@docker exec --privileged ca-roots sh -c "apt install -y ca-certificates"
@docker exec --privileged ca-roots sh -c "cat /etc/ssl/certs/* > /ca-roots.crt"
@docker cp ca-roots:/ca-roots.crt ca-roots.crt
@docker stop ca-roots
## build: Build for the default architecture in use
build:
go build -v -ldflags '$(LD_FLAGS)' -o $(BINARY_NAME)
## mobile-module: Build the WebAssambly mobile module
# More information: https://github.com/golang/go/wiki/WebAssembly
mobile-module:
GOOS=js GOARCH=wasm go build -v -o ./mobile/testdata/ct19-lib.wasm ./mobile
## build-for: Build the availabe binaries for the specified 'os' and 'arch'
# make build-for os=linux arch=amd64
build-for:
CGO_ENABLED=0 GOOS=$(os) GOARCH=$(arch) \
go build -v -ldflags '$(LD_FLAGS)' \
-o $(BINARY_NAME)_$(os)_$(arch)$(suffix)
## install: Install the binary to GOPATH and keep cached all compiled artifacts
install:
@go build -v -ldflags '$(LD_FLAGS)' -i -o ${GOPATH}/bin/$(BINARY_NAME)
## docker: Build docker image
docker:
make build-for os=linux arch=amd64
@-docker rmi $(DOCKER_IMAGE_NAME):$(VERSION_TAG)
@docker build --build-arg VERSION="$(VERSION_TAG)" --rm -t $(DOCKER_IMAGE_NAME):$(VERSION_TAG) .
rm $(BINARY_NAME)_linux_amd64
## proto: Compile protocol buffers and RPC services
proto:
docker run --rm -t -v `pwd`:/workdir proto-builder:1.9.0 prototool lint proto/v1
docker run --rm -t -v `pwd`:/workdir proto-builder:1.9.0 prototool format -w -f proto/v1
docker run --rm -t -v `pwd`:/workdir proto-builder:1.9.0 prototool generate
docker run --rm -t -v `pwd`:/workdir proto-builder:1.9.0 prototool descriptor-set --include-imports --include-source-info -o proto/v1/descriptor.bin proto
# Fix gRPC-Gateway generated code
# https://github.com/grpc-ecosystem/grpc-gateway/issues/229
@-sed -i '' "s/empty.Empty/types.Empty/g" proto/v1/*.pb.gw.go
# Remove comment added by the gateway generator to avoid polluting
# the package documentation
@-sed -i '' '/\/\*/,/*\//d' proto/v1/*.pb.gw.go
# Remove empty files generated by protoc-gen-go-json
for ff in proto/v1/*.pb.json.go; do \
if [ `grep -c '' $$ff` -le 11 ];then \
rm $$ff; \
fi \
done
# Fix inconsistent output from protoc-gen-govalidators
gofmt -w proto/v1/*.validator.pb.go
## ci-update: Update the signature on the CI configuration file
ci-update:
drone sign $(CI_REPO) --save
## ci-run: Run a local CI test
ci-run:
drone exec \
--pipeline="Continuous Integration" \
--secret-file tmp/secrets.txt \
--repo $(CI_REPO) \
--branch master \
--event push \
--exclude "Report result"
@-rm -f key