Merge pull request #11920 from grafana/crosscompile
Crosscompile and packages Grafana on arm, windows, linux and darwin
This commit is contained in:
Executable
+87
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# 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
|
||||
REPO_PATH=$GOPATH/src/github.com/grafana/grafana
|
||||
|
||||
cd /go/src/github.com/grafana/grafana
|
||||
echo "current dir: $(pwd)"
|
||||
|
||||
if [ "$CIRCLE_TAG" != "" ]; then
|
||||
echo "Building releases from tag $CIRCLE_TAG"
|
||||
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
|
||||
echo "Building incremental build for $CIRCLE_BRANCH"
|
||||
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
|
||||
|
||||
yarn install --pure-lockfile --no-progress
|
||||
|
||||
echo "current dir: $(pwd)"
|
||||
|
||||
if [ -d "dist" ]; then
|
||||
rm -rf dist
|
||||
fi
|
||||
|
||||
if [ "$CIRCLE_TAG" != "" ]; then
|
||||
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
|
||||
|
||||
if [ -d '/tmp/phantomjs/darwin' ]; then
|
||||
cp /tmp/phantomjs/darwin/phantomjs tools/phantomjs/phantomjs
|
||||
else
|
||||
echo 'PhantomJS binaries for darwin missing!'
|
||||
fi
|
||||
go run build.go -goos darwin -pkg-arch amd64 -includeBuildNumber=false package-only
|
||||
|
||||
if [ -d '/tmp/phantomjs/windows' ]; then
|
||||
cp /tmp/phantomjs/windows/phantomjs.exe tools/phantomjs/phantomjs.exe
|
||||
rm tools/phantomjs/phantomjs
|
||||
else
|
||||
echo 'PhantomJS binaries for darwin missing!'
|
||||
fi
|
||||
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
|
||||
|
||||
if [ -d '/tmp/phantomjs/darwin' ]; then
|
||||
cp /tmp/phantomjs/darwin/phantomjs tools/phantomjs/phantomjs
|
||||
else
|
||||
echo 'PhantomJS binaries for darwin missing!'
|
||||
fi
|
||||
go run build.go -goos darwin -pkg-arch amd64 -buildNumber=${CIRCLE_BUILD_NUM} package-only
|
||||
|
||||
if [ -d '/tmp/phantomjs/windows' ]; then
|
||||
cp /tmp/phantomjs/windows/phantomjs.exe tools/phantomjs/phantomjs.exe
|
||||
rm tools/phantomjs/phantomjs
|
||||
else
|
||||
echo 'PhantomJS binaries for windows missing!'
|
||||
fi
|
||||
go run build.go -goos windows -pkg-arch amd64 -buildNumber=${CIRCLE_BUILD_NUM} package-only
|
||||
fi
|
||||
+15
-7
@@ -4,6 +4,8 @@
|
||||
# This script is executed from within the container.
|
||||
#
|
||||
|
||||
CCX64=/tmp/x86_64-centos6-linux-gnu/bin/x86_64-centos6-linux-gnu-gcc
|
||||
|
||||
GOPATH=/go
|
||||
REPO_PATH=$GOPATH/src/github.com/grafana/grafana
|
||||
|
||||
@@ -11,23 +13,29 @@ cd /go/src/github.com/grafana/grafana
|
||||
echo "current dir: $(pwd)"
|
||||
|
||||
if [ "$CIRCLE_TAG" != "" ]; then
|
||||
echo "Building a release from tag $CIRCLE_TAG"
|
||||
go run build.go -buildNumber=${CIRCLE_BUILD_NUM} -includeBuildNumber=false build
|
||||
echo "Building releases from tag $CIRCLE_TAG"
|
||||
CC=${CCX64} go run build.go -includeBuildNumber=false build
|
||||
else
|
||||
echo "Building incremental build for $CIRCLE_BRANCH"
|
||||
go run build.go -buildNumber=${CIRCLE_BUILD_NUM} build
|
||||
CC=${CCX64} go run build.go -buildNumber=${CIRCLE_BUILD_NUM} build
|
||||
fi
|
||||
|
||||
yarn install --pure-lockfile --no-progress
|
||||
|
||||
source /etc/profile.d/rvm.sh
|
||||
|
||||
echo "current dir: $(pwd)"
|
||||
|
||||
if [ -d "dist" ]; then
|
||||
rm -rf dist
|
||||
fi
|
||||
|
||||
if [ "$CIRCLE_TAG" != "" ]; then
|
||||
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 -buildNumber=${CIRCLE_BUILD_NUM} -includeBuildNumber=false package latest
|
||||
go run build.go -goos linux -pkg-arch amd64 -includeBuildNumber=false package-only latest
|
||||
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 -buildNumber=${CIRCLE_BUILD_NUM} package latest
|
||||
go run build.go -goos linux -pkg-arch amd64 -buildNumber=${CIRCLE_BUILD_NUM} package-only latest
|
||||
fi
|
||||
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
if [ ! -d '/tmp/phantomjs' ]; then
|
||||
_version="2.1.1"
|
||||
|
||||
curl -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$_version-windows.zip > /tmp/phantomjs-win.zip
|
||||
curl -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$_version-macosx.zip > /tmp/phantomjs-mac.zip
|
||||
|
||||
cd /tmp
|
||||
unzip /tmp/phantomjs-win.zip
|
||||
unzip /tmp/phantomjs-mac.zip
|
||||
|
||||
mkdir -p /tmp/phantomjs/windows /tmp/phantomjs/darwin
|
||||
|
||||
cp /tmp/phantomjs-$_version-windows/bin/phantomjs.exe /tmp/phantomjs/windows/phantomjs.exe
|
||||
cp /tmp/phantomjs-$_version-macosx/bin/phantomjs /tmp/phantomjs/darwin/phantomjs
|
||||
fi
|
||||
+57
-27
@@ -18,8 +18,15 @@ import (
|
||||
var apiUrl = flag.String("apiUrl", "https://grafana.com/api", "api url")
|
||||
var apiKey = flag.String("apiKey", "", "api key")
|
||||
var version = ""
|
||||
var versionRe = regexp.MustCompile(`grafana-(.*)\.(linux|windows)`)
|
||||
var versionRe = regexp.MustCompile(`grafana-(.*)(\.|_)(arm64|armv7|darwin|linux|windows|x86_64)`)
|
||||
var debVersionRe = regexp.MustCompile(`grafana_(.*)_(arm64|armv7|amd64)\.deb`)
|
||||
var builds = []build{}
|
||||
var architectureMapping = map[string]string{
|
||||
"amd64":"amd64",
|
||||
"armv7":"armv7",
|
||||
"arm64":"arm64",
|
||||
"x86_64":"amd64",
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
@@ -60,17 +67,54 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func packageWalker(path string, f os.FileInfo, err error) error {
|
||||
if f.Name() == "dist" || strings.Contains(f.Name(), "sha256") || strings.Contains(f.Name(), "latest") {
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Printf("Finding package file %s", f.Name())
|
||||
result := versionRe.FindSubmatch([]byte(f.Name()))
|
||||
func mapPackage(path string, name string, shaBytes []byte) (build, error) {
|
||||
log.Printf("Finding package file %s", name)
|
||||
result := versionRe.FindSubmatch([]byte(name))
|
||||
debResult := debVersionRe.FindSubmatch([]byte(name))
|
||||
|
||||
if len(result) > 0 {
|
||||
version = string(result[1])
|
||||
log.Printf("Version detected: %v", version)
|
||||
} else if (len(debResult) > 0) {
|
||||
version = string(debResult[1])
|
||||
}
|
||||
|
||||
os := ""
|
||||
if strings.Contains(name, "linux") {
|
||||
os = "linux"
|
||||
}
|
||||
if strings.HasSuffix(name, "windows-amd64.zip") {
|
||||
os = "win"
|
||||
}
|
||||
if strings.HasSuffix(name, "darwin-amd64.tar.gz") {
|
||||
os = "darwin"
|
||||
}
|
||||
if strings.HasSuffix(name, ".rpm") {
|
||||
os = "rhel"
|
||||
}
|
||||
if strings.HasSuffix(name, ".deb") {
|
||||
os = "deb"
|
||||
}
|
||||
|
||||
arch := ""
|
||||
for archListed, archReal := range architectureMapping {
|
||||
if strings.Contains(name, archListed) {
|
||||
arch = archReal
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return build{
|
||||
Os: os,
|
||||
Arch: arch,
|
||||
Url: "https://s3-us-west-2.amazonaws.com/grafana-releases/master/" + name,
|
||||
Sha256: string(shaBytes),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func packageWalker(path string, f os.FileInfo, err error) error {
|
||||
if f.Name() == "dist" || strings.Contains(f.Name(), "sha256") || strings.Contains(f.Name(), "latest") {
|
||||
return nil
|
||||
}
|
||||
|
||||
shaBytes, err := ioutil.ReadFile(path + ".sha256")
|
||||
@@ -78,27 +122,13 @@ func packageWalker(path string, f os.FileInfo, err error) error {
|
||||
log.Fatalf("Failed to read sha256 file %v", err)
|
||||
}
|
||||
|
||||
os := ""
|
||||
if strings.Contains(f.Name(), "linux-x64.tar.gz") {
|
||||
os = "linux"
|
||||
}
|
||||
if strings.HasSuffix(f.Name(), "windows-x64.zip") {
|
||||
os = "win"
|
||||
}
|
||||
if strings.HasSuffix(f.Name(), ".rpm") {
|
||||
os = "rhel"
|
||||
}
|
||||
if strings.HasSuffix(f.Name(), ".deb") {
|
||||
os = "deb"
|
||||
build, err := mapPackage(path, f.Name(), shaBytes)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
builds = append(builds, build{
|
||||
Os: os,
|
||||
Arch: "amd64",
|
||||
Url: "https://s3-us-west-2.amazonaws.com/grafana-releases/master/" + f.Name(),
|
||||
Sha256: string(shaBytes),
|
||||
})
|
||||
|
||||
builds = append(builds, build)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
type testPackage struct {
|
||||
path string
|
||||
version string
|
||||
os string
|
||||
arch string
|
||||
}
|
||||
|
||||
var testData = []testPackage{
|
||||
{
|
||||
path: "grafana-5.2.0-474pre1.arm64.rpm",
|
||||
version: "5.2.0-474pre1",
|
||||
os: "rhel",
|
||||
arch: "arm64",
|
||||
},
|
||||
{
|
||||
path: "grafana-5.2.0-474pre1.armv7.rpm",
|
||||
version: "5.2.0-474pre1",
|
||||
os: "rhel",
|
||||
arch: "armv7",
|
||||
},
|
||||
{
|
||||
path: "grafana-5.2.0-474pre1.darwin-amd64.tar.gz",
|
||||
version: "5.2.0-474pre1",
|
||||
os: "darwin",
|
||||
arch: "amd64",
|
||||
},
|
||||
{
|
||||
path: "grafana-5.2.0-474pre1.linux-amd64.tar.gz",
|
||||
version: "5.2.0-474pre1",
|
||||
os: "linux",
|
||||
arch: "amd64",
|
||||
},
|
||||
{
|
||||
path: "grafana-5.2.0-474pre1.linux-arm64.tar.gz",
|
||||
version: "5.2.0-474pre1",
|
||||
os: "linux",
|
||||
arch: "arm64",
|
||||
},
|
||||
{
|
||||
path: "grafana-5.2.0-474pre1.linux-armv7.tar.gz",
|
||||
version: "5.2.0-474pre1",
|
||||
os: "linux",
|
||||
arch: "armv7",
|
||||
},
|
||||
{
|
||||
path: "grafana-5.2.0-474pre1.windows-amd64.zip",
|
||||
version: "5.2.0-474pre1",
|
||||
os: "win",
|
||||
arch: "amd64",
|
||||
},
|
||||
{
|
||||
path: "grafana-5.2.0-474pre1.x86_64.rpm",
|
||||
version: "5.2.0-474pre1",
|
||||
os: "rhel",
|
||||
arch: "amd64",
|
||||
},
|
||||
{
|
||||
path: "grafana_5.2.0-474pre1_amd64.deb",
|
||||
version: "5.2.0-474pre1",
|
||||
os: "deb",
|
||||
arch: "amd64",
|
||||
},
|
||||
{
|
||||
path: "grafana_5.2.0-474pre1_arm64.deb",
|
||||
version: "5.2.0-474pre1",
|
||||
os: "deb",
|
||||
arch: "arm64",
|
||||
},
|
||||
{
|
||||
path: "grafana_5.2.0-474pre1_armv7.deb",
|
||||
version: "5.2.0-474pre1",
|
||||
os: "deb",
|
||||
arch: "armv7",
|
||||
},
|
||||
}
|
||||
|
||||
func TestFileWalker(t *testing.T) {
|
||||
for _, packageInfo := range testData {
|
||||
version = ""
|
||||
actualPackageInfo, err := mapPackage(packageInfo.path, packageInfo.path, []byte{})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
|
||||
if version != packageInfo.version {
|
||||
t.Errorf("Testing (%v), expected %v to be %v.", packageInfo.path, version, packageInfo.version)
|
||||
}
|
||||
|
||||
if actualPackageInfo.Os != packageInfo.os {
|
||||
t.Errorf("Testing (%v), expected %v to be %v.", packageInfo.path, actualPackageInfo.Os, packageInfo.os)
|
||||
}
|
||||
|
||||
if actualPackageInfo.Arch != packageInfo.arch {
|
||||
t.Errorf("Testing (%v), expected %v to be %v.", packageInfo.path, actualPackageInfo.Arch, packageInfo.arch)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,20 @@ var path = require('path');
|
||||
module.exports = function(grunt) {
|
||||
"use strict";
|
||||
|
||||
// build, then zip and upload to s3
|
||||
// build then zip
|
||||
grunt.registerTask('release', [
|
||||
'build',
|
||||
'build-post-process',
|
||||
'compress:release'
|
||||
]);
|
||||
|
||||
// package into archives
|
||||
grunt.registerTask('package', [
|
||||
'clean:temp',
|
||||
'build-post-process',
|
||||
'compress:release'
|
||||
]);
|
||||
|
||||
grunt.registerTask('build-post-process', function() {
|
||||
grunt.config('copy.public_to_temp', {
|
||||
expand: true,
|
||||
@@ -18,7 +25,7 @@ module.exports = function(grunt) {
|
||||
dest: '<%= tempDir %>/public/',
|
||||
});
|
||||
grunt.config('copy.backend_bin', {
|
||||
cwd: 'bin',
|
||||
cwd: 'bin/<%= platform %>-<%= arch %>',
|
||||
expand: true,
|
||||
src: ['*'],
|
||||
options: { mode: true},
|
||||
|
||||
Reference in New Issue
Block a user