-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
108 lines (86 loc) · 2.83 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
.PHONY: all clean format swag swag-bin server-unittest server frontend run upgrade openfl-device-agent release
RELEASE_VERSION ?= ${shell git describe --tags}
TAG ?= v0.3.0
SERVER_NAME ?= federatedai/fedlcm-server
SERVER_IMG ?= ${SERVER_NAME}:${TAG}
FRONTEND_NAME ?= federatedai/fedlcm-frontend
FRONTEND_IMG ?= ${FRONTEND_NAME}:${TAG}
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
OUTPUT_DIR = output
RELEASE_DIR = ${OUTPUT_DIR}/release
ifeq ($(OS),Windows_NT)
BUILD_MODE = -buildmode=exe
OUTPUT_FILE = ${OUTPUT_DIR}/lifecycle-manager.exe
else
BUILD_MODE =
OUTPUT_FILE = ${OUTPUT_DIR}/lifecycle-manager
endif
OUTPUT_FRONTEND_FOLDER = ${OUTPUT_DIR}/frontend
BRANCH = $(shell git symbolic-ref --short HEAD)
COMMIT = $(shell git log --pretty=format:'%h' -n 1)
NOW = $(shell date "+%Y-%m-%d %T UTC%z")
LDFLAGS = "-X 'github.com/FederatedAI/FedLCM/server/constants.Branch=$(BRANCH)' \
-X 'github.com/FederatedAI/FedLCM/server/constants.Commit=$(COMMIT)' \
-X 'github.com/FederatedAI/FedLCM/server/constants.BuildTime=$(NOW)' \
-extldflags '-static'"
all: swag server frontend openfl-device-agent
frontend:
rm -rf ${OUTPUT_FRONTEND_FOLDER}
mkdir -p ${OUTPUT_DIR}
cd frontend && npm run build --prod
cp -rf frontend/dist/lifecycle-manager ${OUTPUT_FRONTEND_FOLDER}
# Run go fmt & vet against code
format:
go fmt ./...
go vet ./...
# Build manager binary
server: format
mkdir -p ${OUTPUT_DIR}
CGO_ENABLED=0 go build -a --ldflags ${LDFLAGS} -o ${OUTPUT_FILE} ${BUILD_MODE} server/main.go
# Build the cmd line program
openfl-device-agent: format
mkdir -p ${OUTPUT_DIR}
CGO_ENABLED=0 go build -a --ldflags ${LDFLAGS} -o ${OUTPUT_DIR}/openfl-device-agent ${BUILD_MODE} cmd/device-agent/device-agent.go
# Run server tests
server-unittest: format
go test ./... -coverprofile cover.out
run: format
go run --ldflags ${LDFLAGS} ./server/main.go
# Generate swag API file
swag: swag-bin
cd server && $(SWAG_BIN) fmt ;\
$(SWAG_BIN) init --parseDependency --parseInternal
swag-bin:
ifeq (, $(shell which swag))
@{ \
set -e ;\
SWAG_BIN_TMP_DIR=$$(mktemp -d) ;\
cd $$SWAG_BIN_TMP_DIR ;\
go mod init tmp ;\
go install github.com/swaggo/swag/cmd/[email protected] ;\
rm -rf $$SWAG_BIN_TMP_DIR ;\
}
SWAG_BIN=$(GOBIN)/swag
else
SWAG_BIN=$(shell which swag)
endif
docker-build:
docker build . -t ${SERVER_IMG} -f make/server/Dockerfile
docker build . -t ${FRONTEND_IMG} -f make/frontend/Dockerfile
docker-push:
docker push ${SERVER_IMG}
docker push ${FRONTEND_IMG}
clean:
rm -rf ${OUTPUT_DIR}
rm -rf frontend/dist
upgrade:
go get -u ./...
release:
rm -rf ${RELEASE_DIR}
mkdir -p ${RELEASE_DIR}
tar -czvf ${RELEASE_DIR}/fedlcm-k8s-${RELEASE_VERSION}.tgz rbac_config.yaml k8s_deploy.yaml
tar -czvf ${RELEASE_DIR}/fedlcm-docker-compose-${RELEASE_VERSION}.tgz .env docker-compose.yml make/stepca