Skip to content

Commit

Permalink
Use Docker in the build to fix #534.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Braun authored and David Braun committed Mar 27, 2018
1 parent 7c80ca7 commit d709885
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 44 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
- node_modules
key: v1-dependencies-root-{{ checksum "package.json" }}

- run:
- run:
name: Add Gaia
command: |
sudo wget https://www.dropbox.com/s/vkyuut8hnzse614/gaia-0.5.0-linux-32?dl=1 -O ~/repo/gaia
sudo wget https://tendermint-packages.interblock.io/binaries/gaia_linux_amd64/gaia_decb23bed0179244e4f42d697dcd4bf759200a2d -O ~/repo/gaia
sudo chmod o+wx /home/circleci/repo/gaia
- run: yarn run test
- run: bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
env: {
browser: true,
jest: true,
node: true
},
extends: 'standard',
Expand Down
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,33 @@ $ COSMOS_NODE=localhost yarn testnet
---

### Production
Get the Gaia binary from [GitHub](`https://github.com/cosmos/gaia/releases`).

Install [Docker](https://docs.docker.com/get-started/).
Building requires that [Docker](https://www.docker.com/get-docker) is installed
on your system.

Build and run the app.
Build the app:

The first argument is a commit for Voyager (e.g., the tag `0.4.3`). Other
arguments (such as `--platform`) must come afterwards.

```bash
yarn run build 0.4.3 --platform={darwin|win32|linux}
```

You can specify a commit hash for the version of Gaia to use if it has been prebuilt:

```bash
GAIA_COMMIT=decb23bed0179244e4f42d697dcd4bf759200a2d yarn run build 0.4.3 --platform=darwin
```

Run the app.
```bash
yarn run build --platform={darwin|win32|linux} -- --binary={path to the gaia binary}
open builds/Cosmos-{platform}-x64/Cosmos.app
```

When you are testing the build system you can skip the repackaging of the JS files.
```bash
$ yarn run build --platform={darwin|win32|linux} --skip-pack --binary=...
$ yarn run build 0.4.3 --platform=darwin --skip-pack
```

To test if your build worked run:
Expand Down Expand Up @@ -157,7 +171,6 @@ A list of all environment variables and their purpose:
|COSMOS_NETWORK|{path to network configuration folder}|'../networks/gaia-1'|Network to connect to|
|COSMOS_HOME|{path to config persistence folder}|'$HOME/voyager[-dev]'||
|COSMOS_NODE|{ip of a certain node}||Node to connect to|
|PLATFORM_TARGET|'all', 'win32', 'darwin', 'linux', 'mas'|'all'|Which platform to build for|
|COSMOS_DEVTOOLS|'true', 'false'|'false'|Open the debug panel in the electron view|
|ELECTRON_ENABLE_LOGGING|'true', 'false'|'false'|Redirect the browser view console output to the console|
|PREVIEW|'true', 'false'|'true' if NODE_ENV 'development'|Show/Hide features that are in development|
Expand Down
1 change: 0 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ let config = {
ignore: /^\/(src|index\.ejs|icons)/,
out: path.join(__dirname, 'builds'),
overwrite: true,
platform: process.env.PLATFORM_TARGET || 'darwin,linux,win32',
packageManager: 'yarn'
},

Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
"node": ">=9.4.0"
},
"scripts": {
"build:clean": "cross-env PLATFORM_TARGET=clean node tasks/release.js",
"build:darwin": "cross-env PLATFORM_TARGET=darwin node tasks/release.js",
"build:linux": "cross-env PLATFORM_TARGET=linux node tasks/release.js",
"build:mas": "cross-env PLATFORM_TARGET=mas node tasks/release.js",
"build:win32": "cross-env PLATFORM_TARGET=win32 node tasks/release.js",
"build": "cd tasks/build && sh ./build.sh",
"local": "yarn run testnet local",
"testnet": "node tasks/testnet.js",
"lint": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter app test",
Expand Down Expand Up @@ -69,6 +65,7 @@
"json-loader": "0.5.4",
"lodash": "4.17.4",
"markdown-it": "8.3.2",
"minimist": "1.2.0",
"mkdirp": "0.5.1",
"moment-timezone": "0.5.13",
"node-loader": "0.6.0",
Expand Down
2 changes: 2 additions & 0 deletions tasks/build/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Use Unix line endings for text files because we're using Docker.
* text eol=lf
31 changes: 31 additions & 0 deletions tasks/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM node:9.4.0

# Install Wine so that we can build for the 'win32' platform.
# https://wiki.debian.org/Wine#Installation_on_Debian_Jessie_and_newer
RUN dpkg --add-architecture i386 \
&& apt-get update \
&& apt-get --yes install \
wine \
wine32 \
libwine


# Download Gaia.

# Use v0.5.0 by default.
ARG GAIA_COMMIT=decb23bed0179244e4f42d697dcd4bf759200a2d

ARG platforms="darwin linux windows"
RUN mkdir /gaia

RUN cd /gaia && \
for platform in $platforms; \
do wget --output-document=$platform \
https://tendermint-packages.interblock.io/binaries/gaia_${platform}_amd64/gaia_${GAIA_COMMIT}; \
done


COPY entrypoint.sh /
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ENTRYPOINT [ "/entrypoint.sh" ]
14 changes: 14 additions & 0 deletions tasks/build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
set -o errexit
set -o xtrace

docker build --build-arg GAIA_COMMIT --tag cosmos/voyager-builder .
mkdir -p ../../builds

docker run \
--interactive \
--mount type=bind,readonly,source=$(pwd)/../../.git,target=/.git \
--mount type=bind,source=$(pwd)/../../builds,target=/builds \
--rm \
--tty \
cosmos/voyager-builder "$@"
12 changes: 12 additions & 0 deletions tasks/build/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
set -o errexit

git clone /.git .

# Use the specified commit of Voyager.
git checkout "$1"
shift

ln --symbolic /builds
yarn install
node tasks/release.js --binary=/gaia/linux "$@"
46 changes: 23 additions & 23 deletions tasks/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,37 @@ const packager = require('electron-packager')
const fs = require('fs-extra')
var glob = require('glob')
var JSZip = require('jszip')
const minimist = require('minimist')
const zlib = require('zlib')
var tar = require('tar-stream')
var duplexer = require('duplexer')
const packageJson = require('../package.json')

let skipPack = false
let binaryPath = null
process.argv.forEach(function (val) {
if (val === '--skip-pack') {
console.log('Skipping packaging')
skipPack = true
}
if (val.startsWith('--binary')) {
binaryPath = val.replace('--binary=', '')
fs.accessSync(binaryPath)
console.log('Using prebuilt binary', binaryPath)
}
})
const {
binary: binaryPath,
platform,
'skip-pack': skipPack
} = minimist(process.argv.slice(2))

if (!binaryPath) {
if (binaryPath) {
fs.accessSync(binaryPath)
console.log('Using prebuilt binary', binaryPath)
} else {
console.error(`\x1b[31mPlease specify a gaia binary for this platform using the "--binary" flag
Example: npm run build:darwin -- --binary=./gaia
Example: node tasks/release.js --binary=./gaia
\x1b[0m`)
process.exit(1)
}

if (process.env.PLATFORM_TARGET === 'clean') {
if (platform === 'clean') {
require('del').sync(['builds/*', '!.gitkeep'])
console.log('\x1b[33m`builds` directory cleaned.\n\x1b[0m')
} else {
console.log(`Building for platform "${platform}".`)

if (skipPack) {
build(process.env.PLATFORM_TARGET)
console.log('Skipping packaging')
build(platform)
} else {
pack()
}
Expand All @@ -55,7 +54,7 @@ function pack () {
pack.stderr.on('data', data => console.error(data))
pack.on('exit', code => {
if (code === null || code <= 0) {
build(process.env.PLATFORM_TARGET)
build(platform)
}
})
}
Expand All @@ -64,11 +63,12 @@ function pack () {
* Use electron-packager to build electron app
*/
function build (platform) {
let options = require('../config').building

options.afterCopy = [
copyBinary('gaia', binaryPath)
]
let options = Object.assign({}, require('../config').building, {
afterCopy: [
copyBinary('gaia', binaryPath)
],
platform
})

console.log('\x1b[34mBuilding electron app(s)...\n\x1b[0m')
packager(options, async (err, appPaths) => {
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ babel-core@^6.0.0, babel-core@^6.26.0, babel-core@^6.8.0:
slash "^1.0.0"
source-map "^0.5.6"

babel-eslint@^7.0.0:
babel-eslint@^7.2.3:
version "7.2.3"
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-7.2.3.tgz#b2fe2d80126470f5c19442dc757253a897710827"
dependencies:
Expand Down Expand Up @@ -2788,11 +2788,11 @@ eslint-plugin-html@^4.0.2:
dependencies:
htmlparser2 "^3.8.2"

eslint-plugin-promise@^3.4.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-3.6.0.tgz#54b7658c8f454813dc2a870aff8152ec4969ba75"
eslint-plugin-promise@^3.6.0:
version "3.7.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-3.7.0.tgz#f4bde5c2c77cdd69557a8f69a24d1ad3cfc9e67e"

eslint-plugin-standard@^2.0.1:
eslint-plugin-standard@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-standard/-/eslint-plugin-standard-2.3.1.tgz#6765bd2a6d9ecdc7bdf1b145ae4bb30e2b7b86f8"

Expand Down Expand Up @@ -5388,7 +5388,7 @@ [email protected]:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0, minimist@~1.2.0:
minimist@1.2.0, minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0, minimist@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"

Expand Down

0 comments on commit d709885

Please sign in to comment.