electron-userland / electron-installer-snap

Build Snap packages for Electron applications
Apache License 2.0
50 stars 18 forks source link

Snapcraft unable to resolve absolute paths when using LXD #147

Open andreisergiu98 opened 1 year ago

andreisergiu98 commented 1 year ago

Please describe your issue:

Hello!

As the title says snapcraft is unable to resolve absolute paths when trying to build a snap with lxd as provider.

I am building the electorn app using github actions, where kvm and multipass are unavailable, so i'm setting lxd as a provider like this:

      - name: Install Snapcraft
        if: matrix.os.name == 'linux'
        run: |
          sudo snap install snapcraft --classic
          echo /snap/bin >> $GITHUB_PATH
          sudo /snap/bin/lxd waitready
          sudo /snap/bin/lxd init --auto
          sudo snap set lxd daemon.group=adm
          sudo snap restart lxd
          sudo snap set snapcraft provider=lxd
          sudo iptables -I DOCKER-USER -i lxdbr0 -j ACCEPT
          sudo iptables -I DOCKER-USER -o lxdbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

Then I run yarn publish in my electron.forge app.

What happens next is snapcraft is resolving the absolute path of the source /home/user/app/out/ relative to the tmp directory created by this package. This also applies to the --output flag.

I created a patch for myself where i copy the source to the tmp directory and provide the relative path to snapcraft. The output is also set to the tmp directory and then i copy it back to my project.

Here is the patch:

diff --git a/src/index.js b/src/index.js
index a6d50fa2acb44a7356c8a74797dd8ca89956c774..5b33c83bfe5238c5ed2f158ed18341d34f0cb3aa 100644
--- a/src/index.js
+++ b/src/index.js
@@ -92,7 +92,20 @@ class SnapCreator {
     await copyLauncher(snapDir, this.config)
     await createYamlFromTemplate(snapDir, this.packageDir, this.config)
     await copyHooks(snapMetaDir, this.config)
-    await this.snapcraft.run(snapDir, 'snap', this.snapcraftOptions)
+
+    await fs.copy(path.dirname(this.packageDir), path.join(snapDir, 'out'), {
+      recursive: true,
+    });
+  
+    await fs.ensureDir(path.join(snapDir, 'make'));
+
+    await this.snapcraft.run(snapDir, 'snap', {
+      ...this.snapcraftOptions,
+      output: 'make/snap.build',
+    })
+
+    await fs.copy(path.join(snapDir, 'make', 'snap.build'), this.snapcraftOptions.output);
+
     return this.snapDestPath
   }

diff --git a/src/yaml.js b/src/yaml.js
index a71ea23724230c30f535460b9829f36c06b89514..7f3f2deccddd23a81d284c67d7ffd6462499df42 100644
--- a/src/yaml.js
+++ b/src/yaml.js
@@ -193,7 +193,7 @@ class SnapcraftYAML {
   }

   transformParts (packageDir) {
-    this.parts.source = path.dirname(packageDir)
+    this.parts.source = 'out';
     this.parts.organize = {}
     this.parts.organize[path.basename(packageDir)] = this.data.name

*Console output when you run electron-installer-snap with the environment variable `DEBUG='electron-installer-snap:'`. Please include the stack trace if one exists.**

The first error i encountered was that snapcraft required multipass to be installed, which is not possible in a github action. It is fixed by setting lxd as provider as seen above (it might be nice to add it to some docs because I lost a lot of time trying to set it up)

Afterwards snapcraft was unable to determine the source-type of the source (because it couldn't resolve the directory). If source-type was then set to local it complained that the source is not a directory.

With the patch i provided above everything is working as expected.

Put the console output here

What command line arguments are you passing? Alternatively, if you are using the API, what parameters are you passing to the snap() function?

I used @electron-forge/maker-snap and the javascript api ofelectron-installer-snap directly.

Put the arguments or parameters here

Please provide either a failing minimal testcase (with a link to the code) or detailed steps to reproduce your problem. Using electron-quick-start is a good starting point.

welcome[bot] commented 1 year ago

👋 Thanks for opening your first issue here! If you have a question about using electron-installer-snap, read the support docs. If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. Development and issue triage is community-driven, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.