forked from krakend/krakend-ce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
142 lines (119 loc) · 4.72 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
.PHONY: all build test
# This Makefile is a simple example that demonstrates usual steps to build a binary that can be run in the same
# architecture that was compiled in. The "ldflags" in the build assure that any needed dependency is included in the
# binary and no external dependencies are needed to run the service.
BIN_NAME :=krakend
OS := $(shell uname | tr '[:upper:]' '[:lower:]')
VERSION := 2.0.5
GIT_COMMIT := $(shell git rev-parse --short=7 HEAD)
PKGNAME := krakend
LICENSE := Apache 2.0
VENDOR=
URL := http://krakend.io
RELEASE := 0
USER := krakend
ARCH := amd64
DESC := High performance API gateway. Aggregate, filter, manipulate and add middlewares
MAINTAINER := Daniel Ortiz <dortiz@krakend.io>
DOCKER_WDIR := /tmp/fpm
DOCKER_FPM := devopsfaith/fpm
GOLANG_VERSION := 1.17.11
GLIBC_VERSION := $(shell sh find_glibc.sh)
ALPINE_VERSION := 3.15
FPM_OPTS=-s dir -v $(VERSION) -n $(PKGNAME) \
--license "$(LICENSE)" \
--vendor "$(VENDOR)" \
--maintainer "$(MAINTAINER)" \
--architecture $(ARCH) \
--url "$(URL)" \
--description "$(DESC)" \
--config-files etc/ \
--verbose
DEB_OPTS= -t deb --deb-user $(USER) \
--depends ca-certificates \
--before-remove builder/scripts/prerm.deb \
--after-remove builder/scripts/postrm.deb \
--before-install builder/scripts/preinst.deb
RPM_OPTS =--rpm-user $(USER) \
--before-install builder/scripts/preinst.rpm \
--before-remove builder/scripts/prerm.rpm \
--after-remove builder/scripts/postrm.rpm
DEBNAME=${PKGNAME}_${VERSION}-${RELEASE}_${ARCH}.deb
RPMNAME=${PKGNAME}-${VERSION}-${RELEASE}.x86_64.rpm
all: test
build:
@echo "Building the binary..."
@go get .
@go build -ldflags="-X github.com/luraproject/lura/v2/core.KrakendVersion=${VERSION} \
-X github.com/luraproject/lura/v2/core.GoVersion=${GOLANG_VERSION} \
-X github.com/luraproject/lura/v2/core.GlibcVersion=${GLIBC_VERSION}" \
-o ${BIN_NAME} ./cmd/krakend-ce
@echo "You can now use ./${BIN_NAME}"
test: build
go test -v ./tests
# Build KrakenD using docker (defaults to whatever the golang container uses)
build_on_docker:
docker run --rm -it -v "${PWD}:/app" -w /app golang:${GOLANG_VERSION} make -e build
# Build the container using the Dockerfile (alpine)
docker:
docker build --no-cache --pull --build-arg GOLANG_VERSION=${GOLANG_VERSION} --build-arg ALPINE_VERSION=${ALPINE_VERSION} -t devopsfaith/krakend:${VERSION} .
benchmark:
@mkdir -p bench_res
@touch bench_res/${GIT_COMMIT}.out
@docker run --rm -d --name krakend -v "${PWD}/tests/fixtures:/etc/krakend" -p 8080:8080 devopsfaith/krakend:${VERSION} run -dc /etc/krakend/bench.json
@sleep 2
@docker run --rm -it --link krakend peterevans/vegeta sh -c \
"echo 'GET http://krakend:8080/test' | vegeta attack -rate=0 -duration=30s -max-workers=300 | tee results.bin | vegeta report" > bench_res/${GIT_COMMIT}.out
@docker stop krakend
@cat bench_res/${GIT_COMMIT}.out
security_scan:
@mkdir -p sec_scan
@touch sec_scan/${GIT_COMMIT}.out
@docker run --rm -d --name krakend -v "${PWD}/tests/fixtures:/etc/krakend" -p 8080:8080 devopsfaith/krakend:${VERSION} run -dc /etc/krakend/bench.json
@docker run --rm -it --link krakend instrumentisto/nmap --script vuln krakend > sec_scan/${GIT_COMMIT}.out
@docker stop krakend
@cat sec_scan/${GIT_COMMIT}.out
builder/skel/%/etc/init.d/krakend: builder/files/krakend.init
mkdir -p "$(dir $@)"
cp builder/files/krakend.init "$@"
builder/skel/%/usr/bin/krakend: krakend
mkdir -p "$(dir $@)"
cp krakend "$@"
builder/skel/%/etc/krakend/krakend.json: krakend.json
mkdir -p "$(dir $@)"
cp krakend.json "$@"
builder/skel/%/lib/systemd/system/krakend.service: builder/files/krakend.service
mkdir -p "$(dir $@)"
cp builder/files/krakend.service "$@"
builder/skel/%/usr/lib/systemd/system/krakend.service: builder/files/krakend.service
mkdir -p "$(dir $@)"
cp builder/files/krakend.service "$@"
.PHONE: tgz
tgz: builder/skel/tgz/usr/bin/krakend
tgz: builder/skel/tgz/etc/krakend/krakend.json
tgz: builder/skel/tgz/etc/init.d/krakend
tar zcvf krakend_${VERSION}_${ARCH}.tar.gz -C builder/skel/tgz/ .
.PHONY: deb
deb: builder/skel/deb/usr/bin/krakend
deb: builder/skel/deb/etc/krakend/krakend.json
docker run --rm -it -v "${PWD}:${DOCKER_WDIR}" -w ${DOCKER_WDIR} ${DOCKER_FPM}:deb -t deb ${DEB_OPTS} \
--iteration ${RELEASE} \
--deb-systemd builder/files/krakend.service \
-C builder/skel/deb \
${FPM_OPTS}
.PHONY: rpm
rpm: builder/skel/rpm/usr/lib/systemd/system/krakend.service
rpm: builder/skel/rpm/usr/bin/krakend
rpm: builder/skel/rpm/etc/krakend/krakend.json
docker run --rm -it -v "${PWD}:${DOCKER_WDIR}" -w ${DOCKER_WDIR} ${DOCKER_FPM}:rpm -t rpm ${RPM_OPTS} \
--iteration ${RELEASE} \
-C builder/skel/rpm \
${FPM_OPTS}
.PHONY: clean
clean:
rm -rf builder/skel/*
rm -f *.deb
rm -f *.rpm
rm -f *.tar.gz
rm -f krakend
rm -rf vendor/