This repository has been archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
152 lines (126 loc) · 4.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
.PHONY: *
.DEFAULT_GOAL:=help
# Project setup
BINARY_NAME=dlt4eu
OWNER=bryk-io
REPO=dlt4eu
PROJECT_REPO=github.com/$(OWNER)/$(REPO)
DOCKER_IMAGE=ghcr.io/$(OWNER)/$(BINARY_NAME)
MAINTAINERS='Ben Cessa <[email protected]>'
# State values
GIT_COMMIT_DATE=$(shell TZ=UTC git log -n1 --pretty=format:'%cd' --date='format-local:%Y-%m-%dT%H:%M:%SZ')
GIT_COMMIT_HASH=$(shell git log -n1 --pretty=format:'%H')
GIT_TAG=$(shell git describe --tags --always --abbrev=0 | cut -c 1-7)
# Linker tags
# https://golang.org/cmd/link/
LD_FLAGS += -s -w
LD_FLAGS += -X $(PROJECT_REPO)/cli/cmd.coreVersion=$(GIT_TAG:v%=%)
LD_FLAGS += -X $(PROJECT_REPO)/cli/cmd.buildTimestamp=$(GIT_COMMIT_DATE)
LD_FLAGS += -X $(PROJECT_REPO)/cli/cmd.buildCode=$(GIT_COMMIT_HASH)
# For commands that require a specific package path, default to all local
# subdirectories if no value is provided.
pkg?="..."
# Proto builder basic setup
proto-builder=docker run --rm -it -v $(shell pwd):/workdir ghcr.io/bryk-io/buf-builder:0.25.0
## help: Prints this help message
help:
@echo "Commands available"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' | sort
## bench: Run benchmarks
bench:
go test -run=XXX -bench=. ./$(pkg)
## build: Build for the current architecture in use, intended for development
build:
# Build CLI application
go build -v -ldflags '$(LD_FLAGS)' -o $(BINARY_NAME) ./cli
## build-for: Build the available 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) \
./cli
## 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
## clean: Download and compile all dependencies and intermediary products
clean:
@-rm -rf vendor
go clean
go mod tidy
go mod verify
go mod download
go mod vendor
## docker: Build docker image
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
docker:
make build-for os=linux arch=amd64
mv $(BINARY_NAME)_linux_amd64 $(BINARY_NAME)
@-docker rmi $(DOCKER_IMAGE):$(GIT_TAG:v%=%)
@docker build \
"--label=org.opencontainers.image.title=$(BINARY_NAME)" \
"--label=org.opencontainers.image.authors=$(MAINTAINERS)" \
"--label=org.opencontainers.image.created=$(GIT_COMMIT_DATE)" \
"--label=org.opencontainers.image.revision=$(GIT_COMMIT_HASH)" \
"--label=org.opencontainers.image.version=$(GIT_TAG:v%=%)" \
--rm -t $(DOCKER_IMAGE):$(GIT_TAG:v%=%) .
@rm $(BINARY_NAME)
## 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) ./cli
## graphql: Generate graphql schema
graphql:
gqlgen generate --verbose
## lint: Static analysis
lint:
# Code
golangci-lint run -v ./$(pkg)
# Helm charts
helm lint helm/*
## proto: Compile all PB definitions and RPC services
proto:
# Verify style and consistency
$(proto-builder) buf check lint --file $(shell echo proto/v1/*.proto | tr ' ' ',')
@-$(proto-builder) buf check breaking \
--file $(shell echo proto/v1/*.proto | tr ' ' ',') \
--against-input proto/v1/image.bin
# Clean old builds
@-rm proto/v1/image.bin
# Build package image
$(proto-builder) buf image build -o proto/v1/image.bin --file $(shell echo proto/v1/*.proto | tr ' ' ',')
# Build package code
$(proto-builder) buf protoc \
--proto_path=proto \
--go_out=proto \
--go-grpc_out=proto \
--grpc-gateway_out=logtostderr=true:proto \
--swagger_out=logtostderr=true:proto \
proto/v1/*.proto
# Remove package comment added by the gateway generator to avoid polluting
# the package documentation.
@-sed -i '' '/\/\*/,/*\//d' proto/v1/*.pb.gw.go
# Style adjustments
gofmt -s -w proto/v1
goimports -w proto/v1
## release: Prepare artifacts for a new tagged release
release:
goreleaser release --skip-validate --skip-publish --rm-dist
## scan: Look for known vulnerabilities in the project dependencies
# https://github.com/sonatype-nexus-community/nancy
scan:
@go list -f '{{if not .Indirect}}{{.}}{{end}}' -mod=mod -m all | nancy sleuth -o text
## test: Run all tests excluding the vendor dependencies
test:
# Unit tests
# -count=1 -p=1 (disable cache and parallel execution)
go test -race -v -failfast -coverprofile=coverage.report ./$(pkg)
go tool cover -html coverage.report -o coverage.html
## updates: List available updates for direct dependencies
# https://github.com/golang/go/wiki/Modules#how-to-upgrade-and-downgrade-dependencies
updates:
@go list -mod=mod -u -f '{{if (and (not (or .Main .Indirect)) .Update)}}{{.Path}}: {{.Version}} -> {{.Update.Version}}{{end}}' -m all 2> /dev/null