-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
189 lines (151 loc) · 7.86 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
# __
# .-----.-----.______.-----.----.-----.--.--.--.--.______.----.---.-.----| |--.-----.
# | _ | _ |______| _ | _| _ |_ _| | |______| __| _ | __| | -__|
# |___ |_____| | __|__| |_____|__.__|___ | |____|___._|____|__|__|_____|
# |_____| |__| |_____|
#
# Copyright (c) 2023 Fabio Cicerchia. https://fabiocicerchia.it. MIT License
# Repo: https://github.com/fabiocicerchia/go-proxy-cache
IS_LINUX=$(shell (ls -1 /etc/issue || true) | wc -l | awk '{$$1=$$1;print}')
.PHONY: test changelog staticcheck tlsfuzzer
.SILENT: help
default: help
################################################################################
# HELP
################################################################################
help: ## prints this help
echo " __"
echo " .-----.-----.______.-----.----.-----.--.--.--.--.______.----.---.-.----| |--.-----."
echo " | _ | _ |______| _ | _| _ |_ _| | |______| __| _ | __| | -__|"
echo " |___ |_____| | __|__| |_____|__.__|___ | |____|___._|____|__|__|_____|"
echo " |_____| |__| |_____|"
echo ""
echo "Copyright (c) 2023 Fabio Cicerchia. https://fabiocicerchia.it. MIT License"
echo "Repo: https://github.com/fabiocicerchia/go-proxy-cache"
echo ""
@gawk 'BEGIN { \
FS = ":.*##"; \
printf "Use: make \033[36m<target>\033[0m\n"; \
} /^\$$?\(?[a-zA-Z_-]+\)?:.*?##/ { \
printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 \
} /^##@/ { \
printf "\n\033[1m%s\033[0m\n", substr($$0, 5) \
}' $(MAKEFILE_LIST)
################################################################################
##@ BUILD
################################################################################
build: ## build
go build -o go-proxy-cache main.go
build-race: ## build-race
go build -race -o go-proxy-cache main.go
build-multiarch: ## build-multiarch
./bin/build-multiarch.sh
################################################################################
##@ SCA
################################################################################
sca: lint sec fmt staticcheck tlsfuzzer ## sca checks
lint: ## lint
docker run --rm -v $$PWD:/app -w /app golangci/golangci-lint:v1.51.0 golangci-lint run -v ./...
sec: ## security scan
curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh
./bin/gosec ./...
fmt: ## format code
gofmt -w -s .
staticcheck: ## staticcheck
ifeq ($(IS_LINUX),1)
wget -O staticcheck_amd64.tar.gz https://github.com/dominikh/go-tools/releases/download/2021.1.1/staticcheck_linux_amd64.tar.gz
else
wget -O staticcheck_amd64.tar.gz https://github.com/dominikh/go-tools/releases/download/2021.1.1/staticcheck_darwin_amd64.tar.gz
endif
tar xvzf staticcheck_amd64.tar.gz
chmod +x ./staticcheck/staticcheck
./staticcheck/staticcheck ./...
tlsfuzzer: ## tlsfuzzer
go run main.go &
echo "127.0.0.1 www.w3.org" | sudo tee -a /etc/hosts
pip3 install --pre tlslite-ng
git clone https://github.com/tlsfuzzer/tlsfuzzer
cd tlsfuzzer; \
git clone https://github.com/warner/python-ecdsa .python-ecdsa; \
ln -s .python-ecdsa/src/ecdsa/ ecdsa; \
git clone https://github.com/tlsfuzzer/tlslite-ng .tlslite-ng; \
ln -s .tlslite-ng/tlslite/ tlslite; \
PYTHONPATH=. python scripts/test-bleichenbacher-workaround.py -h www.w3.org -p 443
################################################################################
##@ TEST
################################################################################
test: test-unit test-functional test-endtoend test-ws test-http2 ## test
test-unit: ## test unit
TESTING=1 grc go test -v -race -count=1 --tags=unit ./...
test-functional: ## test functional
python3 -m http.server &> /dev/null &
TESTING=1 grc go test -v -race -count=1 --tags=functional ./...
pgrep python3 | xargs kill || true
test-endtoend: ## test endtoend
grc go test -v -race -count=1 --tags=endtoend ./...
test-ws: ## test websocket
cd test/full-setup/ws && npm install
node test/full-setup/ws/ws_client.js
# @DEPRECATED
test-http2: ## test HTTP2
nghttp -ans https://testing.local:50443/push
cover: ## coverage
python3 -m http.server &> /dev/null &
TESTING=1 grc go test -race -count=1 --tags=unit,functional -coverprofile c.out ./...
go tool cover -func=c.out
go tool cover -html=c.out -o cover.html
pgrep python3 | xargs kill || true
codeclimate: ## codeclimate
ifeq ($(IS_LINUX),1)
wget -O staticcheck_amd64.tar.gz https://github.com/dominikh/go-tools/releases/download/2021.1.1/staticcheck_linux_amd64.tar.gz
else
wget -O test-reporter https://codeclimate.com/downloads/test-reporter/test-reporter-latest-darwin-amd64 && chmod +x test-reporter
endif
# CODECLIMATE WORKAROUND
mkdir -p ./github.com/fabiocicerchia
ln -s $$PWD ./github.com/fabiocicerchia/go-proxy-cache
# / CODECLIMATE WORKAROUND
./test-reporter before-build
make cover
./test-reporter --debug after-build
codecov: ## codecov
curl -s https://codecov.io/bash | bash
################################################################################
##@ UTILITY
################################################################################
.install-changelog:
pip3 install gitchangelog pystache
changelog: .install-changelog ## generate a changelog
which gitchangelog || curl -sSL https://raw.githubusercontent.com/vaab/gitchangelog/master/src/gitchangelog/gitchangelog.py > /usr/local/bin/gitchangelog && chmod +x /usr/local/bin/gitchangelog
gitchangelog > CHANGELOG.md
cat CHANGELOG.md | awk 'BEGIN {RS=""}{gsub(/^\*/,"-")}1' | tee CHANGELOG.md
markdownlint --fix CHANGELOG.md || true
release: ## release
cat main.go | sed "s/const AppVersion = .*/const AppVersion = \"$$VER\"/" | tee main.go
cat main.go | sed "s/const GitCommit = .*/const GitCommit = \"$(shell git rev-parse --short HEAD)\"/" | tee main.go
make changelog
git add CHANGELOG.md
git commit -m "updated changelog for v$$VER"
git tag -af v$$VER -m "Release v$$VER"
################################################################################
##@ DOCKER
################################################################################
docker-push-all: ## build and push multiple docker images for multiarch
PLATFORM=amd64 make docker-push-arch
PLATFORM=arm64 make docker-push-arch
docker-push-arch: docker-push ## build and push multiple docker images for one platform
docker buildx build --push --platform=$$PLATFORM -t fabiocicerchia/go-proxy-cache:$$VER-alpine-$$PLATFORM -t fabiocicerchia/go-proxy-cache:alpine-$$PLATFORM -f docker/Dockerfile.alpine .
docker buildx build --push --platform=$$PLATFORM -t fabiocicerchia/go-proxy-cache:$$VER-amazonlinux-$$PLATFORM -t fabiocicerchia/go-proxy-cache:amazonlinux-$$PLATFORM -f docker/Dockerfile.amazonlinux .
docker buildx build --push --platform=$$PLATFORM -t fabiocicerchia/go-proxy-cache:$$VER-debian-$$PLATFORM -t fabiocicerchia/go-proxy-cache:debian-$$PLATFORM -f docker/Dockerfile.debian .
docker buildx build --push --platform=$$PLATFORM -t fabiocicerchia/go-proxy-cache:$$VER-fedora-$$PLATFORM -t fabiocicerchia/go-proxy-cache:fedora-$$PLATFORM -f docker/Dockerfile.fedora .
docker buildx build --push --platform=$$PLATFORM -t fabiocicerchia/go-proxy-cache:$$VER-ubuntu-$$PLATFORM -t fabiocicerchia/go-proxy-cache:ubuntu-$$PLATFORM -f docker/Dockerfile.ubuntu .
################################################################################
##@ HELM
################################################################################
helm-create-package: ## create an helm package from current chart
helm package -d kubernetes/helm/charts kubernetes/helm/
helm-update-repo: ## update index chart repo
helm repo index kubernetes/helm/
helm-deploy-chart: ## deploy to a new helm chart's package
export DEPLOY_FILEPATH=kubernetes/helm/charts/$$DEPLOY_FILE
echo "Manually push the file $$DEPLOY_FILEPATH to GitHub"