forked from bytebase/bytebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·80 lines (61 loc) · 2.27 KB
/
build.sh
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
#!/bin/sh
# cd to the root directory and run
# ./build.sh [outdir]
# exit when any command fails
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
if [ -z "$1" ];
then
OUTPUT_DIR=$( cd bytebase-build &> /dev/null && pwd )
else
OUTPUT_DIR="$1"
fi
OUTPUT_BINARY=$OUTPUT_DIR/bytebase
if [[ `dirname "${BASH_SOURCE[0]}"` != "." ]]
then
echo "${RED}Precheck failed.${NC} Build script must run from Bytebase root directory ${SCRIPT_DIR}"; exit 1;
fi
GO_VERSION=`go version | { read _ _ v _; echo ${v#go}; }`
if [[ "${GO_VERSION}" < "1.16" ]];
then
echo "${RED}Precheck failed.${NC} Require go version >= 1.16. Current version ${GO_VERSION}."; exit 1;
fi
if ! command -v npm &> /dev/null
then
echo "${RED}Precheck failed.${NC} npm is not installed."; exit 1;
fi
# Step 1 - Build the frontend release version into the backend/server/dist folder
# Step 2 - Build the monolithic app by building backend release version together with the backend/server/dist (leveraing embed introduced in Golang 1.16).
VERSION=`cat ./VERSION`
echo "Start building Bytebase monolithic ${VERSION}..."
echo ""
echo "Step 1 - building bytebase frontend..."
if command -v yarn &> /dev/null
then
yarn --cwd ./frontend release
else
npm --prefix ./frontend run release
fi
echo "Completed building bytebase frontend."
echo ""
echo "Step 2 - building bytebase backend..."
flags="-X 'github.com/bytebase/bytebase/bin/server/cmd.version=${VERSION}'
-X 'github.com/bytebase/bytebase/bin/server/cmd.goversion=$(go version)'
-X 'github.com/bytebase/bytebase/bin/server/cmd.gitcommit=$(git rev-parse HEAD)'
-X 'github.com/bytebase/bytebase/bin/server/cmd.buildtime=$(date -u +"%Y-%m-%dT%H:%M:%SZ")'
-X 'github.com/bytebase/bytebase/bin/server/cmd.builduser=$(id -u -n)'"
# -ldflags="-w -s" means omit DWARF symbol table and the symbol table and debug information
go build --tags "release" -ldflags "-w -s $flags" -o ${OUTPUT_BINARY} ./bin/server/main.go
echo "Completed building bytebase backend."
echo ""
echo "Step 3 - printing version..."
${OUTPUT_BINARY} version
echo ""
echo "${GREEN}Completed building Bytebase monolithic ${VERSION} at ${OUTPUT_BINARY}.${NC}"
echo ""
echo "Command to start Bytebase on http://localhost:8080"
echo ""
echo "$ ${OUTPUT_BINARY} --host http://localhost --port 8080${NC}"
echo ""