canonical / snapcraft

Package, distribute, and update any app for Linux and IoT.
https://snapcraft.io
GNU General Public License v3.0
1.18k stars 445 forks source link

[core24] Non-core24 runs in managed mode are not being correctly logged #4610

Closed tigarmo closed 8 months ago

tigarmo commented 8 months ago

Bug Description

The fallback logic in feature/craft-application has an issue with handling of logs in managed (lxd/etc) instances. The flow is this - let's say that the command is "snapcraft pull".

1) "Snapcraft-1" starts up on the host; 2) Realizes that the project has a non-core24 base, and falls back; 3) core22/core20 code picks up the execution, prepares the lxd instance; 4) launches Snapcraft in the instance with SNAPCRAFT_MANAGED_MODE set; 5) "Snapcraft-2" starts up inside the instance; 6) Like in 2, falls back to non-core24 code. However, before this, the Emitter is initialized - Snapcraft-2 thinks it's running on host because it's looking at CRAFT_MANAGED_MODE and not at SNAPCRAFT_MANAGED_MODE; 7) core22/core20 code in Snapcraft-2 picks up the execution, creates the lifecycle, runs "pull", finishes; 8) core22/core20 code in Snapcraft-1 tries to read the instance logs, but fails because Snapcraft-2 put it in /root/.local/state/snapcraft/logs because it thought it was running on host.

To Reproduce

Run a lifecycle command on any core22/core20 project using a Snapcraft snap from feature/craft-application, then look at the generated logs. The instance logs are not present.

Environment

Jammy

snapcraft.yaml

name: simple-snap
version: "1.0"
summary: Build a simple confined snap
description: |
  Build a simple confined snap to test the build process.

base: core22
confinement: strict

parts:
  hello:
    plugin: nil

Relevant log output

# ... removed the log before this
2024-02-23 14:52:19.913 Executing in container: lxc --project snapcraft exec local:snapcraft-hello-try-on-amd64-for-amd64-17455838 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 chown root:root /root/.bashrc
2024-02-23 14:52:20.022 Emitter: Pausing control of the terminal
2024-02-23 14:52:28.830 Emitter: Resuming control of the terminal
2024-02-23 14:52:28.831 Executing in container: lxc --project snapcraft exec local:snapcraft-hello-try-on-amd64-for-amd64-17455838 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 test -f /tmp/snapcraft.log
2024-02-23 14:52:28.995 Could not find log file /tmp/snapcraft.log in instance.
# ...

Additional context

No response

syncronize-issues-to-jira[bot] commented 8 months ago

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CRAFT-2539.

This message was autogenerated

mattculler commented 8 months ago

Completed in: https://github.com/canonical/snapcraft/pull/4638