Electron-builder: Build snap packages for Linux

Created on 16 Jun 2016  ยท  50Comments  ยท  Source: electron-userland/electron-builder

Snaps are universal Linux packages which work on any distribution or device. Snaps are faster to install, easier to create, safer to run, and they update automatically and transactionally so your app is always fresh and never broken.

Snap packages are supported by all major Linux distributions and integrate well with desktop environments.
https://insights.ubuntu.com/2016/06/14/universal-snap-packages-launch-on-multiple-linux-distros/

Although snap packages are relatively easy to build, there is an excellent tool to package and publish snaps called snapcraft.
http://snapcraft.io

feature linux

Most helpful comment

if question to me:

  • snap store ubuntu
  • auto updates without any effort (including update server (I know, that bintray can be used))
  • relatively easy setup (for me, "make executable" before laugh, is not good) โ€” no need to know what AppImage file is.

Disadvantages:

  • AppImage works everywhere
  • vendor-lock
  • you can build it only on Linux
  • root is required

For now, AppImage is the default format for electron-builder and unlikely it will be changed in the foreseeable future.

Two "critical" AppImage issues for me:

  • AppImage launch (make executable before launch)
  • Icon in the dock.

All 50 comments

Are you affiliated with Snap or just user?

I'm a "just user". ๐Ÿ˜’

Here's a tutorial on how to snap electron-based apps, may be helpful to build a script;

http://www.linuxuk.org/post/20160518_snapping_electron_based_applications_simplenote/

Moved to backlog to keep issue list clear.

@nmabhinandan What do you use currently โ€” AppImage or deb? Are you still "dream" about snap?

I decided to support Snap. Will be fixed soon.

What advantage do you see with snap over AppImage?

if question to me:

  • snap store ubuntu
  • auto updates without any effort (including update server (I know, that bintray can be used))
  • relatively easy setup (for me, "make executable" before laugh, is not good) โ€” no need to know what AppImage file is.

Disadvantages:

  • AppImage works everywhere
  • vendor-lock
  • you can build it only on Linux
  • root is required

For now, AppImage is the default format for electron-builder and unlikely it will be changed in the foreseeable future.

Two "critical" AppImage issues for me:

  • AppImage launch (make executable before launch)
  • Icon in the dock.

BTW, we use AppImage to distribute JetBrains Toolbox app for Linux, but image packed into tar.gz archive to avoid "make executable before launch" (I know, that you don't like it :)).

Thanks @develar, let me know if you have ideas how to improve in these areas. Yes, I met @kropp recently :-)

@develar I've asked on the snapcraft mailinglist about building snaps on other platforms than Linux.

Not sure if it's interesting, but this is an article on someone creating a snap for an electron app: http://www.linuxuk.org/post/20160518_snapping_electron_based_applications_simplenote/

We'd be very happy to help making it really easy for Electron apps to be snapped, on any Linux platform (and possibly under the Windows Subsystem for Linux in future versions of Windows). The thread on the snapcraft list is a good start, will follow up there.

Not sure how to link properly to a thread in a mailinglist archive, but this is the start:
https://lists.ubuntu.com/archives/snapcraft/2016-November/001614.html

One working day is required to implement snaps support in the electron-builder. We already provides Docker image (https://github.com/electron-userland/electron-builder/wiki/Docker), so, docker aspect (multi-platform build) is not a problem or time-consuming task (it will be only user problem โ€” install docker :( to build snaps). You can ask me to add snaps to electron-builder Docker images.

Currently, this task is postponed (auto-updates is my current goal).

You can expect snaps support by end of this year. To speed up, you can or make donation, or make PR.

Also, don't forget to answer here โ€” why AppImage is not suitable for you.

I don't like AppImages because it requires a manual action to update, or a per application solution. With applications installed as snap their all updated with the general updates. This is because snaps come from a repository / channel and AppImages don't.

Yes, the auto-update of snaps is the heart of the CI / daily build magic
too :)

Building the snap in a docker image should work fine - just use Ubuntu
16.04 and a current snapcraft. I don't think you would be able to test
it inside a docker process, but you could build it and push it to the
cloud and then devices will auto-update. If it's one days work let me
make that donation :)

Do you have a standard recommended CI, like Travis? Because the real win
is integrating snap builds with the auto-update mechanism for developers
to run trunk of the app.

Mark

Do you have a standard recommended CI, like Travis?

