-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
212 lines (175 loc) · 6.77 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
################################################################################
## VERSION PARAMS ##
################################################################################
## Docker Build Versions
DOCKER_BUILD_IMAGE = golang:1.23
DOCKER_BASE_IMAGE = alpine:3.20
################################################################################
GO ?= $(shell command -v go 2> /dev/null)
ELROND_IMAGE_REPO ?=mattermost/elrond
ELROND_IMAGE ?= mattermost/elrond:test
APP := elrond
MACHINE = $(shell uname -m)
GOFLAGS ?= $(GOFLAGS:)
BUILD_TIME := $(shell date -u +%Y%m%d.%H%M%S)
BUILD_HASH := $(shell git rev-parse HEAD)
################################################################################
LOGRUS_URL := github.com/sirupsen/logrus
LOGRUS_VERSION := $(shell find go.mod -type f -exec cat {} + | grep ${LOGRUS_URL} | awk '{print $$NF}')
LOGRUS_PATH := $(GOPATH)/pkg/mod/${LOGRUS_URL}\@${LOGRUS_VERSION}
TOOLS_BIN_DIR := $(abspath bin)
# Tools
GOLANGCILINT_VER := v1.61.0
GOLANGCILINT := $(TOOLS_BIN_DIR)/$(GOLANGCILINT_BIN)
OUTDATED_VER := master
OUTDATED_BIN := go-mod-outdated
OUTDATED_GEN := $(TOOLS_BIN_DIR)/$(OUTDATED_BIN)
export GO111MODULE=on
all: check-style dist
## Runs govet and gofmt against all packages.
.PHONY: check-style
check-style: govet lint goformat
@echo Checking for style guide compliance
## Runs lint against all packages.
lint: $(GOPATH)/bin/golangci-lint
@echo Running golangci-lint
golangci-lint run ./...
## Runs lint against all packages for changes only
lint-changes: $(GOPATH)/bin/golangci-lint
@echo Running golangci-lint over changes only
golangci-lint run -n
## Runs govet against all packages.
.PHONY: vet
govet:
@echo Running govet
$(GO) vet ./...
@echo Govet success
## Checks if files are formatted with go fmt.
.PHONY: goformat
goformat:
@echo Checking if code is formatted
@for package in $(PACKAGES); do \
echo "Checking "$$package; \
files=$$(go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}} {{end}}' $$package); \
if [ "$$files" ]; then \
gofmt_output=$$(gofmt -d -s $$files 2>&1); \
if [ "$$gofmt_output" ]; then \
echo "$$gofmt_output"; \
echo "gofmt failed"; \
echo "To fix it, run:"; \
echo "go fmt [FAILED_PACKAGE]"; \
exit 1; \
fi; \
fi; \
done
@echo "gofmt success"; \
## Builds and thats all :)
.PHONY: dist
dist: build
.PHONY: binaries
binaries: ## Build binaries of elrond
@echo Building binaries of elrond
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO) build -gcflags all=-trimpath=$(PWD) -asmflags all=-trimpath=$(PWD) -a -installsuffix cgo -o build/_output/bin/elrond-linux-amd64 ./cmd/$(APP)
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 $(GO) build -gcflags all=-trimpath=$(PWD) -asmflags all=-trimpath=$(PWD) -a -installsuffix cgo -o build/_output/bin/elrond-darwin-amd64 ./cmd/$(APP)
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GO) build -gcflags all=-trimpath=$(PWD) -asmflags all=-trimpath=$(PWD) -a -installsuffix cgo -o build/_output/bin/elrond-linux-arm64 ./cmd/$(APP)
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 $(GO) build -gcflags all=-trimpath=$(PWD) -asmflags all=-trimpath=$(PWD) -a -installsuffix cgo -o build/_output/bin/elrond-darwin-arm64 ./cmd/$(APP)
.PHONY: build
build: ## Build the elrond
@echo Building Elrond for ARCH=$(ARCH)
@if [ "$(ARCH)" = "amd64" ]; then \
export GOARCH="amd64"; \
elif [ "$(ARCH)" = "arm64" ]; then \
export GOARCH="arm64"; \
elif [ "$(ARCH)" = "arm" ]; then \
export GOARCH="arm"; \
else \
echo "Unknown architecture $(ARCH)"; \
exit 1; \
fi; \
GOOS=linux CGO_ENABLED=0 $(GO) build -buildvcs=false -ldflags '$(LDFLAGS)' -gcflags all=-trimpath=$(PWD) -asmflags all=-trimpath=$(PWD) -a -installsuffix cgo -o ./build/_output/bin/elrond ./cmd/$(APP)
.PHONY: build-image
build-image: ## Build the docker image for Elrond
@echo Building Elrond Docker Image
@if [ -z "$(DOCKER_USERNAME)" ] || [ -z "$(DOCKER_PASSWORD)" ]; then \
echo "DOCKER_USERNAME and/or DOCKER_PASSWORD not set. Skipping Docker login."; \
else \
echo $(DOCKER_PASSWORD) | docker login --username $(DOCKER_USERNAME) --password-stdin; \
fi
docker buildx build \
--platform linux/arm64,linux/amd64 \
--build-arg DOCKER_BUILD_IMAGE=$(DOCKER_BUILD_IMAGE) \
--build-arg DOCKER_BASE_IMAGE=$(DOCKER_BASE_IMAGE) \
. -f build/Dockerfile -t $(ELROND_IMAGE) \
--no-cache \
--push
.PHONY: build-image-with-tag
build-image-with-tag: ## Build the docker image for elrond
@echo Building Elrond Docker Image
@if [ -z "$(DOCKER_USERNAME)" ] || [ -z "$(DOCKER_PASSWORD)" ]; then \
echo "DOCKER_USERNAME and/or DOCKER_PASSWORD not set. Skipping Docker login."; \
else \
echo $(DOCKER_PASSWORD) | docker login --username $(DOCKER_USERNAME) --password-stdin; \
fi
: $${TAG:?}
docker buildx build \
--platform linux/arm64,linux/amd64 \
--build-arg DOCKER_BUILD_IMAGE=$(DOCKER_BUILD_IMAGE) \
--build-arg DOCKER_BASE_IMAGE=$(DOCKER_BASE_IMAGE) \
. -f build/Dockerfile -t $(ELROND_IMAGE) -t $(ELROND_IMAGE_REPO):${TAG} \
--push
.PHONY: build-image-locally
build-image-locally: ## Build the docker image for Elrond
@echo Building Elrond Docker Image
@if [ -z "$(DOCKER_USERNAME)" ] || [ -z "$(DOCKER_PASSWORD)" ]; then \
echo "DOCKER_USERNAME and/or DOCKER_PASSWORD not set. Skipping Docker login."; \
else \
echo $(DOCKER_PASSWORD) | docker login --username $(DOCKER_USERNAME) --password-stdin; \
fi
docker buildx build \
--platform linux/arm64 \
--build-arg DOCKER_BUILD_IMAGE=$(DOCKER_BUILD_IMAGE) \
--build-arg DOCKER_BASE_IMAGE=$(DOCKER_BASE_IMAGE) \
. -f build/Dockerfile -t $(ELROND_IMAGE) \
--no-cache \
--load
.PHONY: scan
scan:
docker scout cves $(ELROND_IMAGE)
.PHONY: push-image-pr
push-image-pr:
@echo Push Image PR
./scripts/push-image-pr.sh
.PHONY: push-image
push-image:
@echo Push Image
./scripts/push-image.sh
.PHONY: install
install: build
go install ./...
.PHONY: release
release:
@echo Cut a release
./scripts/release.sh
.PHONY: deps
deps:
apt-get update && apt-get install -y hub git
go install k8s.io/release/cmd/release-notes@latest
.PHONY: unittest
unittest:
$(GO) test ./... -v -covermode=count -coverprofile=coverage.out
.PHONY: check-modules
check-modules: $(OUTDATED_GEN) ## Check outdated modules
@echo Checking outdated modules
$(GO) list -mod=mod -u -m -json all | $(OUTDATED_GEN) -update -direct
.PHONY: update-modules
update-modules: $(OUTDATED_GEN) ## Check outdated modules
@echo Update modules
$(GO) get -u ./...
$(GO) mod tidy
## --------------------------------------
## Tooling Binaries
## --------------------------------------
$(GOPATH)/bin/golangci-lint: ## Install golangci-lint
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VER)
$(OUTDATED_GEN): ## Build go-mod-outdated.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/psampaz/go-mod-outdated $(OUTDATED_BIN) $(OUTDATED_VER)