mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
build: crossplatform build with packages.
Big thanks to @fg2it who created a POC as well as the build container that this work is based on.
This commit is contained in:
parent
5de2c99c32
commit
9123e0fca8
@ -70,10 +70,13 @@ jobs:
|
|||||||
|
|
||||||
build:
|
build:
|
||||||
docker:
|
docker:
|
||||||
- image: grafana/build-container:v0.1
|
- image: grafana/build-container:crosscompile
|
||||||
working_directory: /go/src/github.com/grafana/grafana
|
working_directory: /go/src/github.com/grafana/grafana
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
|
- run:
|
||||||
|
name: prepare build tools
|
||||||
|
command: '/tmp/bootstrap.sh'
|
||||||
- run:
|
- run:
|
||||||
name: build and package grafana
|
name: build and package grafana
|
||||||
command: './scripts/build/build.sh'
|
command: './scripts/build/build.sh'
|
||||||
|
@ -12,6 +12,10 @@ module.exports = function (grunt) {
|
|||||||
platform: process.platform.replace('win32', 'windows'),
|
platform: process.platform.replace('win32', 'windows'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (grunt.option('platform')) {
|
||||||
|
config.platform = grunt.option('platform');
|
||||||
|
}
|
||||||
|
|
||||||
if (grunt.option('arch')) {
|
if (grunt.option('arch')) {
|
||||||
config.arch = grunt.option('arch');
|
config.arch = grunt.option('arch');
|
||||||
} else {
|
} else {
|
||||||
|
61
build.go
61
build.go
@ -27,8 +27,7 @@ var (
|
|||||||
goarch string
|
goarch string
|
||||||
goos string
|
goos string
|
||||||
gocc string
|
gocc string
|
||||||
gocxx string
|
cgo bool
|
||||||
cgo string
|
|
||||||
pkgArch string
|
pkgArch string
|
||||||
version string = "v1"
|
version string = "v1"
|
||||||
// deb & rpm does not support semver so have to handle their version a little differently
|
// deb & rpm does not support semver so have to handle their version a little differently
|
||||||
@ -53,8 +52,7 @@ func main() {
|
|||||||
flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH")
|
flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH")
|
||||||
flag.StringVar(&goos, "goos", runtime.GOOS, "GOOS")
|
flag.StringVar(&goos, "goos", runtime.GOOS, "GOOS")
|
||||||
flag.StringVar(&gocc, "cc", "", "CC")
|
flag.StringVar(&gocc, "cc", "", "CC")
|
||||||
flag.StringVar(&gocxx, "cxx", "", "CXX")
|
flag.BoolVar(&cgo, "cgo-enabled", cgo, "Enable cgo")
|
||||||
flag.StringVar(&cgo, "cgo-enabled", "", "CGO_ENABLED")
|
|
||||||
flag.StringVar(&pkgArch, "pkg-arch", "", "PKG ARCH")
|
flag.StringVar(&pkgArch, "pkg-arch", "", "PKG ARCH")
|
||||||
flag.StringVar(&phjsToRelease, "phjs", "", "PhantomJS binary")
|
flag.StringVar(&phjsToRelease, "phjs", "", "PhantomJS binary")
|
||||||
flag.BoolVar(&race, "race", race, "Use race detector")
|
flag.BoolVar(&race, "race", race, "Use race detector")
|
||||||
@ -93,20 +91,24 @@ func main() {
|
|||||||
build("grafana-server", "./pkg/cmd/grafana-server", []string{})
|
build("grafana-server", "./pkg/cmd/grafana-server", []string{})
|
||||||
|
|
||||||
case "build":
|
case "build":
|
||||||
clean()
|
//clean()
|
||||||
for _, binary := range binaries {
|
for _, binary := range binaries {
|
||||||
build(binary, "./pkg/cmd/"+binary, []string{})
|
build(binary, "./pkg/cmd/"+binary, []string{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "build-frontend":
|
||||||
|
grunt(gruntBuildArg("build")...)
|
||||||
|
|
||||||
case "test":
|
case "test":
|
||||||
test("./pkg/...")
|
test("./pkg/...")
|
||||||
grunt("test")
|
grunt("test")
|
||||||
|
|
||||||
case "package":
|
case "package":
|
||||||
grunt(gruntBuildArg("release")...)
|
grunt(gruntBuildArg("build")...)
|
||||||
if runtime.GOOS != "windows" {
|
packageGrafana()
|
||||||
createLinuxPackages()
|
|
||||||
}
|
case "package-only":
|
||||||
|
packageGrafana()
|
||||||
|
|
||||||
case "pkg-rpm":
|
case "pkg-rpm":
|
||||||
grunt(gruntBuildArg("release")...)
|
grunt(gruntBuildArg("release")...)
|
||||||
@ -131,6 +133,22 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func packageGrafana() {
|
||||||
|
platformArg := fmt.Sprintf("--platform=%v", goos)
|
||||||
|
previousPkgArch := pkgArch
|
||||||
|
if pkgArch == "" {
|
||||||
|
pkgArch = goarch
|
||||||
|
}
|
||||||
|
postProcessArgs := gruntBuildArg("package")
|
||||||
|
postProcessArgs = append(postProcessArgs, platformArg)
|
||||||
|
grunt(postProcessArgs...)
|
||||||
|
pkgArch = previousPkgArch
|
||||||
|
|
||||||
|
if goos == "linux" && goarch == "amd64"{
|
||||||
|
createLinuxPackages()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func makeLatestDistCopies() {
|
func makeLatestDistCopies() {
|
||||||
files, err := ioutil.ReadDir("dist")
|
files, err := ioutil.ReadDir("dist")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -138,9 +156,9 @@ func makeLatestDistCopies() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
latestMapping := map[string]string{
|
latestMapping := map[string]string{
|
||||||
".deb": "dist/grafana_latest_amd64.deb",
|
"_amd64.deb": "dist/grafana_latest_amd64.deb",
|
||||||
".rpm": "dist/grafana-latest-1.x86_64.rpm",
|
".x86_64.rpm": "dist/grafana-latest-1.x86_64.rpm",
|
||||||
".tar.gz": "dist/grafana-latest.linux-x64.tar.gz",
|
".linux-amd64.tar.gz": "dist/grafana-latest.linux-x64.tar.gz",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
@ -386,7 +404,8 @@ func test(pkg string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func build(binaryName, pkg string, tags []string) {
|
func build(binaryName, pkg string, tags []string) {
|
||||||
binary := "./bin/" + binaryName
|
binary := fmt.Sprintf("./bin/%s-%s/%s", goos, goarch, binaryName)
|
||||||
|
|
||||||
if goos == "windows" {
|
if goos == "windows" {
|
||||||
binary += ".exe"
|
binary += ".exe"
|
||||||
}
|
}
|
||||||
@ -408,6 +427,7 @@ func build(binaryName, pkg string, tags []string) {
|
|||||||
if !isDev {
|
if !isDev {
|
||||||
setBuildEnv()
|
setBuildEnv()
|
||||||
runPrint("go", "version")
|
runPrint("go", "version")
|
||||||
|
fmt.Printf("Targeting %s/%s\n", goos, goarch)
|
||||||
}
|
}
|
||||||
|
|
||||||
runPrint("go", args...)
|
runPrint("go", args...)
|
||||||
@ -451,6 +471,14 @@ func clean() {
|
|||||||
|
|
||||||
func setBuildEnv() {
|
func setBuildEnv() {
|
||||||
os.Setenv("GOOS", goos)
|
os.Setenv("GOOS", goos)
|
||||||
|
if goos == "windows" {
|
||||||
|
// require windows >=7
|
||||||
|
os.Setenv("CGO_CFLAGS", "-D_WIN32_WINNT=0x0601")
|
||||||
|
}
|
||||||
|
if goarch != "amd64" || goos != "linux" {
|
||||||
|
// needed for all other archs
|
||||||
|
cgo = true
|
||||||
|
}
|
||||||
if strings.HasPrefix(goarch, "armv") {
|
if strings.HasPrefix(goarch, "armv") {
|
||||||
os.Setenv("GOARCH", "arm")
|
os.Setenv("GOARCH", "arm")
|
||||||
os.Setenv("GOARM", goarch[4:])
|
os.Setenv("GOARM", goarch[4:])
|
||||||
@ -460,15 +488,12 @@ func setBuildEnv() {
|
|||||||
if goarch == "386" {
|
if goarch == "386" {
|
||||||
os.Setenv("GO386", "387")
|
os.Setenv("GO386", "387")
|
||||||
}
|
}
|
||||||
if cgo != "" {
|
if cgo {
|
||||||
os.Setenv("CGO_ENABLED", cgo)
|
os.Setenv("CGO_ENABLED", "1")
|
||||||
}
|
}
|
||||||
if gocc != "" {
|
if gocc != "" {
|
||||||
os.Setenv("CC", gocc)
|
os.Setenv("CC", gocc)
|
||||||
}
|
}
|
||||||
if gocxx != "" {
|
|
||||||
os.Setenv("CXX", gocxx)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGitSha() string {
|
func getGitSha() string {
|
||||||
|
@ -4,6 +4,12 @@
|
|||||||
# This script is executed from within the container.
|
# This script is executed from within the container.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
CCARMV7=arm-linux-gnueabihf-gcc
|
||||||
|
CCARM64=aarch64-linux-gnu-gcc
|
||||||
|
CCOSX64=/tmp/osxcross/target/bin/o64-clang
|
||||||
|
CCWIN64=x86_64-w64-mingw32-gcc
|
||||||
|
CCX64=/tmp/x86_64-centos6-linux-gnu/bin/x86_64-centos6-linux-gnu-gcc
|
||||||
|
|
||||||
GOPATH=/go
|
GOPATH=/go
|
||||||
REPO_PATH=$GOPATH/src/github.com/grafana/grafana
|
REPO_PATH=$GOPATH/src/github.com/grafana/grafana
|
||||||
|
|
||||||
@ -11,23 +17,45 @@ cd /go/src/github.com/grafana/grafana
|
|||||||
echo "current dir: $(pwd)"
|
echo "current dir: $(pwd)"
|
||||||
|
|
||||||
if [ "$CIRCLE_TAG" != "" ]; then
|
if [ "$CIRCLE_TAG" != "" ]; then
|
||||||
echo "Building a release from tag $CIRCLE_TAG"
|
echo "Building releases from tag $CIRCLE_TAG"
|
||||||
go run build.go -buildNumber=${CIRCLE_BUILD_NUM} -includeBuildNumber=false build
|
go run build.go -goarch armv7 -cc ${CCARMV7} -includeBuildNumber=false build
|
||||||
|
go run build.go -goarch arm64 -cc ${CCARM64} -includeBuildNumber=false build
|
||||||
|
go run build.go -goos darwin -cc ${CCOSX64} -includeBuildNumber=false build
|
||||||
|
go run build.go -goos windows -cc ${CCWIN64} -includeBuildNumber=false build
|
||||||
|
CC=${CCX64} go run build.go -includeBuildNumber=false build
|
||||||
else
|
else
|
||||||
echo "Building incremental build for $CIRCLE_BRANCH"
|
echo "Building incremental build for $CIRCLE_BRANCH"
|
||||||
go run build.go -buildNumber=${CIRCLE_BUILD_NUM} build
|
go run build.go -goarch armv7 -cc ${CCARMV7} -buildNumber=${CIRCLE_BUILD_NUM} build
|
||||||
|
go run build.go -goarch arm64 -cc ${CCARM64} -buildNumber=${CIRCLE_BUILD_NUM} build
|
||||||
|
go run build.go -goos darwin -cc ${CCOSX64} -buildNumber=${CIRCLE_BUILD_NUM} build
|
||||||
|
go run build.go -goos windows -cc ${CCWIN64} -buildNumber=${CIRCLE_BUILD_NUM} build
|
||||||
|
CC=${CCX64} go run build.go -buildNumber=${CIRCLE_BUILD_NUM} build
|
||||||
fi
|
fi
|
||||||
|
|
||||||
yarn install --pure-lockfile --no-progress
|
yarn install --pure-lockfile --no-progress
|
||||||
|
|
||||||
source /etc/profile.d/rvm.sh
|
|
||||||
|
|
||||||
echo "current dir: $(pwd)"
|
echo "current dir: $(pwd)"
|
||||||
|
|
||||||
if [ "$CIRCLE_TAG" != "" ]; then
|
if [ -d "dist" ]; then
|
||||||
echo "Packaging a release from tag $CIRCLE_TAG"
|
rm -rf dist
|
||||||
go run build.go -buildNumber=${CIRCLE_BUILD_NUM} -includeBuildNumber=false package latest
|
fi
|
||||||
else
|
|
||||||
echo "Packaging incremental build for $CIRCLE_BRANCH"
|
if [ "$CIRCLE_TAG" != "" ]; then
|
||||||
go run build.go -buildNumber=${CIRCLE_BUILD_NUM} package latest
|
echo "Building frontend from tag $CIRCLE_TAG"
|
||||||
|
go run build.go -includeBuildNumber=false build-frontend
|
||||||
|
echo "Packaging a release from tag $CIRCLE_TAG"
|
||||||
|
go run build.go -goos linux -pkg-arch amd64 -includeBuildNumber=false package-only latest
|
||||||
|
go run build.go -goos linux -pkg-arch armv7 -includeBuildNumber=false package-only
|
||||||
|
go run build.go -goos linux -pkg-arch arm64 -includeBuildNumber=false package-only
|
||||||
|
go run build.go -goos darwin -pkg-arch amd64 -includeBuildNumber=false package-only
|
||||||
|
go run build.go -goos windows -pkg-arch amd64 -includeBuildNumber=false package-only
|
||||||
|
else
|
||||||
|
echo "Building frontend for $CIRCLE_BRANCH"
|
||||||
|
go run build.go -buildNumber=${CIRCLE_BUILD_NUM} build-frontend
|
||||||
|
echo "Packaging incremental build for $CIRCLE_BRANCH"
|
||||||
|
go run build.go -goos linux -pkg-arch amd64 -buildNumber=${CIRCLE_BUILD_NUM} package-only latest
|
||||||
|
go run build.go -goos linux -pkg-arch armv7 -buildNumber=${CIRCLE_BUILD_NUM} package-only
|
||||||
|
go run build.go -goos linux -pkg-arch arm64 -buildNumber=${CIRCLE_BUILD_NUM} package-only
|
||||||
|
go run build.go -goos darwin -pkg-arch amd64 -buildNumber=${CIRCLE_BUILD_NUM} package-only
|
||||||
|
go run build.go -goos windows -pkg-arch amd64 -buildNumber=${CIRCLE_BUILD_NUM} package-only
|
||||||
fi
|
fi
|
||||||
|
@ -3,13 +3,20 @@ var path = require('path');
|
|||||||
module.exports = function(grunt) {
|
module.exports = function(grunt) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// build, then zip and upload to s3
|
// build then zip
|
||||||
grunt.registerTask('release', [
|
grunt.registerTask('release', [
|
||||||
'build',
|
'build',
|
||||||
'build-post-process',
|
'build-post-process',
|
||||||
'compress:release'
|
'compress:release'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// package into archives
|
||||||
|
grunt.registerTask('package', [
|
||||||
|
'clean:temp',
|
||||||
|
'build-post-process',
|
||||||
|
'compress:release'
|
||||||
|
]);
|
||||||
|
|
||||||
grunt.registerTask('build-post-process', function() {
|
grunt.registerTask('build-post-process', function() {
|
||||||
grunt.config('copy.public_to_temp', {
|
grunt.config('copy.public_to_temp', {
|
||||||
expand: true,
|
expand: true,
|
||||||
@ -18,7 +25,7 @@ module.exports = function(grunt) {
|
|||||||
dest: '<%= tempDir %>/public/',
|
dest: '<%= tempDir %>/public/',
|
||||||
});
|
});
|
||||||
grunt.config('copy.backend_bin', {
|
grunt.config('copy.backend_bin', {
|
||||||
cwd: 'bin',
|
cwd: 'bin/<%= platform %>-<%= arch %>',
|
||||||
expand: true,
|
expand: true,
|
||||||
src: ['*'],
|
src: ['*'],
|
||||||
options: { mode: true},
|
options: { mode: true},
|
||||||
|
Loading…
Reference in New Issue
Block a user