-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
124 lines (102 loc) · 5.63 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
SHELL=/bin/bash
# Makefile for the Odd Forest Microservice HTTP API Server
# Copyright 2023 Intel Corporation
# define standard colors
BLACK := $(shell tput -Txterm setaf 0)
RED := $(shell tput -Txterm setaf 1)
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
LIGHTPURPLE := $(shell tput -Txterm setaf 4)
PURPLE := $(shell tput -Txterm setaf 5)
BLUE := $(shell tput -Txterm setaf 6)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
os := $(shell uname -s)
arch := $(shell uname -p)
date := $(shell date)
echo:
@printf "${GREEN}Make is installed. Build away!${RESET}\n"
ifeq (, $(shell which go))
@printf "Golang not installed. Install go manually or use make install_deps.\n"
else
@printf "${GREEN} Go installed! Ready to build.\n${RESET}"
endif
install_deps:
@printf "${LIGHTPURPLE}Installing Go 1.23.3 64-bit...${RESET}\n"
wget https://golang.org/dl/go1.23.3.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.23.3.linux-amd64.tar.gz
@echo "export PATH=$$PATH:/usr/local/go/bin" >> ~/.bashrc
exec $$SHELL
.PHONY: build_linux
build_linux: start_build clean
ifeq ($(arch),x86_64)
@printf "\t${PURPLE}Building for Linux 64-bit...${RESET}\n"
cd oddforest-microservice/src; \
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ../../bin/oddforest_server.run main.go
@printf "\t${GREEN}Linux 64 build completed.${RESET}\n"
endif
.PHONY: start_build
start_build:
@printf "\t${GREEN}Starting Build${RESET} Current Time: $(shell date +"%T.%3N")\n"
@printf "\t${BLUE}Executing tests...${RESET}\n"
-go test ../...
.PHONY: compile_assets
compile_assets:
@printf "\t${BLUE}Compiling assets...${RESET}\n"
go run ../internal/vfsgen/asset_gen.go
mv apiassets.go ../pkg/apiserver/apiassets.go
mv mainassets.go ../pkg/main/mainassets.go
mv pamassets.go ../pkg/ncbpam/pamassets.go
.PHONY:full_build
full_build: start_build run_tests build_linux finish_build
.PHONY:run_tests
run_tests:
@printf "\t${YELLOW}Running Test Suite...${RESET}\n"
go test -cover -covermode=atomic -coverprofile=main_coverage.out -cpuprofile=main_cpu.out -memprofile=main_mem.out -coverpkg=all -outputdir=../tests/ -v -o ../tests/main.test ../pkg/main
go test -cover -covermode=atomic -coverprofile=apiserver_coverage.out -cpuprofile=apiserver_cpu.out -memprofile=apiserver_mem.out -coverpkg=all -outputdir=../tests/ -v -o ../tests/apiserver.test ../pkg/apiserver
go test -cover -covermode=atomic -coverprofile=projectpath_coverage.out -cpuprofile=projectpath_cpu.out -memprofile=projectpath_mem.out -coverpkg=all -outputdir=../tests/ -v -o ../tests/projectpath.test ../pkg/projectpath
go test -cover -covermode=atomic -coverprofile=logrusfilehook_coverage.out -cpuprofile=logrusfilehook_cpu.out -memprofile=logrusfilehook_mem.out -coverpkg=all -outputdir=../tests/ -v -o ../tests/logrusfilehook.test ../pkg/logrusfilehook
go test -cover -covermode=atomic -coverprofile=ncbpam_coverage.out -cpuprofile=ncbpam_cpu.out -memprofile=ncbpam_mem.out -coverpkg=all -outputdir=../tests/ -v -o ../tests/ncbpam.test ../pkg/ncbpam
go tool cover -html=../tests/main_coverage.out -o=../tests/main_coverage.html
go tool cover -html=../tests/apiserver_coverage.out -o=../tests/apiserver_coverage.html
go tool cover -html=../tests/projectpath_coverage.out -o=../tests/projectpath_coverage.html
go tool cover -html=../tests/logrusfilehook_coverage.out -o=../tests/logrusfilehook_coverage.html
go tool cover -html=../tests/ncbpam_coverage.out -o=../tests/ncbpam_coverage.html
.PHONY:run
run:
./bin/oddforest_server.run
.PHONY:run_debug
run_debug:
./bin/oddforest_server.run -debug
.PHONY:run_noencrypt
run_noencrypt:
./bin/oddforest_server.run -noencrypt
.PHONY:run_nolog
run_nolog:
./bin/oddforest_server.run -nolog
.PHONY:run_options
run_options:
./bin/oddforest_server.run -h
.PHONY:run_background
run_background:
./bin/oddforest_server.run > /dev/null 2>&1 &
.PHONY:clean
clean:
ifeq ("$(wildcard $(./bin/oddforest_server.run))","")
-rm ./bin/oddforest_server.run
endif
@printf "\t${RED}Binaries removed${RESET}\n"
.PHONY:help
help:
@printf "\t${GREEN}Build and run the server.${RESET} Usage: make ${YELLOW}<Target>${RESET}\n Targets:\n"
@printf "\t${BLUE}compile_assets${RESET}: compiles assets and configuration files for bundling with the binary. Necessary for single-binary distribution.\n"
@printf "\t${BLUE}full_build${RESET}: Runs a full build. Builds for ARM64, Linux x86_64, runs the testing suite, generates profiles and test binaries.\n"
@printf "\t${BLUE}install_deps${RESET}: attempts to install Go 1.23.3.\n"
@printf "\t${BLUE}echo${RESET}: checks for make and go\n"
@printf "\t${BLUE}run_tests${RESET}: runs the Go test suite, creating CPU, Memory, and Test profiles and a Test Coverage HTML report. Note that this is computationally expensive.\n"
@printf "\t${BLUE}run${RESET}: run the server with default settings. Serves the server on ${GREEN}localhost:8080${RESET}. If using an external device to access, use the server's ip address instead of localhost.\n"
@printf "\t${BLUE}run_debug${RESET}: run the server in debug mode. ${RED}Extremely insecure! Only use for dev purposes, and even then use only when absolutely necessary!${RESET} ${YELLOW}Username: admin Password: admin ${RESET}\n"
@printf "\t${BLUE}run_nolog${RESET}: run the server without logging to file. ${YELLOW}Not recommended. ${RESET}\n"
@printf "\t${BLUE}run_options${RESET}: invoke's the server help function, explaining the possible command flags.\n"
@printf "\t${BLUE}run_background${RESET}: run the server in the background. The process ID will be printed on invoking.\n"
@printf "\t${BLUE}clean${RESET}: clear out the binaries from the ../bin/ directory.\n"