canonical / rockcraft

Tool to create OCI Images using the language from Snapcraft and Charmcraft.
GNU General Public License v3.0
35 stars 43 forks source link

npm plugin fails #309

Closed nrobinaubertin closed 1 year ago

nrobinaubertin commented 1 year ago

Bug Description

I try to use the npm plugin in its most basic form and packing fails.

To Reproduce

Just rockcraft pack the rockfile. Proposed here with ubuntu:22.04 but also fails with ubuntu:20.04

Environment

# uname -a
Linux t14 5.19.0-40-generic #41~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 31 16:00:14 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
# snap info rockcraft | tail
snap-id:      3mPIBn6L9IYLyBAZsaqjlnMk7huEtqlv
tracking:     latest/edge
refresh-date: today at 11:46 EDT
channels:
  latest/stable:    --
  latest/candidate: --
  latest/beta:      --
  latest/edge:      0+git.f8e53fd 2023-06-27 (898) 86MB classic
installed:          0+git.f8e53fd            (898) 86MB classic

rockcraft.yaml

name: test
summary: test
description: test
base: ubuntu:22.04
license: Apache-2.0
version: "1.0"
platforms:
  amd64:
parts:
  npm-test:
    plugin: npm
    source: .

Relevant log output

2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.663 Requested build-packages already installed: ['gcc']
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.934 verify plugin environment for part 'npm-test'
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.935 plugin validation environment: # Environment
2023-06-28 14:03:45.231 :: ## Application environment
2023-06-28 14:03:45.231 :: ## Part environment
2023-06-28 14:03:45.231 :: export CRAFT_ARCH_TRIPLET="x86_64-linux-gnu"
2023-06-28 14:03:45.231 :: export CRAFT_TARGET_ARCH="amd64"
2023-06-28 14:03:45.231 :: export CRAFT_PARALLEL_BUILD_COUNT="1"
2023-06-28 14:03:45.231 :: export CRAFT_PROJECT_DIR="/root/project"
2023-06-28 14:03:45.231 :: export CRAFT_OVERLAY="/root/overlay/overlay"
2023-06-28 14:03:45.231 :: export CRAFT_STAGE="/root/stage"
2023-06-28 14:03:45.231 :: export CRAFT_PRIME="/root/prime"
2023-06-28 14:03:45.231 :: export CRAFT_PROJECT_NAME="test"
2023-06-28 14:03:45.231 :: export CRAFT_PART_NAME="npm-test"
2023-06-28 14:03:45.231 :: export CRAFT_STEP_NAME="BUILD"
2023-06-28 14:03:45.231 :: export CRAFT_PART_SRC="/root/parts/npm-test/src"
2023-06-28 14:03:45.231 :: export CRAFT_PART_SRC_WORK="/root/parts/npm-test/src"
2023-06-28 14:03:45.231 :: export CRAFT_PART_BUILD="/root/parts/npm-test/build"
2023-06-28 14:03:45.231 :: export CRAFT_PART_BUILD_WORK="/root/parts/npm-test/build"
2023-06-28 14:03:45.231 :: export CRAFT_PART_INSTALL="/root/parts/npm-test/install"
2023-06-28 14:03:45.231 :: ## Plugin environment
2023-06-28 14:03:45.231 :: ## User environment
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.935 plugin validation command: 'node --version'
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.941 Environment validation failed for part 'npm-test': 'node' not found and part 'npm-test' does not depend on a part named 'npm-deps' that would satisfy the dependency.
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945 Traceback (most recent call last):
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945   File "/snap/rockcraft/898/lib/python3.8/site-packages/craft_parts/plugins/validator.py", line 100, in validate_dependency
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945     output = self._execute(command).strip()
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945   File "/snap/rockcraft/898/lib/python3.8/site-packages/craft_parts/plugins/validator.py", line 143, in _execute
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945     proc = subprocess.run(
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945   File "/snap/rockcraft/898/usr/lib/python3.8/subprocess.py", line 516, in run
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945     raise CalledProcessError(retcode, process.args,
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945 subprocess.CalledProcessError: Command '['/bin/bash', '/tmp/tmpmza_3nli']' returned non-zero exit status 127.
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945 The above exception was the direct cause of the following exception:
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945 Traceback (most recent call last):
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945   File "/snap/rockcraft/898/lib/python3.8/site-packages/rockcraft/parts.py", line 159, in run
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945     with self._lcm.action_executor() as aex:
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945   File "/snap/rockcraft/898/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 292, in __enter__
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945     self._executor.prologue()
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945   File "/snap/rockcraft/898/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 92, in prologue
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945     self._verify_plugin_environment()
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945   File "/snap/rockcraft/898/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 278, in _verify_plugin_environment
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945     validator.validate_environment(part_dependencies=part.dependencies)
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945   File "/snap/rockcraft/898/lib/python3.8/site-packages/craft_parts/plugins/npm_plugin.py", line 100, in validate_environment
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945     self.validate_dependency(
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945   File "/snap/rockcraft/898/lib/python3.8/site-packages/craft_parts/plugins/validator.py", line 118, in validate_dependency
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945     raise errors.PluginEnvironmentValidationError(
2023-06-28 14:03:45.231 :: 2023-06-28 18:03:44.945 craft_parts.errors.PluginEnvironmentValidationError: Environment validation failed for part 'npm-test': 'node' not found and part 'npm-test' does not depend on a part named 'npm-deps' that would satisfy the dependency.
2023-06-28 14:03:45.232 Executing on host: lxc --project rockcraft config device show local:rockcraft-test-3278282
2023-06-28 14:03:45.283 Executing on host: lxc --project rockcraft config device remove local:rockcraft-test-3278282 disk-/root/project
2023-06-28 14:03:45.362 Executing on host: lxc --project rockcraft stop local:rockcraft-test-3278282
2023-06-28 14:03:46.759 craft-providers error: Failed to execute pack in instance.
nrobinaubertin commented 1 year ago

Might be related to https://github.com/canonical/rockcraft/issues/307

tigarmo commented 1 year ago

The message is a bit opaque but it's meant to say that you should provide a node binary; This can be a stage-package, or snap, or a specific version downloaded "manually" via override-build.

nrobinaubertin commented 1 year ago

So to use the npm-plugin, I need to provide a node binary ? I didn't understand that reading the doc. I would suggest adding a line about that if it's the case

lengau commented 1 year ago

@nrobinaubertin rockcraft should be the same as snapcraft's core22 support on this front, since they both use the craft-parts npm plugin.

You can provide npm as @tigarmo suggested above, or you can set npm-node-version (and optionally npm_include_node), similar to how it's done in traefik-rock. The meanings are the same as what's listed in the core22 section of the snapcraft doc you linked.

lengau commented 1 year ago

I've updated the docs to provide some more clarity. It may take a bit of time for the update to make its way into production, but ITMT you can view the edited version on the snapcraft forum. This won't necessarily be 100% identical since rockcraft and snapcraft do differ in a few ways, but relevant to your question it should be the same. Feel free to reopen if not!