Travis and Circle CI are supported explicitly. I recommend to use Travis to build macOS and Circle CI to build Linux. electron-builder uses Docker on Circle CI to test (https://github.com/electron-userland/electron-builder/blob/master/circle.yml#L17).

OK, if Circle CI has good support for secure secrets on their side, then
we can probably also hook up CI builds to the store, so developers can
run them if they want, automagically.

Mark

I don't like AppImages because it requires a manual action to update, or a per application solution. With applications installed as snap their all updated with the general updates. This is because snaps come from a repository / channel and AppImages don't.

Don't think it can be much easier than this:

This empowers the end user to decide what to update, and when.

@peteruithoven that's a step-by-step guide that refers to some old infos though...

Now electron apps can run confined and with proper desktop integration.
See this example for more infos: https://github.com/3v1n0/electron-quick-start-snap

@3v1n0 Yes. Currently you can set target to dir to get only unpacked linux directory. And then pack it using another tools.

Work started. Please do not send PR for now.

Initially supported:

  • Doesn't work on macOS yet. But electron-builder automatically uses docker, so, you will not notice that snap requires Linux.
  • No desktop integration. To investigate. i.e. your app is not added to menu.
  • electron-download fixed โ€” you can run build in the Linux VM in the macOS directory (Parallels Desktop). So, you can open terminal in the Linux VM and build your app. Until macOS Docker is not fully supported.

Issue is not closed because it is very raw. Snap is not so straightforward and well documented as AppImage.

Not yet pushed.

@develar hello there

To get desktop files you currently have to do something similar to https://github.com/snapcore/snapcraft/tree/master/demos/qt5-text-editor

In the upcoming snapcraft you will also be able to do something like this:

apps:
    my-app:
        command: my-command
        desktop: <path-in-snap-to-desktop>

I am guessing that since you generate everything on the fly you can go with the former just fine.

@develar your feedback is welcome so any specifics to make your life easier, just say so!

@develar is this related to snaps at all? Sorry I am missing context and should of mentioned "life easier related to creating a snap"

@sergiusens I am sorry, comment related to another issue. Thanks for your comments, I will try.

@sergiusens desktop-glib-only is currently used. I have read https://developer.ubuntu.com/en/blog/2016/07/06/announcing-new-snap-desktop-launchers/

No luck โ€” no app in the menu (Ubuntu/Xubuntu). Should I create .desktop file as part of the app?

Generated snapcraft.yaml https://gist.github.com/develar/88bc3e8e225e30a43a654e3653b0d9ec
Built on Xubuntu, because on Ubuntu doesn't work (snapcraft version 2.22.1 on both VM) (I will post internal error trace later).

When app is integrated โ€” on sudo snap install --force-dangerous or on first launch? Or does it work only if installed from ubuntu store? Is Xubuntu supported or only Ubunuu?

@sergiusens Thanks a lot for https://github.com/snapcore/snapcraft/pull/919! I will try. https://github.com/snapcore/snapcraft/blob/master/docs/metadata.md is much more better then http://snapcraft.io/docs/ (e.g., no more question about package icon โ€” "relative to the icon inside the snap").

Ok, I have no idea how to build snap with a desktop integration and package icon. Also, it seems unreleased snapcraft is required to add icon to package (https://github.com/snapcore/snapcraft/commit/4a4435cbe9cee4ac0d2225b0d37d897af1c927c1). (currently, you will get deprecated warning โ€” in any case package icon and app icon doesn't work).

As @sergiusens is here, I don't want to waste my time anymore and will wait some advice how to make it working.

@develar I would post a question on the snapcraft mailing list, it's quite active.
I could also also try to ask it for you, if you prefer that.

@peteruithoven no need, I will bring in the necessary folk into play; I plan on looking at this today as I carved out some time for this.

@develar the deprecated message is harmless and should just work

@develar how can I setup an environment to play around with this?

@sergiusens You can just provide me minimum snaps app that has desktop integration โ€”ย i.e. menu entries for app is created on install. And shed light on "When app is integrated โ€” on sudo snap install --force-dangerous or on first launch? Or does it work only if installed from ubuntu store".

If you say โ€” this example definitely has package icon / entry in the menu for app / icon โ€” I will continue to digging what's wrong on my side. Is Xubuntu supported or I have to use only Ubuntu?

But if you want to help me and try electron-builder โ€”

  • install git lfs โ€” https://git-lfs.github.com
  • git lfs clone https://github.com/electron-userland/electron-builder.git
  • cd electron-builder and npm install
  • uncomment line test.ifNotCi("snap" ... in the test/src/linux/linuxPackagerTest.ts.
  • npm run compile

and then you can run test:

TEST_APP_TMP_DIR=/tmp/electron-builder-test ./node_modules/.bin/jest -t "snap" linuxPackagerTest

npm run compile to recompile sources.

Currently I am on vacation, I haven't attempted again to investigate or try snaps examples to see โ€” does it work or not. Thanks for you help.

Sorry. I am still not ready to waste my time and investigate why snaps desktop integration doesn't work. But in any case I hope to fix it this year, as promised.

Another "nice" feature of snapcraft โ€” when it is spawned by electron-builder, it can request sudo password to install system deps and build process hangs...

Issue is closed as fixed.

All stopper issues were fixed by new snapcraft release (and one issue on electron-builder side). Only 2.24+ snapcraft version must be used. electron-builder doesn't check it. Please always ensure that you use latest version. App now correctly integrated into your system (desktop integration and icon).

Known issues:

  1. macOS not supported. You have to use our docker image explicitly for now.
  2. Right after launch app icon replaced to unknown. Yeah... to investigate why correctly looking snap doesn't work. Maybe someone will help to fix it.
  3. build may hangs forever because snapcraft can ask for a root password. Workaround (it is required only once to install system deps, others build will be successful without sudo): well, try to call snapcraft snap in the dist/linux-unpacked-snap In case of any issue it is very easy way to forget about electron-builder and play with snapcraft directly to investigate what's wrong. I mean โ€” you don't need to modify snap.ts source to investigate issues, you can just edit generated snapcraft.yaml and then send a PR to fix electron-builder issue if discovered.

snap package size can be reduced from 68MB to 46MB using ubuntu-app-platform but it is buggy and not reliable. (https://bugs.launchpad.net/snappy/+bug/1652369)

cannot mount /snap/ubuntu-app-platform/19 at /snap/snap-electron-builder-test/x4/ubuntu-app-platform with options bind,ro. errmsg: No such file or directory

Will try electron-builder for snapping my app very soon, thank you very much for this!

Questions:

  1. Snap package can be uploaded to the Ubuntu Store?
  2. Platform supported is only desktop or it will run on mobile / tablet?

Thanks

Snap package can be uploaded to the Ubuntu Store?

Yes. And you can configure some options. Defaults options are equals to official snapcraft options and, so, snap can be published to Ubuntu Store as is.

Platform supported is only desktop or it will run on mobile / tablet?

Well... I don't know ;) At least, not restricted.

You can build snap on macOS (just install docker for mac). 10.13.0+ Do not use Docker Toolbox. Only Docker for Mac is supported and will work. (Well, there is not yet reported snap bug that leads to inability to use mapped volumes, but using Docker for Mac in any case is very important).

Right after launch app icon replaced to unknown

Issue on electron-builder side identified and fix will be published soon.

Snap desktop integration doesn't work correctly for Elementary OS (https://github.com/ubuntu/snapcraft-desktop-helpers/issues/32).

AppImage correctly integrated into Elementary OS, but app doesn't start (electron-builder issue, will be fixed soon).

I have snap my first electron application, thank you very much for your work on this! I have a problem with the sound, the issue is here. Someone told me to add pulseaudio as a stage-packages.

How to modify/customize the snap.yaml generated by electron-builder?
Thanks

@develar Thank you, sounds is working! Should it be the actual defaults?
["libnotify4", "libappindicator1", "libxtst6", "libnss3", "libxss1", "fontconfig-config", "gconf2", "libasound2", "pulseaudio"]

@patricksebastien 80.6 vs 85.1 ... well, I guess 5 MB is ok ((sound doesn't work -> googling -> find option in the electron-builder -> enable it) * user count). Will be added to default packages. I hope ubuntu-platform will be usable sometime and snap size will be reduced.

Sorry, I need to use the webcam. How to add plugs: "camera" in snap.yaml? Didn't find this option in the documentation.

@patricksebastien Please file issue. Will be fixed soon if filed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

probonopd picture probonopd  ยท  55Comments

ghost picture ghost  ยท  51Comments

Sambego picture Sambego  ยท  64Comments

UdaraJay picture UdaraJay  ยท  146Comments

jechazelle picture jechazelle  ยท  77Comments