From 5fe03e7d4035c51afb0655bbb150454fc0240946 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Tue, 2 Jan 2018 22:09:47 -0800 Subject: [PATCH 1/2] Use docker to deterministically build gaia binary on release --- tasks/release.js | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/tasks/release.js b/tasks/release.js index fa76dee103..95bb4c45a2 100644 --- a/tasks/release.js +++ b/tasks/release.js @@ -1,11 +1,12 @@ 'use strict' const { exec } = require('child_process') -const path = require('path') +const { join } = require('path') const packager = require('electron-packager') const rebuild = require('electron-rebuild').default const mkdirp = require('mkdirp').sync const fs = require('fs-extra') +const { promisify } = require('util') let skipPack = false let binaryPath = null @@ -56,7 +57,7 @@ function build () { options.afterCopy = [ binaryPath ? copyBinary('gaia', binaryPath) - : goBuild(`github.com/cosmos/gaia/cmd/gaia`) + : buildGaiaBinary() ] // prune installs the packages options.afterPrune = [ @@ -84,7 +85,7 @@ function build () { function copyBinary (name, binaryLocation) { return function (buildPath, electronVersion, platform, arch, cb) { - let binPath = path.join(buildPath, 'bin', name) + let binPath = join(buildPath, 'bin', name) if (platform === 'win32') { binPath = binPath + '.exe' } @@ -98,29 +99,38 @@ const GOARCH = { 'ia32': '386' } -function goBuild (pkg) { +function buildGaiaBinary () { return function (buildPath, electronVersion, platform, arch, cb) { if (platform === 'win32') platform = 'windows' if (platform === 'mas') platform = 'darwin' if (GOARCH[arch]) arch = GOARCH[arch] - let name = path.basename(pkg) - console.log(`\x1b[34mBuilding ${name} binary (${platform}/${arch})...\n\x1b[0m`) + console.log(`\x1b[34mBuilding gaia binary (${platform}/${arch})...\n\x1b[0m`) - mkdirp(path.join(buildPath, 'bin')) - let binPath = path.join(buildPath, 'bin', name) - if (platform === 'windows') { - binPath = binPath + '.exe' - } - let cmd = `cross-env GOOS=${platform} GOARCH=${arch} go build -o ${binPath} ${pkg}` - console.log(`> ${cmd}\n`) - let go = exec(cmd) + let output = 'gaia' + if (platform === 'windows') output += '.exe' - go.stdout.on('data', (data) => process.stdout.write(data)) - go.stderr.on('data', (data) => process.stderr.write(data)) - go.once('exit', (code) => { + let cmd = ` + docker run -v "/tmp:/mnt" golang bash -c " + go get github.com/cosmos/gaia; + cd /go/src/github.com/cosmos/gaia && \ + git checkout develop && \ + make get_vendor_deps && \ + GOOS=darwin GOARCH=amd64 go build \ + -o /mnt/${output} \ + -ldflags '-s -w' \ + ./cmd/gaia + " + ` + let docker = exec(cmd) + docker.stdout.on('data', (data) => process.stdout.write(data)) + docker.stderr.on('data', (data) => process.stderr.write(data)) + docker.once('exit', (code) => { if (code !== 0) return cb(Error('Build failed')) - cb() + + let binPath = join(buildPath, 'bin') + mkdirp(binPath) + fs.copy(join('/tmp', output), join(binPath, output), cb) }) } } From b5fce376a5bfd1dfed91a47e0439e7a0442189c6 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Wed, 3 Jan 2018 07:35:16 -0800 Subject: [PATCH 2/2] Fixed docker release script for multiple platforms, enable windows builds by default --- config.js | 2 +- tasks/release.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config.js b/config.js index 61e6cfe77d..176ef04547 100644 --- a/config.js +++ b/config.js @@ -24,7 +24,7 @@ let config = { ignore: /^\/(src|index\.ejs|icons)/, out: path.join(__dirname, 'builds'), overwrite: true, - platform: process.env.PLATFORM_TARGET || 'darwin,linux', + platform: process.env.PLATFORM_TARGET || 'darwin,linux,windows', packageManager: 'yarn' } } diff --git a/tasks/release.js b/tasks/release.js index 95bb4c45a2..4e70ba6432 100644 --- a/tasks/release.js +++ b/tasks/release.js @@ -17,7 +17,7 @@ process.argv.forEach(function (val) { } if (val.startsWith('--binary')) { binaryPath = val.replace('--binary=', '') - console.log('Using build binary', binaryPath) + console.log('Using prebuilt binary', binaryPath) } }) @@ -116,7 +116,7 @@ function buildGaiaBinary () { cd /go/src/github.com/cosmos/gaia && \ git checkout develop && \ make get_vendor_deps && \ - GOOS=darwin GOARCH=amd64 go build \ + GOOS=${platform} GOARCH=${arch} go build \ -o /mnt/${output} \ -ldflags '-s -w' \ ./cmd/gaia