forked from easegress-io/easegress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
107 lines (83 loc) · 3.35 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
SHELL:=/bin/bash
.PHONY: build build_client build_server \
build_client_alpine build_server_alpine build_server_ubuntu \
run fmt vet clean \
mod_update vendor_from_mod vendor_clean test
export GO111MODULE=on
export GOPROXY=https://goproxy.io
# Path Related
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MKFILE_DIR := $(dir $(MKFILE_PATH))
# Version
RELEASE?=1.0.0
# Git Related
GIT_REPO_INFO=$(shell cd ${MKFILE_DIR} && git config --get remote.origin.url)
ifndef GIT_COMMIT
GIT_COMMIT := git-$(shell git rev-parse --short HEAD)
endif
# Docker Related
DOCKER=docker
DOCKER_REPO_INFO?=megaease/easegress
# Source Files
ALL_FILES = $(shell find ${MKFILE_DIR}{cmd,pkg} -type f -name "*.go")
CLIENT_FILES = $(shell find ${MKFILE_DIR}{cmd/client,pkg} -type f -name "*.go")
SERVER_FILES = $(shell find ${MKFILE_DIR}{cmd/server,pkg} -type f -name "*.go")
# Targets
TARGET_SERVER=${MKFILE_DIR}bin/easegress-server
TARGET_CLIENT=${MKFILE_DIR}bin/egctl
TARGET=${TARGET_SERVER} ${TARGET_CLIENT}
# Rules
build: ${TARGET}
build_client: ${TARGET_CLIENT}
build_server: ${TARGET_SERVER}
build_client_alpine: ${TARGET_CLIENT}
@echo "build client docker image (from alpine)"
rm -rf ${MKFILE_DIR}rootfs/alpine/opt && \
mkdir -p ${MKFILE_DIR}rootfs/alpine/opt/easegress/bin && \
cp ${TARGET_CLIENT} ${MKFILE_DIR}rootfs/alpine/opt/easegress/bin && \
cd ${MKFILE_DIR}rootfs/alpine && $(DOCKER) build -t ${DOCKER_REPO_INFO}:client-${RELEASE}_alpine -f ./Dockerfile.client .
build_server_alpine: ${TARGET_SERVER}
@echo "build server docker image (from alpine)"
rm -rf ${MKFILE_DIR}rootfs/alpine/opt && \
mkdir -p ${MKFILE_DIR}rootfs/alpine/opt/easegress/bin && \
cp ${TARGET_SERVER} ${MKFILE_DIR}rootfs/alpine/opt/easegress/bin && \
cd ${MKFILE_DIR}rootfs/alpine && $(DOCKER) build -t ${DOCKER_REPO_INFO}:server-${RELEASE}_alpine -f ./Dockerfile.server .
build_server_ubuntu: ${TARGET_SERVER}
@echo "build server docker image (from ubuntu)"
rm -rf ${MKFILE_DIR}rootfs/ubuntu/opt && \
mkdir -p ${MKFILE_DIR}rootfs/ubuntu/opt/easegress/bin && \
cp ${TARGET_SERVER} ${MKFILE_DIR}rootfs/ubuntu/opt/easegress/bin && \
cd ${MKFILE_DIR}rootfs/ubuntu && $(DOCKER) build -t ${DOCKER_REPO_INFO}:server-${RELEASE}_ubuntu -f ./Dockerfile.server .
test:
@go list ./{cmd,pkg}/... | grep -v -E 'vendor' | xargs -n1 go test
clean:
rm -rf ${TARGET}
run: build_server
${TARGET_SERVER}
fmt:
cd ${MKFILE_DIR} && go fmt ./{cmd,pkg}/...
vet:
cd ${MKFILE_DIR} && go vet ./{cmd,pkg}/...
vendor_from_mod:
cd ${MKFILE_DIR} && go mod vendor
vendor_clean:
rm -rf ${MKFILE_DIR}vendor
mod_update:
cd ${MKFILE_DIR} && go get -u
GO_LD_FLAGS= "-s -w -X github.com/megaease/easegress/pkg/version.RELEASE=${RELEASE} -X github.com/megaease/easegress/pkg/version.COMMIT=${GIT_COMMIT} -X github.com/megaease/easegress/pkg/version.REPO=${GIT_REPO_INFO}"
${TARGET_SERVER} : ${SERVER_FILES}
@echo "build server"
cd ${MKFILE_DIR} && \
CGO_ENABLED=0 go build -v -ldflags ${GO_LD_FLAGS} \
-o ${TARGET_SERVER} ${MKFILE_DIR}cmd/server/main.go
${TARGET_CLIENT} : ${CLIENT_FILES}
@echo "build client"
cd ${MKFILE_DIR} && \
CGO_ENABLED=0 go build -v -ldflags ${GO_LD_FLAGS} \
-o ${TARGET_CLIENT} ${MKFILE_DIR}cmd/client/main.go
${TARGET_INVENTORY} : ${INVENTORY_FILES}
@echo "build inventory"
cd ${MKFILE_DIR} && \
rm -rf ${TARGET_INVENTORY} && \
mkdir -p ${TARGET_INVENTORY} && \
cp -r ${INVENTORY_FILES} ${TARGET_INVENTORY}