This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: use build.sh to build mdz (#138)
Signed-off-by: Wei Zhang <[email protected]>
- Loading branch information
Showing
5 changed files
with
89 additions
and
28 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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
.idea | ||
|
||
bin/ | ||
debug-bin/ | ||
**/password.txt | ||
**/gateway-password.txt | ||
|
||
|
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 |
---|---|---|
|
@@ -28,9 +28,6 @@ | |
# This repo's root import path (under GOPATH). | ||
ROOT := github.com/tensorchord/openmodelz/mdz | ||
|
||
# Target binaries. You can build multiple binaries for a single project. | ||
TARGETS := mdz | ||
|
||
# Container image prefix and suffix added to targets. | ||
# The final built images are: | ||
# $[REGISTRY]/$[IMAGE_PREFIX]$[TARGET]$[IMAGE_SUFFIX]:$[VERSION] | ||
|
@@ -137,31 +134,23 @@ swag-install: | |
go install github.com/swaggo/swag/cmd/[email protected] | ||
|
||
build-local: | ||
@for target in $(TARGETS); do \ | ||
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) go build -trimpath -v -o $(OUTPUT_DIR)/$${target} \ | ||
-ldflags "-s -w -X $(ROOT)/pkg/version.version=$(VERSION) -X $(ROOT)/pkg/version.buildDate=$(BUILD_DATE) -X $(ROOT)/pkg/version.gitCommit=$(GIT_COMMIT) -X $(ROOT)/pkg/version.gitTreeState=$(GIT_TREE_STATE)" \ | ||
$(CMD_DIR)/$${target}; \ | ||
done | ||
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) \ | ||
VERSION=$(VERSION) BUILD_DATE=$(BUILD_DATE) \ | ||
GIT_COMMIT=$(GIT_COMMIT) GIT_TREE_STATE=$(GIT_TREE_STATE) GIT_TAG=$(GIT_TAG) \ | ||
./hack/build.sh build | ||
|
||
build-release: | ||
@for target in $(TARGETS); do \ | ||
CGO_ENABLED=$(CGO_ENABLED) go build -trimpath -o $(OUTPUT_DIR)/$${target} \ | ||
-ldflags "-s -w -X $(ROOT)/pkg/version.version=$(VERSION) \ | ||
-X $(ROOT)/pkg/version.buildDate=$(BUILD_DATE) \ | ||
-X $(ROOT)/pkg/version.gitCommit=$(GIT_COMMIT) \ | ||
-X $(ROOT)/pkg/version.gitTreeState=$(GIT_TREE_STATE) \ | ||
-X $(ROOT)/pkg/version.gitTag=$(GIT_TAG)" \ | ||
$(CMD_DIR)/$${target}; \ | ||
done | ||
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) \ | ||
VERSION=$(VERSION) BUILD_DATE=$(BUILD_DATE) \ | ||
GIT_COMMIT=$(GIT_COMMIT) GIT_TREE_STATE=$(GIT_TREE_STATE) GIT_TAG=$(GIT_TAG) \ | ||
./hack/build.sh release | ||
|
||
# It is used by vscode to attach into the process. | ||
debug-local: | ||
@for target in $(TARGETS); do \ | ||
CGO_ENABLED=$(CGO_ENABLED) go build -tags $(DASHBOARD_BUILD) -trimpath \ | ||
-v -o $(DEBUG_DIR)/$${target} \ | ||
-gcflags='all=-N -l' \ | ||
$(CMD_DIR)/$${target}; \ | ||
done | ||
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) \ | ||
VERSION=$(VERSION) BUILD_DATE=$(BUILD_DATE) \ | ||
GIT_COMMIT=$(GIT_COMMIT) GIT_TREE_STATE=$(GIT_TREE_STATE) GIT_TAG=$(GIT_TAG) \ | ||
./hack/build.sh debug local | ||
|
||
addlicense: addlicense-install ## Add license to GO code files | ||
addlicense -l mpl -c "TensorChord Inc." $$(find . -type f -name '*.go' | grep -v pkg/docs/docs.go) | ||
|
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -x | ||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
kind=${1:-"build"} | ||
deps=${2:-"remote"} | ||
|
||
PROJECT_ROOT=$(realpath "$(dirname "${BASH_SOURCE[@]}")/..") | ||
PROJECT=github.com/tensorchord/openmodelz/mdz | ||
|
||
VERSION=${VERSION:-"v0.0.$(date +%Y%m%d)"} | ||
BUILD_DATE=${BUILD_DATE:-""} | ||
GIT_COMMIT=${GIT_COMMIT:-""} | ||
GIT_TREE_STATE=${GIT_TREE_STATE:-""} | ||
GIT_TAG=${GIT_TAG:-""} | ||
|
||
CGO_ENABLED=${CGO_ENABLED:="0"} | ||
GOOS=${GOOS:="$(go env GOOS)"} | ||
GOARCH=${GOARCH:="$(go env GOARCH)"} | ||
|
||
DASHBOARD_BUILD=${DASHBOARD_BUILD:-"debug"} | ||
|
||
OUTPUT_DIR=${OUTPUT_DIR:-"${PROJECT_ROOT}"} | ||
if [[ ${kind} == "debug" ]]; then | ||
OUTPUT_DIR="${OUTPUT_DIR}/debug-bin" | ||
else | ||
OUTPUT_DIR="${OUTPUT_DIR}/bin" | ||
fi | ||
|
||
LDFLAGS="-s -w \ | ||
-X ${PROJECT}/pkg/version.version=${VERSION} \ | ||
-X ${PROJECT}/pkg/version.buildDate=${BUILD_DATE} \ | ||
-X ${PROJECT}/pkg/version.gitCommit=${GIT_COMMIT} \ | ||
-X ${PROJECT}/pkg/version.gitTreeState=${GIT_TREE_STATE}" | ||
if [[ ${kind} == "release" ]]; then | ||
LDFLAGS="${LDFLAGS} -X ${PROJECT}/pkg/version.gitTag=${GIT_TAG}" | ||
fi | ||
|
||
DEBUG_ARGS=() | ||
if [[ ${kind} == "debug" ]]; then | ||
DEBUG_ARGS=(-tags "${DASHBOARD_BUILD}" -gcflags="all=-N -l") | ||
fi | ||
|
||
MOD_FILE="${PROJECT_ROOT}/go.mod" | ||
if [[ ${deps} == "local" ]]; then | ||
if ! grep "\.\./agent" "${MOD_FILE}"; then | ||
echo "replace github.com/tensorchord/openmodelz/agent => ../agent" >> "${MOD_FILE}" | ||
go mod tidy | ||
fi | ||
else | ||
if grep "\.\./agent" "${MOD_FILE}"; then | ||
sed -i -e '/..agent/d' "${MOD_FILE}" | ||
go mod tidy | ||
fi | ||
fi | ||
|
||
CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build \ | ||
"${DEBUG_ARGS[@]}" \ | ||
-trimpath -v \ | ||
-ldflags "${LDFLAGS}" \ | ||
-o "${OUTPUT_DIR}/mdz" \ | ||
"./cmd/mdz" |