1
1
SHELL =/bin/bash
2
- COMMIT =$(shell git rev-parse --short HEAD)
3
- VERSION ?= $(shell head -n 1 VERSION 2> /dev/null || echo "0.0.0")
4
- BUILD =$(shell date +% FT% T% z)
5
- LDFLAGS =-w -s -X main.Version=${VERSION} -X main.Build=${BUILD}
6
- PACKAGE_PATH =./dev-tools/package/
7
- DOCKER_BUILD =@export DOCKER_CONTENT_TRUST=1 && export DOCKER_BUILDKIT=1 && docker build --build-arg COMMIT='$(COMMIT ) ' --build-arg VERSION='$(VERSION ) ' --build-arg LDFLAGS='$(LDFLAGS ) ' -f $(PACKAGE_PATH ) Dockerfile
8
-
2
+ DEFAULT_VERSION =$(shell awk '/const defaultVersion/{print $$NF}' main.go | tr -d '"')
3
+ TARGET_ARCH_386 =x86
4
+ TARGET_ARCH_amd64 =x86_64
5
+ TARGET_ARCH_arm64 =arm64
6
+ PLATFORMS ?= darwin/amd64 linux/386 linux/amd64 linux/arm64 windows/386 windows/amd64
7
+ VERSION ?= ${DEFAULT_VERSION}
8
+
9
+ ifeq ($(SNAPSHOT ) ,true)
10
+ BUILD_VERSION =${VERSION}-SNAPSHOT
11
+ else
12
+ BUILD_VERSION =${VERSION}
13
+ endif
14
+
15
+ PLATFORM_TARGETS =$(addprefix release-, $(PLATFORMS ) )
16
+ LDFLAGS =-w -s -X main.Version=${BUILD_VERSION}
9
17
CMD_COLOR_ON =\033[32m\xE2\x9c\x93
10
18
CMD_COLOR_OFF =\033[0m
11
19
@@ -14,33 +22,16 @@ help: ## - Show help message
14
22
@printf " ${CMD_COLOR_ON} usage: make [target]\n\n${CMD_COLOR_OFF} "
15
23
@grep -E ' ^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST ) | sort | sed -e " s/^Makefile://" | awk ' BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
16
24
17
- .PHONY : rpm
18
- rpm : # # - Build x86_64 linux RPM
19
- @printf " ${CMD_COLOR_ON} Build rpm\n${CMD_COLOR_OFF} "
20
- @${DOCKER_BUILD} --ssh default --target rpm -o ./ .
21
-
22
- .PHONY : image
23
- image : # # - Build the elastic fleet docker images
24
- @printf " ${CMD_COLOR_ON} Build the elastic fleet docker image\n${CMD_COLOR_OFF} "
25
- ${DOCKER_BUILD} --ssh default --target fleet -t fleet .
26
-
27
- .PHONY : run
28
- run : image # # - Run the smallest and secured golang docker image based on scratch
29
- @printf " ${CMD_COLOR_ON} Run the elastic fleet docker image\n${CMD_COLOR_OFF} "
30
- @docker-compose -f ./dev-tools/package/docker-compose.yml up
31
-
32
-
33
25
.PHONY : local
34
- local : # # - Build packages using local environment
26
+ local : # # - Build local binary for local environment (bin/fleet-server)
35
27
@printf " ${CMD_COLOR_ON} Build binaries using local go installation\n${CMD_COLOR_OFF} "
36
- go build -ldflags=" ${LDFLAGS} " -o ./bin/fleet .
28
+ go build -ldflags=" ${LDFLAGS} " -o ./bin/fleet-server .
37
29
@printf " ${CMD_COLOR_ON} Binaries in ./bin/\n${CMD_COLOR_OFF} "
38
30
39
-
40
31
.PHONY : clean
41
32
clean : # # - Clean up build artifacts
42
33
@printf " ${CMD_COLOR_ON} Clean up build artifacts\n${CMD_COLOR_OFF} "
43
- rm -rf ./bin/ * .rpm ./build/
34
+ rm -rf ./bin/ ./build/
44
35
45
36
.PHONY : generate
46
37
generate : # # - Generate schema models
@@ -106,6 +97,42 @@ junit-report: ## - Run the junit-report generation for all the out files generat
106
97
@go get -v -u github.com/jstemmer/go-junit-report
107
98
$(foreach file, $(wildcard build/* .out) , go-junit-report > "${file}.xml" < ${file};)
108
99
100
+ # #################################################
101
+ # Release building targets
102
+ # #################################################
103
+
104
+ build/distributions :
105
+ @mkdir -p build/distributions
106
+
107
+ .PHONY : $(PLATFORM_TARGETS )
108
+ $(PLATFORM_TARGETS ) : release-% :
109
+ $(eval $@ _OS := $(firstword $(subst /, ,$(lastword $(subst release-, ,$@ ) ) ) ) )
110
+ $(eval $@ _GO_ARCH := $(lastword $(subst /, ,$(lastword $(subst release-, ,$@ ) ) ) ) )
111
+ $(eval $@ _ARCH := $(TARGET_ARCH_$($@ _GO_ARCH) ) )
112
+ GOOS=$($@ _OS) GOARCH=$($@ _GO_ARCH) go build -ldflags=" ${LDFLAGS} " -o build/binaries/fleet-server-$(VERSION ) -$($@ _OS) -$($@ _ARCH) /fleet-server .
113
+ @$(MAKE ) OS=$($@ _OS) ARCH=$($@ _ARCH) package-target
114
+
115
+ .PHONY : package-target
116
+ package-target : build/distributions
117
+ ifeq ($(OS ) ,windows)
118
+ @cd build/binaries && zip -q -r ../distributions/fleet-server-$(VERSION)-$(OS)-$(ARCH).zip fleet-server-$(VERSION)-$(OS)-$(ARCH)
119
+ @cd build/distributions && shasum -a 512 fleet-server-$(VERSION)-$(OS)-$(ARCH).zip > fleet-server-$(VERSION)-$(OS)-$(ARCH).zip.sha512
120
+ else
121
+ @tar -C build/binaries -zcf build/distributions/fleet-server-$(VERSION)-$(OS)-$(ARCH).tar.gz fleet-server-$(VERSION)-$(OS)-$(ARCH)
122
+ @cd build/distributions && shasum -a 512 fleet-server-$(VERSION)-$(OS)-$(ARCH).tar.gz > fleet-server-$(VERSION)-$(OS)-$(ARCH).tar.gz.sha512
123
+ endif
124
+
125
+ .PHONY : release
126
+ release : $(PLATFORM_TARGETS ) # # - Builds a release. Specify exact platform with PLATFORMS env.
127
+
128
+ .PHONY : release-manager-snapshot
129
+ release-manager-snapshot : # # - Builds a snapshot release. The Go version defined in .go-version will be installed and used for the build.
130
+ @$(MAKE ) SNAPSHOT=true release-manager-release
131
+
132
+ .PHONY : release-manager-release
133
+ release-manager-release : # # - Builds a snapshot release. The Go version defined in .go-version will be installed and used for the build.
134
+ ./dev-tools/run_with_go_ver $(MAKE ) release
135
+
109
136
# #################################################
110
137
# Integration testing targets
111
138
# #################################################
0 commit comments