2017-01-23 08:09:18 -06:00
|
|
|
#!/bin/bash
|
2019-10-24 07:34:14 -05:00
|
|
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
|
2017-01-23 08:09:18 -06:00
|
|
|
#
|
|
|
|
# This script is executed from within the container.
|
|
|
|
#
|
2018-10-22 07:33:19 -05:00
|
|
|
set -e
|
|
|
|
|
2019-05-01 10:20:01 -05:00
|
|
|
##########
|
2019-03-22 10:12:42 -05:00
|
|
|
CCARMV6=/opt/rpi-tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
|
2018-12-20 15:48:53 -06:00
|
|
|
CCARMV7=arm-linux-gnueabihf-gcc
|
2019-10-24 07:34:14 -05:00
|
|
|
CCARMV7_MUSL=/tmp/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-gcc
|
2018-12-20 15:48:53 -06:00
|
|
|
CCARM64=aarch64-linux-gnu-gcc
|
2019-10-24 07:34:14 -05:00
|
|
|
CCARM64_MUSL=/tmp/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
|
2018-05-08 02:42:20 -05:00
|
|
|
CCX64=/tmp/x86_64-centos6-linux-gnu/bin/x86_64-centos6-linux-gnu-gcc
|
2019-10-24 07:34:14 -05:00
|
|
|
CCX64_MUSL=/tmp/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc
|
2019-05-01 10:20:01 -05:00
|
|
|
|
|
|
|
BUILD_FAST=0
|
|
|
|
BUILD_BACKEND=1
|
|
|
|
BUILD_FRONTEND=1
|
|
|
|
BUILD_PACKAGE=1
|
|
|
|
|
|
|
|
while [ "$1" != "" ]; do
|
|
|
|
case "$1" in
|
|
|
|
"--fast")
|
|
|
|
BUILD_FAST=1
|
|
|
|
echo "Fast build enabled"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
"--backend-only")
|
|
|
|
BUILD_FRONTEND=0
|
|
|
|
BUILD_PACKAGE=0
|
|
|
|
echo "Building only backend"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
"--frontend-only")
|
|
|
|
BUILD_BACKEND=0
|
|
|
|
BUILD_PACKAGE=0
|
|
|
|
echo "Building only frontend"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
"--package-only")
|
|
|
|
BUILD_BACKEND=0
|
|
|
|
BUILD_FRONTEND=0
|
|
|
|
echo "Building only packaging"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
# unknown param causes args to be passed through to $@
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2019-07-23 05:12:33 -05:00
|
|
|
# shellcheck disable=SC2124
|
2019-05-01 10:20:01 -05:00
|
|
|
EXTRA_OPTS="$@"
|
|
|
|
|
2017-02-24 02:22:57 -06:00
|
|
|
cd /go/src/github.com/grafana/grafana
|
2017-01-30 10:27:12 -06:00
|
|
|
echo "current dir: $(pwd)"
|
|
|
|
|
|
|
|
if [ "$CIRCLE_TAG" != "" ]; then
|
2018-05-08 02:42:20 -05:00
|
|
|
echo "Building releases from tag $CIRCLE_TAG"
|
2018-11-05 08:05:12 -06:00
|
|
|
OPT="-includeBuildId=false ${EXTRA_OPTS}"
|
2017-01-31 03:10:25 -06:00
|
|
|
else
|
|
|
|
echo "Building incremental build for $CIRCLE_BRANCH"
|
2018-11-05 08:05:12 -06:00
|
|
|
OPT="-buildId=${CIRCLE_WORKFLOW_ID} ${EXTRA_OPTS}"
|
2017-01-24 04:24:45 -06:00
|
|
|
fi
|
2017-01-23 08:09:18 -06:00
|
|
|
|
2019-03-22 10:12:42 -05:00
|
|
|
|
2018-10-22 07:33:19 -05:00
|
|
|
echo "Build arguments: $OPT"
|
2019-03-22 10:12:42 -05:00
|
|
|
echo "current dir: $(pwd)"
|
|
|
|
|
2019-05-01 10:20:01 -05:00
|
|
|
function build_backend_linux_amd64() {
|
|
|
|
if [ ! -d "dist" ]; then
|
|
|
|
mkdir dist
|
|
|
|
fi
|
2019-10-24 07:34:14 -05:00
|
|
|
CC=${CCX64} go run build.go ${OPT} build
|
|
|
|
CC=${CCX64_MUSL} go run build.go -libc musl ${OPT} build
|
2019-05-01 10:20:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function build_backend() {
|
|
|
|
if [ ! -d "dist" ]; then
|
|
|
|
mkdir dist
|
|
|
|
fi
|
|
|
|
|
2019-10-24 07:34:14 -05:00
|
|
|
go run build.go -goarch armv6 -cc ${CCARMV6} ${OPT} build
|
|
|
|
go run build.go -goarch armv7 -cc ${CCARMV7} ${OPT} build
|
|
|
|
go run build.go -goarch arm64 -cc ${CCARM64} ${OPT} build
|
|
|
|
go run build.go -goarch armv7 -libc musl -cc ${CCARMV7_MUSL} ${OPT} build
|
|
|
|
go run build.go -goarch arm64 -libc musl -cc ${CCARM64_MUSL} ${OPT} build
|
2019-05-01 10:20:01 -05:00
|
|
|
build_backend_linux_amd64
|
|
|
|
}
|
|
|
|
|
|
|
|
function build_frontend() {
|
|
|
|
if [ ! -d "dist" ]; then
|
|
|
|
mkdir dist
|
|
|
|
fi
|
|
|
|
yarn install --pure-lockfile --no-progress
|
|
|
|
echo "Building frontend"
|
2019-11-08 05:48:32 -06:00
|
|
|
|
|
|
|
start=$(date +%s%N)
|
2019-10-24 07:34:14 -05:00
|
|
|
go run build.go ${OPT} build-frontend
|
2019-11-08 05:48:32 -06:00
|
|
|
runtime=$((($(date +%s%N) - start)/1000000))
|
2020-05-18 08:41:06 -05:00
|
|
|
echo "Frontend build took: $runtime ms"
|
2019-05-01 10:20:01 -05:00
|
|
|
echo "FRONTEND: finished"
|
|
|
|
}
|
|
|
|
|
|
|
|
function package_linux_amd64() {
|
|
|
|
echo "Packaging Linux AMD64"
|
2019-10-24 07:34:14 -05:00
|
|
|
go run build.go -goos linux -pkg-arch amd64 ${OPT} package-only
|
|
|
|
go run build.go -goos linux -pkg-arch amd64 ${OPT} -libc musl -skipRpm -skipDeb package-only
|
2019-05-01 10:20:01 -05:00
|
|
|
go run build.go latest
|
|
|
|
echo "PACKAGE LINUX AMD64: finished"
|
|
|
|
}
|
|
|
|
|
|
|
|
function package_all() {
|
|
|
|
echo "Packaging ALL"
|
2019-10-24 07:34:14 -05:00
|
|
|
go run build.go -goos linux -pkg-arch armv6 ${OPT} -skipRpm package-only
|
|
|
|
go run build.go -goos linux -pkg-arch armv7 ${OPT} package-only
|
|
|
|
go run build.go -goos linux -pkg-arch arm64 ${OPT} package-only
|
|
|
|
go run build.go -goos linux -pkg-arch armv7 -libc musl -skipRpm -skipDeb ${OPT} package-only
|
|
|
|
go run build.go -goos linux -pkg-arch arm64 -libc musl -skipRpm -skipDeb ${OPT} package-only
|
2019-05-01 10:20:01 -05:00
|
|
|
package_linux_amd64
|
|
|
|
echo "PACKAGE ALL: finished"
|
|
|
|
}
|
|
|
|
|
|
|
|
function package_setup() {
|
|
|
|
echo "Packaging: Setup environment"
|
|
|
|
if [ -d "dist" ]; then
|
|
|
|
rm -rf dist
|
|
|
|
fi
|
|
|
|
mkdir dist
|
2019-10-24 07:34:14 -05:00
|
|
|
go run build.go -gen-version ${OPT} > dist/grafana.version
|
2019-05-01 10:20:01 -05:00
|
|
|
# Load ruby, needed for packing with fpm
|
2019-07-23 05:12:33 -05:00
|
|
|
# shellcheck disable=SC1091
|
2019-05-01 10:20:01 -05:00
|
|
|
source /etc/profile.d/rvm.sh
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $BUILD_FAST = "0" ]; then
|
|
|
|
build_backend
|
|
|
|
build_frontend
|
|
|
|
package_setup
|
|
|
|
package_all
|
|
|
|
else
|
|
|
|
if [ $BUILD_BACKEND = "1" ]; then
|
|
|
|
build_backend_linux_amd64
|
|
|
|
fi
|
|
|
|
if [ $BUILD_FRONTEND = "1" ]; then
|
|
|
|
build_frontend
|
|
|
|
fi
|
|
|
|
if [ $BUILD_PACKAGE = "1" ]; then
|
|
|
|
package_setup
|
|
|
|
package_linux_amd64
|
|
|
|
# last step
|
|
|
|
#go run build.go latest
|
|
|
|
fi
|
2019-03-25 07:57:30 -05:00
|
|
|
fi
|