From f343def050d78f22978c9224c054d0501ea4d21c Mon Sep 17 00:00:00 2001 From: develar Date: Mon, 26 Dec 2016 19:04:09 +0100 Subject: [PATCH] feat(snaps): build snaps on macOs #509 --- .idea/dictionaries/develar.xml | 2 ++ docker/6/Dockerfile | 10 +--------- docker/7/Dockerfile | 10 +--------- docker/base/Dockerfile | 26 +++++--------------------- package.json | 2 +- src/metadata.ts | 4 ++++ src/options/linuxOptions.ts | 2 +- src/targets/fpm.ts | 4 ++-- src/targets/snap.ts | 27 +++++++++++++-------------- test/jestSetup.js | 6 ++++-- test/src/linux/snapTest.ts | 4 ++-- test/typings/jest-ex.d.ts | 1 + yarn.lock | 10 +++++----- 13 files changed, 42 insertions(+), 66 deletions(-) diff --git a/.idea/dictionaries/develar.xml b/.idea/dictionaries/develar.xml index e7e3d47c0f4..382ab3c3f86 100644 --- a/.idea/dictionaries/develar.xml +++ b/.idea/dictionaries/develar.xml @@ -97,6 +97,7 @@ langs lcid libappindicator + libasound libdbusmenu libexec libgconf @@ -193,6 +194,7 @@ xamarin xenial xorriso + xubuntu yargs zenity zisofs diff --git a/docker/6/Dockerfile b/docker/6/Dockerfile index d0409ef6bb1..2623b2a9b66 100644 --- a/docker/6/Dockerfile +++ b/docker/6/Dockerfile @@ -1,12 +1,4 @@ FROM electronuserland/electron-builder:base -ENV NODE_VERSION 6.9.2 - # https://github.com/npm/npm/issues/4531 -RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \ - && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \ - && gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \ - && grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \ - && tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \ - && rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \ - && curl -L https://npmjs.org/install.sh | sh && npm cache clean && npm config set unsafe-perm true && npm completion >> ~/.bashrc \ No newline at end of file +RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - && apt-get install -y nodejs && curl -L https://npmjs.org/install.sh | sh && npm cache clean && npm config set unsafe-perm true && npm completion >> ~/.bashrc && apt-get clean && rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/docker/7/Dockerfile b/docker/7/Dockerfile index e8d9cd73444..de63834ade3 100644 --- a/docker/7/Dockerfile +++ b/docker/7/Dockerfile @@ -1,12 +1,4 @@ FROM electronuserland/electron-builder:base -ENV NODE_VERSION 7.3.0 - # https://github.com/npm/npm/issues/4531 -RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \ - && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \ - && gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \ - && grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \ - && tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \ - && rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \ - && curl -L https://npmjs.org/install.sh | sh && npm cache clean && npm config set unsafe-perm true && npm completion >> ~/.bashrc \ No newline at end of file +RUN curl -sL https://deb.nodesource.com/setup_7.x | bash - && apt-get install -y nodejs && curl -L https://npmjs.org/install.sh | sh && npm cache clean && npm config set unsafe-perm true && npm completion >> ~/.bashrc && apt-get clean && rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/docker/base/Dockerfile b/docker/base/Dockerfile index 6931ae0a9b7..304b73944d0 100644 --- a/docker/base/Dockerfile +++ b/docker/base/Dockerfile @@ -1,4 +1,4 @@ -FROM buildpack-deps:xenial-curl +FROM buildpack-deps:yakkety-curl # rpm is required for FPM to build rpm package # yasm is required to build p7zip @@ -15,30 +15,14 @@ ENV USE_SYSTEM_7ZA true ENV DEBUG_COLORS true ENV FORCE_COLOR true -RUN curl -L https://yarnpkg.com/latest.tar.gz | tar xvz && mv dist yarn && ln -s /yarn/bin/yarn /usr/local/bin/yarn && apt-get update -y && \ - apt-get install --no-install-recommends -y git snapcraft qtbase5-dev xorriso bsdtar build-essential autoconf libssl-dev icnsutils graphicsmagick gcc-multilib g++-multilib libgnome-keyring-dev lzip rpm yasm && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* && \ +RUN curl -L https://yarnpkg.com/latest.tar.gz | tar xvz && mv dist yarn && apt-get update -y && apt-get upgrade -y && \ + apt-get install --no-install-recommends -y nodejs git snapcraft qtbase5-dev xorriso bsdtar build-essential autoconf libssl-dev icnsutils graphicsmagick gcc-multilib g++-multilib libgnome-keyring-dev lzip rpm yasm && \ + apt-get clean && rm -rf /var/lib/apt/lists/* && \ curl -L http://tukaani.org/xz/xz-$XZ_VERSION.tar.xz | tar -xJ && cd xz-$XZ_VERSION && ./configure && make && make install && cd .. && rm -rf xz-$XZ_VERSION && ldconfig && \ mkdir -p /tmp/7z && curl -L http://downloads.sourceforge.net/project/p7zip/p7zip/16.02/p7zip_16.02_src_all.tar.bz2 | tar -xj -C /tmp/7z --strip-components 1 && cd /tmp/7z && cp makefile.linux_amd64_asm makefile.machine && make && make install && rm -rf /tmp/7z COPY test.sh /test.sh -# nodejs keys -RUN set -ex \ - && for key in \ - 9554F04D7259F04124DE6B476D5A82AC7E37093B \ - 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ - 0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \ - FD3A5288F042B6850C66B31F09FE44734EB7990E \ - 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \ - DD8F2338BAE7501E3DD5AC78C273792F7D83545D \ - B9AE9905FFD7803F25714661B63B535A4C206CA9 \ - C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ - ; do \ - gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ - done - WORKDIR /project # fix error /usr/local/bundle/gems/fpm-1.5.0/lib/fpm/package/freebsd.rb:72:in `encode': "\xE2" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError) @@ -48,4 +32,4 @@ RUN locale-gen en_US.UTF-8 ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 -ENV PATH "$HOME/.yarn/bin:$PATH" \ No newline at end of file +ENV PATH "/yarn/bin:$PATH" \ No newline at end of file diff --git a/package.json b/package.json index 134528f16a8..5e79559984d 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "chromium-pickle-js": "^0.2.0", "cli-cursor": "^1.0.2", "cuint": "^0.2.2", - "debug": "2.5.1", + "debug": "2.5.2", "electron-download-tf": "3.1.0", "electron-macos-sign": "^1.3.4", "fs-extra-p": "^3.0.3", diff --git a/src/metadata.ts b/src/metadata.ts index a90e3b894e2..b00c03b7baf 100755 --- a/src/metadata.ts +++ b/src/metadata.ts @@ -414,6 +414,10 @@ export enum Arch { ia32, x64, armv7l } +export function toLinuxArchString(arch: Arch) { + return arch === Arch.ia32 ? "i386" : (arch === Arch.x64 ? "amd64" : "armv7l") +} + export function archFromString(name: string): Arch { if (name === "x64") { return Arch.x64 diff --git a/src/options/linuxOptions.ts b/src/options/linuxOptions.ts index f8dc4456739..b205790b25b 100644 --- a/src/options/linuxOptions.ts +++ b/src/options/linuxOptions.ts @@ -101,7 +101,7 @@ export interface SnapOptions extends LinuxBuildOptions { /* The list of Ubuntu packages to use that are needed to support the `app` part creation. Like `depends` for `deb`. - Defaults to `["libnotify4", "libappindicator1", "libxtst6", "libnss3", "fontconfig-config"]`. + Defaults to `["libnotify4", "libappindicator1", "libxtst6", "libnss3", "libxss1", "fontconfig-config", "gconf2", "libasound2"]`. */ stagePackages?: Array | null diff --git a/src/targets/fpm.ts b/src/targets/fpm.ts index 0cc6877445a..af3eff0d758 100644 --- a/src/targets/fpm.ts +++ b/src/targets/fpm.ts @@ -1,4 +1,4 @@ -import { Arch } from "../metadata" +import { Arch, toLinuxArchString } from "../metadata" import { smarten } from "../platformPackager" import { use, exec } from "../util/util" import * as path from "path" @@ -95,7 +95,7 @@ export default class FpmTarget extends Target { const args = [ "-s", "dir", "-t", target, - "--architecture", arch === Arch.ia32 ? "i386" : (arch === Arch.x64 ? "amd64" : "armv7l"), + "--architecture", toLinuxArchString(arch), "--name", appInfo.name, "--force", "--after-install", scripts[0], diff --git a/src/targets/snap.ts b/src/targets/snap.ts index 991aeeed0f7..1b5d2decdfb 100644 --- a/src/targets/snap.ts +++ b/src/targets/snap.ts @@ -1,10 +1,10 @@ import { toDebArch } from "../platformPackager" -import { Arch } from "../metadata" +import { Arch, toLinuxArchString } from "../metadata" import { LinuxTargetHelper } from "./LinuxTargetHelper" import { LinuxPackager } from "../linuxPackager" import { log } from "../util/log" import { SnapOptions } from "../options/linuxOptions" -import { emptyDir, writeFile, rename, copy } from "fs-extra-p" +import { emptyDir, writeFile, copy } from "fs-extra-p" import * as path from "path" import { safeDump } from "js-yaml" import { spawn } from "../util/util" @@ -81,12 +81,13 @@ export default class SnapTarget extends Target { } } + // libxss1, libasound2, gconf2 - was "error while loading shared libraries: libXss.so.1" on Xubuntu 16.04 const isUseDocker = process.platform !== "linux" snap.parts = { app: { plugin: "dump", - "stage-packages": options.stagePackages || (isUseUbuntuPlatform ? ["libnss3"] : ["libnotify4", "libappindicator1", "libxtst6", "libnss3", "fontconfig-config"]), - source: isUseDocker ? `/out/${path.basename(snapDir)}` : appOutDir, + "stage-packages": options.stagePackages || (isUseUbuntuPlatform ? ["libnss3"] : ["libnotify4", "libappindicator1", "libxtst6", "libnss3", "libxss1", "fontconfig-config", "gconf2", "libasound2"]), + source: isUseDocker ? `/out/${path.basename(appOutDir)}` : appOutDir, after: isUseUbuntuPlatform ? ["extra", "desktop-ubuntu-app-platform"] : ["desktop-glib-only"] } } @@ -101,30 +102,28 @@ export default class SnapTarget extends Target { const snapcraft = path.join(snapDir, "snapcraft.yaml") await writeFile(snapcraft, safeDump(snap, {lineWidth: 160})) - // const args = ["snapcraft", path.relative(snapDir)] - // snap /out/${path.basename(snapDir)} --output /out/${path.basename(resultFile)} + const snapName = `${snap.name}_${snap.version}_${toDebArch(arch)}.snap` + const resultFile = path.join(this.outDir, snapName) + if (isUseDocker) { await spawn("docker", ["run", "--rm", "-v", `${packager.info.projectDir}:/project`, + "-v", `/tmp/apt-cache:/var/cache/apt/archives`, "-v", `${homedir()}/.electron:/root/.electron`, // dist dir can be outside of project dir "-v", `${this.outDir}:/out`, - "-w", `/out/${path.basename(snapDir)}`, "electronuserland/electron-builder:latest", - "/bin/bash", "-c", `env && snapcraft snap`], { + "/bin/bash", "-c", `snapcraft --version && cp -R /out/${path.basename(snapDir)} /s/ && cd /s && snapcraft snap --target-arch ${toLinuxArchString(arch)} -o /out/${snapName}`], { cwd: packager.info.projectDir, + stdio: ["ignore", "inherit", "pipe"], }) } else { - await spawn("snapcraft", ["snap"], { + await spawn("snapcraft", ["snap", "--target-arch", toLinuxArchString(arch), "-o", resultFile], { cwd: snapDir, - stdio: ["ignore", "inherit", "pipe"] + stdio: ["ignore", "inherit", "pipe"], }) } - - const snapName = `${snap.name}_${snap.version}_${toDebArch(arch)}.snap` - const resultFile = path.join(this.outDir, snapName) - await rename(path.join(snapDir, snapName), resultFile) packager.dispatchArtifactCreated(resultFile) } } \ No newline at end of file diff --git a/test/jestSetup.js b/test/jestSetup.js index 26f27872f21..aaf371d6e8f 100644 --- a/test/jestSetup.js +++ b/test/jestSetup.js @@ -17,7 +17,8 @@ if (process.env.RUN_IN_BAND !== "true") { // test = it } -test.ifMac = process.platform === "darwin" ? test : skip +const isMac = process.platform === "darwin" +test.ifMac = isMac ? test : skip test.ifNotWindows = isWindows ? skip : test if (isCi) { @@ -29,13 +30,14 @@ else { test.ifNotCi = test } -test.ifNotCiMac = isCi && process.platform === "darwin" ? skip : test +test.ifNotCiMac = isCi && isMac ? skip : test test.ifNotCiWin = isCi && isWindows ? skip : test test.ifDevOrWinCi = !isCi || isWindows ? test : skip test.ifDevOrLinuxCi = !isCi || process.platform === "linux" ? test : skip test.ifWinCi = isCi && isWindows ? test : skip test.ifLinux = process.platform === "linux" ? test : skip +test.ifLinuxOrDevMac = process.platform === "linux" || (!isCi && isMac) ? test : skip delete process.env.CSC_NAME process.env.CSC_IDENTITY_AUTO_DISCOVERY = "false" diff --git a/test/src/linux/snapTest.ts b/test/src/linux/snapTest.ts index 7c6b2353284..6ec4322df8d 100644 --- a/test/src/linux/snapTest.ts +++ b/test/src/linux/snapTest.ts @@ -1,7 +1,7 @@ import { Platform } from "out" import { app } from "../helpers/packTester" -test.ifLinux("platform", app({ +test.ifLinuxOrDevMac("platform", app({ targets: Platform.LINUX.createTarget("snap"), config: { productName: "Sep P", @@ -14,7 +14,7 @@ test.ifLinux("platform", app({ }, })) -test.ifLinux("snap", app({ +test.ifLinuxOrDevMac("snap", app({ targets: Platform.LINUX.createTarget("snap"), config: { productName: "Sep", diff --git a/test/typings/jest-ex.d.ts b/test/typings/jest-ex.d.ts index eb7ef7b8d98..69ed277ad77 100644 --- a/test/typings/jest-ex.d.ts +++ b/test/typings/jest-ex.d.ts @@ -10,6 +10,7 @@ declare module jest { ifWinCi: jest.It ifDevOrLinuxCi: jest.It ifLinux: jest.It + ifLinuxOrDevMac: jest.It } interface Matchers { diff --git a/yarn.lock b/yarn.lock index 39894c8cc26..d27c7a1309b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1019,9 +1019,9 @@ dateformat@^1.0.11, dateformat@^1.0.12: get-stdin "^4.0.1" meow "^3.3.0" -debug@2, debug@2.5.1, debug@^2.1.1, debug@^2.1.3, debug@^2.2.0, debug@^2.3.2, debug@^2.3.3: - version "2.5.1" - resolved "https://registry.yarnpkg.com/debug/-/debug-2.5.1.tgz#9107bb4a506052ec2a02314bc606313ed2b921c1" +debug@2, debug@2.5.2, debug@^2.1.1, debug@^2.1.3, debug@^2.2.0, debug@^2.3.2, debug@^2.3.3: + version "2.5.2" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.5.2.tgz#50c295a53dbf1657146e0c1b21307275e90d49cb" dependencies: ms "0.7.2" @@ -1106,8 +1106,8 @@ dezalgo@^1.0.0, dezalgo@^1.0.1: wrappy "1" diff@^3.0.0, diff@^3.0.1: - version "3.1.0" - resolved "https://registry.yarnpkg.com/diff/-/diff-3.1.0.tgz#9406c73a401e6c2b3ba901c5e2c44eb6a60c5385" + version "3.2.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9" dot-prop@^3.0.0: version "3.0.0"