Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deterministic gaia binaries #314

Merged
merged 4 commits into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Expand Down
48 changes: 29 additions & 19 deletions tasks/release.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,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)
}
})

Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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'
}
Expand All @@ -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=${platform} GOARCH=${arch} 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)
})
}
}