Skip to content

Commit

Permalink
feat(snaps): build snaps on macOs #509
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Dec 26, 2016
1 parent 62e0bcb commit f343def
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 66 deletions.
2 changes: 2 additions & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions docker/6/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
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/*
10 changes: 1 addition & 9 deletions docker/7/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
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/*
26 changes: 5 additions & 21 deletions docker/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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"
ENV PATH "/yarn/bin:$PATH"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/options/linuxOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> | null

Expand Down
4 changes: 2 additions & 2 deletions src/targets/fpm.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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],
Expand Down
27 changes: 13 additions & 14 deletions src/targets/snap.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"]
}
}
Expand All @@ -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)
}
}
6 changes: 4 additions & 2 deletions test/jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions test/src/linux/snapTest.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -14,7 +14,7 @@ test.ifLinux("platform", app({
},
}))

test.ifLinux("snap", app({
test.ifLinuxOrDevMac("snap", app({
targets: Platform.LINUX.createTarget("snap"),
config: {
productName: "Sep",
Expand Down
1 change: 1 addition & 0 deletions test/typings/jest-ex.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare module jest {
ifWinCi: jest.It
ifDevOrLinuxCi: jest.It
ifLinux: jest.It
ifLinuxOrDevMac: jest.It
}

interface Matchers {
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1019,9 +1019,9 @@ dateformat@^1.0.11, dateformat@^1.0.12:
get-stdin "^4.0.1"
meow "^3.3.0"

debug@2, [email protected].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, [email protected].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"

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit f343def

Please sign in to comment.