-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpackage.sh
executable file
·58 lines (46 loc) · 1.59 KB
/
package.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
#!/bin/sh
# make a release tarball
PKGNAME=tidb-insight
git submodule update --init --recursive
if [ -z $1 ]; then
RELVER=`git describe --tags`
else
RELVER=$1
fi
RELPATH=${PKGNAME}-${RELVER}
GO_RELEASE_BIN=go1.16.10.linux-${HOSTARCH}
BUILD_ROOT="`pwd`/.build"
mkdir -p ${BUILD_ROOT}
cd ${BUILD_ROOT}
if [ ! -f ${GO_RELEASE_BIN}.tar.gz ]; then
wget https://dl.google.com/go/${GO_RELEASE_BIN}.tar.gz
tar zxf ${GO_RELEASE_BIN}.tar.gz
fi
# clean exist binaries
rm -rf ${BUILD_ROOT}/${PKGNAME} ${BUILD_ROOT}/${PKGNAME}-*.tar.gz
mkdir -p ${BUILD_ROOT}/${PKGNAME}
cp -rf ${BUILD_ROOT}/../* ${BUILD_ROOT}/${PKGNAME}/ 2>/dev/null
# prepare dependencies
GOROOT="${BUILD_ROOT}/go"
export GOROOT
BUILD_FLAGS="-trimpath"
export BUILD_FLAGS
# compile a static binary
cd ${BUILD_ROOT}/${PKGNAME}/collector/
GOBIN=${GOROOT}/bin/go GOOS=${GOOS} GOARCH=${GOARCH} make static || exit 1
cd ${BUILD_ROOT}/${PKGNAME}/tools/
GOBIN=${GOROOT}/bin/go GOOS=${GOOS} GOARCH=${GOARCH} make static || exit 1
# compile other tools
cd ${BUILD_ROOT}/${PKGNAME}/tools/vmtouch
LDFLAGS="-static" make || exit 1
install -Dsm755 vmtouch ${BUILD_ROOT}/${PKGNAME}/bin/
# clean unecessary files
cd ${BUILD_ROOT}/${PKGNAME}/
mv tools/docker bin/ && sed -i 's/tools/bin/g' docker.sh
rm -rf collector data tools docs tests pkg Makefile package.sh Gopkg.* *.log
find ${BUILD_ROOT}/${PKGNAME}/ -name "*.pyc" | xargs rm 2>/dev/null
find ${BUILD_ROOT}/${PKGNAME}/ -name "__pycache__" | xargs rm -rf 2>/dev/null
find ${BUILD_ROOT}/${PKGNAME}/ -name "*.out" | xargs rm 2>/dev/null
# make tarball archive
cd ${BUILD_ROOT}
tar zcf ${RELPATH}.tar.gz ${PKGNAME}