From f2b6a50f8a7d8904c5a934de1888e81aea86d2c9 Mon Sep 17 00:00:00 2001 From: David Braun Date: Mon, 19 Mar 2018 16:38:24 -0400 Subject: [PATCH] Use Docker in the build to fix #534. --- .circleci/config.yml | 6 ++--- .eslintrc.js | 1 + README.md | 25 ++++++++++++++++----- config.js | 1 - package.json | 7 ++---- tasks/build/.gitattributes | 2 ++ tasks/build/Dockerfile | 31 +++++++++++++++++++++++++ tasks/build/build.sh | 14 ++++++++++++ tasks/build/entrypoint.sh | 12 ++++++++++ tasks/release.js | 46 +++++++++++++++++++------------------- yarn.lock | 12 +++++----- 11 files changed, 113 insertions(+), 44 deletions(-) create mode 100644 tasks/build/.gitattributes create mode 100644 tasks/build/Dockerfile create mode 100755 tasks/build/build.sh create mode 100755 tasks/build/entrypoint.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 66a14eee20..001cfb1af9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/.eslintrc.js b/.eslintrc.js index bedfbefedc..21f1090678 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -6,6 +6,7 @@ module.exports = { }, env: { browser: true, + jest: true, node: true }, extends: 'standard', diff --git a/README.md b/README.md index d1dc8fca10..deb6cb6a06 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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| diff --git a/config.js b/config.js index f0ca296d52..0d5a273f0c 100644 --- a/config.js +++ b/config.js @@ -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' }, diff --git a/package.json b/package.json index eba705f88b..1b011e3036 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/tasks/build/.gitattributes b/tasks/build/.gitattributes new file mode 100644 index 0000000000..ae8075657a --- /dev/null +++ b/tasks/build/.gitattributes @@ -0,0 +1,2 @@ +# Use Unix line endings for text files because we're using Docker. +* text eol=lf diff --git a/tasks/build/Dockerfile b/tasks/build/Dockerfile new file mode 100644 index 0000000000..72d54b8665 --- /dev/null +++ b/tasks/build/Dockerfile @@ -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" ] diff --git a/tasks/build/build.sh b/tasks/build/build.sh new file mode 100755 index 0000000000..3009aca264 --- /dev/null +++ b/tasks/build/build.sh @@ -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 "$@" diff --git a/tasks/build/entrypoint.sh b/tasks/build/entrypoint.sh new file mode 100755 index 0000000000..c220aadc03 --- /dev/null +++ b/tasks/build/entrypoint.sh @@ -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 "$@" diff --git a/tasks/release.js b/tasks/release.js index bb63e65632..6c3a79ada6 100644 --- a/tasks/release.js +++ b/tasks/release.js @@ -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() } @@ -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) } }) } @@ -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) => { diff --git a/yarn.lock b/yarn.lock index 003c6d037c..9081137fb5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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: @@ -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" @@ -5388,7 +5388,7 @@ minimist@0.0.8: 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"