From 52032aac14552bb37d96f37479babc46147ea43f Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 17 Feb 2020 20:10:58 +0000 Subject: [PATCH] Docker powered linux building --- .gitignore | 1 + README | 3 ++ dockerbuild/Dockerfile | 10 ++++++ hak/matrix-seshat/build.js | 16 +++++---- hak/matrix-seshat/check.js | 26 +++++++------- hak/matrix-seshat/fetchDeps.js | 4 ++- package.json | 2 ++ scripts/hak/build.js | 2 +- scripts/hak/index.js | 64 ++++++++++++++++++---------------- scripts/in-docker.sh | 11 ++++-- 10 files changed, 86 insertions(+), 53 deletions(-) create mode 100644 dockerbuild/Dockerfile diff --git a/.gitignore b/.gitignore index e992cc5..d9931d1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /pkg/control /.hak /.yarnrc +/docker diff --git a/README b/README index faa8140..14cea3d 100644 --- a/README +++ b/README @@ -61,6 +61,9 @@ This will do a couple of things: You can also build using docker, which will always produce the linux package: ``` +# Run this once to make the docker image +yarn run docker:setup + yarn run docker:install yarn run docker:build ``` diff --git a/dockerbuild/Dockerfile b/dockerbuild/Dockerfile new file mode 100644 index 0000000..6ef8d0d --- /dev/null +++ b/dockerbuild/Dockerfile @@ -0,0 +1,10 @@ +FROM electronuserland/builder:12 + +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH + +RUN apt-get update && \ + apt-get install -y libsqlcipher-dev && \ + rm -rf /var/lib/apt/lists/* && \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal diff --git a/hak/matrix-seshat/build.js b/hak/matrix-seshat/build.js index 5345fc3..2efe4aa 100644 --- a/hak/matrix-seshat/build.js +++ b/hak/matrix-seshat/build.js @@ -24,7 +24,7 @@ module.exports = async function(hakEnv, moduleInfo) { if (hakEnv.isWin()) { await buildOpenSslWin(hakEnv, moduleInfo); await buildSqlCipherWin(hakEnv, moduleInfo); - } else { + } else if (hakEnv.isMac()) { await buildSqlCipherUnix(hakEnv, moduleInfo); } await buildMatrixSeshat(hakEnv, moduleInfo); @@ -228,11 +228,15 @@ async function buildSqlCipherUnix(hakEnv, moduleInfo) { } async function buildMatrixSeshat(hakEnv, moduleInfo) { - const env = Object.assign({ - SQLCIPHER_STATIC: 1, - SQLCIPHER_LIB_DIR: path.join(moduleInfo.depPrefix, 'lib'), - SQLCIPHER_INCLUDE_DIR: path.join(moduleInfo.depPrefix, 'include'), - }, hakEnv.makeGypEnv()); + const env = hakEnv.makeGypEnv(); + + if (!hakEnv.isLinux()) { + Object.assign(env, { + SQLCIPHER_STATIC: 1, + SQLCIPHER_LIB_DIR: path.join(moduleInfo.depPrefix, 'lib'), + SQLCIPHER_INCLUDE_DIR: path.join(moduleInfo.depPrefix, 'include'), + }); + } if (hakEnv.isWin()) { env.RUSTFLAGS = '-Ctarget-feature=+crt-static -Clink-args=libcrypto.lib'; diff --git a/hak/matrix-seshat/check.js b/hak/matrix-seshat/check.js index ff88ed1..6a65970 100644 --- a/hak/matrix-seshat/check.js +++ b/hak/matrix-seshat/check.js @@ -18,19 +18,21 @@ const childProcess = require('child_process'); module.exports = async function(hakEnv, moduleInfo) { // of course tcl doesn't have a --version - await new Promise((resolve, reject) => { - const proc = childProcess.spawn('tclsh', [], { - stdio: ['pipe', 'ignore', 'ignore'], + if (!hakEnv.isLinux()) { + await new Promise((resolve, reject) => { + const proc = childProcess.spawn('tclsh', [], { + stdio: ['pipe', 'ignore', 'ignore'], + }); + proc.on('exit', (code) => { + if (code !== 0) { + reject("Can't find tclsh - have you installed TCL?"); + } else { + resolve(); + } + }); + proc.stdin.end(); }); - proc.on('exit', (code) => { - if (code !== 0) { - reject("Can't find tclsh - have you installed TCL?"); - } else { - resolve(); - } - }); - proc.stdin.end(); - }); + } const tools = []; if (hakEnv.isWin()) { diff --git a/hak/matrix-seshat/fetchDeps.js b/hak/matrix-seshat/fetchDeps.js index 7d97266..a628ec8 100644 --- a/hak/matrix-seshat/fetchDeps.js +++ b/hak/matrix-seshat/fetchDeps.js @@ -23,7 +23,9 @@ const needle = require('needle'); const tar = require('tar'); module.exports = async function(hakEnv, moduleInfo) { - await getSqlCipher(hakEnv, moduleInfo); + if (!hakEnv.isLinux()) { + await getSqlCipher(hakEnv, moduleInfo); + } if (hakEnv.isWin()) { getOpenSsl(hakEnv, moduleInfo); diff --git a/package.json b/package.json index b131a31..624e511 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,8 @@ "lint": "eslint src/ scripts/ hak/", "build": "yarn run setversion && electron-builder", "in-docker": "scripts/in-docker.sh", + "docker:setup": "docker build -t riot-desktop-dockerbuild dockerbuild", + "docker:buildnative": "yarn run in-docker yarn run hak", "docker:build": "yarn run in-docker yarn run build", "docker:install": "yarn run in-docker yarn install", "debrepo": "scripts/mkrepo.sh", diff --git a/scripts/hak/build.js b/scripts/hak/build.js index 8249d19..da685df 100644 --- a/scripts/hak/build.js +++ b/scripts/hak/build.js @@ -15,7 +15,7 @@ limitations under the License. */ async function build(hakEnv, moduleInfo) { - moduleInfo.scripts.build(hakEnv, moduleInfo); + await moduleInfo.scripts.build(hakEnv, moduleInfo); } module.exports = build; diff --git a/scripts/hak/index.js b/scripts/hak/index.js index 8737517..cfb75c0 100644 --- a/scripts/hak/index.js +++ b/scripts/hak/index.js @@ -89,45 +89,47 @@ async function main() { } } + let cmds; if (process.argv.length < 3) { - console.log("Usage: hak [modules...]"); - process.exit(1); + cmds = ['check', 'fetch', 'fetchDeps', 'build', 'copy', 'link']; + } else { + cmds = [process.argv[2]]; } - const cmd = process.argv[2]; - if (GENERALCOMMANDS.includes(cmd)) { - if (cmd === 'target') { - console.log(hakEnv.getNodeTriple()); - } - return; - } - - if (!MODULECOMMANDS.includes(cmd)) { - console.error("Unknown command: " + cmd); - console.log("Commands I know about:"); - for (const cmd of MODULECOMMANDS) { - console.log("\t" + cmd); - } - process.exit(1); - } - - const cmdFunc = require('./' + cmd); - let modules = process.argv.slice(3); - if (modules.length === 0) modules = Object.keys(deps); - for (const mod of modules) { - const depInfo = deps[mod]; - if (depInfo === undefined) { - console.log( - "Module " + mod + " not found - is it in hakDependencies " + - "in your package.json?", - ); + for (const cmd of cmds) { + if (GENERALCOMMANDS.includes(cmd)) { + if (cmd === 'target') { + console.log(hakEnv.getNodeTriple()); + } + return; + } + + if (!MODULECOMMANDS.includes(cmd)) { + console.error("Unknown command: " + cmd); + console.log("Commands I know about:"); + for (const cmd of MODULECOMMANDS) { + console.log("\t" + cmd); + } process.exit(1); } - console.log("hak " + cmd + ": " + mod); - await cmdFunc(hakEnv, depInfo); + + const cmdFunc = require('./' + cmd); + + for (const mod of modules) { + const depInfo = deps[mod]; + if (depInfo === undefined) { + console.log( + "Module " + mod + " not found - is it in hakDependencies " + + "in your package.json?", + ); + process.exit(1); + } + console.log("hak " + cmd + ": " + mod); + await cmdFunc(hakEnv, depInfo); + } } } diff --git a/scripts/in-docker.sh b/scripts/in-docker.sh index 7b2d908..bab0e26 100755 --- a/scripts/in-docker.sh +++ b/scripts/in-docker.sh @@ -1,12 +1,19 @@ #!/bin/bash +docker inspect riot-desktop-dockerbuild 2> /dev/null > /dev/null +if [ $? != 0 ]; then + echo "Docker image riot-desktop-builder not found. Have you run yarn run docker:setup?" + exit 1 +fi + # Taken from https://www.electron.build/multi-platform-build#docker docker run --rm -ti \ --env-file <(env | grep -iE 'DEBUG|NODE_|ELECTRON_|YARN_|NPM_|CI|CIRCLE|TRAVIS_TAG|TRAVIS|TRAVIS_REPO_|TRAVIS_BUILD_|TRAVIS_BRANCH|TRAVIS_PULL_REQUEST_|APPVEYOR_|CSC_|GH_|GITHUB_|BT_|AWS_|STRIP|BUILD_') \ --env ELECTRON_CACHE="/root/.cache/electron" \ --env ELECTRON_BUILDER_CACHE="/root/.cache/electron-builder" \ -v ${PWD}:/project \ - -v ${PWD}/docker_node_modules:/project/node_modules \ + -v ${PWD}/docker/node_modules:/project/node_modules \ + -v ${PWD}/docker/.hak:/project/.hak \ -v ~/.cache/electron:/root/.cache/electron \ -v ~/.cache/electron-builder:/root/.cache/electron-builder \ - electronuserland/builder "$@" + riot-desktop-dockerbuild "$@"