-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dungnh139
committed
Oct 21, 2024
1 parent
5078ad5
commit 26ddf3f
Showing
10 changed files
with
107 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
*.dll | ||
*.so | ||
*.dylib | ||
_output/ | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
PACKAGE_NAME = github.com/bamboo-firewall/be | ||
SERVER_DIR = ./cmd/server | ||
SERVER_BIN_NAME = bamboo-apiserver | ||
CLI_DIR = ./cmd/bamboofwcli | ||
CLI_BIN_NAME = bbfw | ||
|
||
VERSION ?= $(shell git describe --abbrev=0 --tags) | ||
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) | ||
BUILD_TIME ?= $(shell date +%Y-%m-%dT%H:%M:%S%z) | ||
.PHONY: all-platform | ||
all-platform: | ||
build/build.sh $(SERVER_DIR) $(SERVER_BIN_NAME) all | ||
build/build.sh $(CLI_DIR) $(CLI_BIN_NAME) all | ||
|
||
ORGANIZATION = ATAOCloud | ||
.PHONY: all | ||
all: build-server build-bbfw | ||
|
||
LDFLAGS = -s -w -X $(PACKAGE_NAME)/buildinfo.Version=$(VERSION) \ | ||
-X $(PACKAGE_NAME)/buildinfo.GitBranch=$(BRANCH) \ | ||
-X $(PACKAGE_NAME)/buildinfo.BuildDate=$(BUILD_TIME) \ | ||
-X $(PACKAGE_NAME)/buildinfo.Organization=$(ORGANIZATION) | ||
.PHONY: build-server | ||
build-server: | ||
build/build.sh $(SERVER_DIR) $(SERVER_BIN_NAME) | ||
|
||
GOOS ?= linux | ||
GOARCH ?= amd64 | ||
CGO_ENABLED ?= 0 | ||
|
||
BUILD := go build -buildvcs=false -a -installsuffix cgo | ||
|
||
.PHONY: build | ||
build-bbfwcli: | ||
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) $(BUILD) -ldflags="$(LDFLAGS)" -o bbfwcli ./cmd/bamboofwcli | ||
.PHONY: build-bbfw | ||
build-bbfw: | ||
build/build.sh $(CLI_DIR) $(CLI_BIN_NAME) | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f bbfwcli | ||
build/clean.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
ROOT_PATH="$(cd "$(dirname "$0")/.." && pwd -P)" | ||
BUILD_PATH="${ROOT_PATH}/build" | ||
|
||
source "${BUILD_PATH}/init.sh" | ||
|
||
golang::build_binaries "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
ROOT_PATH="$(cd "$(dirname "$0")/.." && pwd -P)" | ||
BUILD_PATH="${ROOT_PATH}/build" | ||
|
||
source "${BUILD_PATH}/init.sh" | ||
|
||
cleanup() { | ||
rm -r ${BUILD_OUTPUT_PATH} | ||
} | ||
|
||
cleanup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env bash | ||
|
||
readonly SUPPORTED_PLATFORMS=( | ||
linux/amd64 | ||
linux/arm64 | ||
darwin/amd64 | ||
darwin/arm64 | ||
windows/amd64 | ||
windows/arm64 | ||
) | ||
|
||
golang::build_binaries() { | ||
local -a platforms | ||
if [[ "$3" == "all" ]]; then | ||
platforms=("${SUPPORTED_PLATFORMS[@]}") | ||
else | ||
local host_platform | ||
host_platform=$(golang::host_platform) | ||
platforms+=("${host_platform}") | ||
fi | ||
|
||
for platform in "${platforms[@]}"; do | ||
golang::build_binary_for_platform ${platform} $1 $2 | ||
done | ||
} | ||
|
||
golang::build_binary_for_platform() { | ||
local platform="$1" | ||
local build_dir="$2" | ||
local bin_name="$3" | ||
|
||
GOOS=${platform%%/*} | ||
GOARCH=${platform##*/} | ||
output="${BUILD_CMD_PATH}/${GOOS}/${GOARCH}/${bin_name}" | ||
|
||
CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} ${GO_BUILD} -ldflags="${LDFLAGS}" -o ${output} ${build_dir} | ||
} | ||
|
||
golang::host_platform() { | ||
echo "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
|
||
BUILD_OUTPUT_PATH="${ROOT_PATH}/_output" | ||
BUILD_CMD_PATH="${BUILD_OUTPUT_PATH}/bin" | ||
|
||
PACKAGE_NAME="github.com/bamboo-firewall/be" | ||
|
||
VERSION="$(git describe --abbrev=0 --tags)" | ||
BRANCH="$(git rev-parse --abbrev-ref HEAD)" | ||
BUILD_TIME="$(date +%Y-%m-%dT%H:%M:%S%z)" | ||
|
||
ORGANIZATION="ATAOCloud" | ||
|
||
LDFLAGS="-s -w -X ${PACKAGE_NAME}/buildinfo.Version=${VERSION} \ | ||
-X ${PACKAGE_NAME}/buildinfo.GitBranch=${BRANCH} \ | ||
-X ${PACKAGE_NAME}/buildinfo.BuildDate=${BUILD_TIME} \ | ||
-X ${PACKAGE_NAME}/buildinfo.Organization=${ORGANIZATION}" | ||
|
||
CGO_ENABLED=0 | ||
|
||
GO_BUILD="go build -buildvcs=false -a -installsuffix cgo" | ||
|
||
source "${BUILD_PATH}/golang.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import ( | |
) | ||
|
||
const ( | ||
binaryName = "bbfwcli" | ||
binaryName = "bbfw" | ||
) | ||
|
||
var rootCMD = &cobra.Command{ | ||
|