Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapcraft unable to resolve absolute paths when using LXD #147

Open
2 tasks done
andreisergiu98 opened this issue Sep 8, 2023 · 1 comment
Open
2 tasks done

Snapcraft unable to resolve absolute paths when using LXD #147

andreisergiu98 opened this issue Sep 8, 2023 · 1 comment

Comments

@andreisergiu98
Copy link

  • [] I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

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
Copy link

welcome bot commented Sep 8, 2023

👋 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant