docs: add snapcraft + electron-packager example (#25750)

* docs: add snapcraft + electron-packager example

Add example to snap electron app (electron-quick-start)
using snapcraft & electron-packager.

Include notes on how to apply this to an existing project.

Signed-off-by: Chris Patterson <chris.patterson@canonical.com>

* Update snapcraft.md

* Update snapcraft.md

* Update snapcraft.md

* Update docs/tutorial/snapcraft.md

Co-authored-by: John Kleinschmidt <jkleinsc@github.com>

Co-authored-by: Cheng Zhao <github@zcbenz.com>
Co-authored-by: John Kleinschmidt <jkleinsc@github.com>
This commit is contained in:
Chris Patterson 2020-10-26 03:47:01 -04:00 committed by GitHub
parent ecb758dae5
commit 6a0c5a8a65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,6 +79,78 @@ snap(options)
.then(snapPath => console.log(`Created snap at ${snapPath}!`))
```
## Using `snapcraft` with `electron-packager`
### Step 1: Create Sample Snapcraft Project
Create your project directory and add add the following to `snap/snapcraft.yaml`:
```yaml
name: electron-packager-hello-world
version: '0.1'
summary: Hello World Electron app
description: |
Simple Hello World Electron app as an example
base: core18
confinement: strict
grade: stable
apps:
electron-packager-hello-world:
command: electron-quick-start/electron-quick-start --no-sandbox
extensions: [gnome-3-34]
plugs:
- browser-support
- network
- network-bind
environment:
# Correct the TMPDIR path for Chromium Framework/Electron to ensure
# libappindicator has readable resources.
TMPDIR: $XDG_RUNTIME_DIR
parts:
electron-quick-start:
plugin: nil
source: https://github.com/electron/electron-quick-start.git
override-build: |
npm install electron electron-packager
npx electron-packager . --overwrite --platform=linux --output=release-build --prune=true
cp -rv ./electron-quick-start-linux-* $SNAPCRAFT_PART_INSTALL/electron-quick-start
build-snaps:
- node/14/stable
build-packages:
- unzip
stage-packages:
- libnss3
- libnspr4
```
If you want to apply this example to an existing project:
- Replace `source: https://github.com/electron/electron-quick-start.git` with `source: .`.
- Replace all instances of `electron-quick-start` with your project's name.
### Step 2: Build the snap
```sh
$ snapcraft
<output snipped>
Snapped electron-packager-hello-world_0.1_amd64.snap
```
### Step 3: Install the snap
```sh
sudo snap install electron-packager-hello-world_0.1_amd64.snap --dangerous
```
### Step 4: Run the snap
```sh
electron-packager-hello-world
```
## Using an Existing Debian Package
Snapcraft is capable of taking an existing `.deb` file and turning it into