canonical / snapcraft

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

Can't build Core20 snaps on non-snap distros #4960

Open dstathis opened 1 month ago

dstathis commented 1 month ago

Bug Description

When running on nixos, I get the following error from snapcraft despite lxd being installed:

[nix-shell:~/repos/grafana-agent-snap]$ snapcraft_legacy --use-lxd
You need 'LXD' set-up to build snaps: snap support is required to continue: https://docs.snapcraft.io/installing-snapd/6735.

To Reproduce

Pack a core20 charm using the --use-lxd flag on nixos.

Environment

snapcraft 8.2.5 lxd 5.21.1 LTS

snapcraft.yaml

name: grafana-agent
version: '0.40.4'
summary: A telemetry collector for sending metrics, logs, and trace data
license: Apache-2.0
contact: simon.aronsson@canonical.com
issues: https://github.com/canonical/grafana-agent-snap/issues
source-code: https://github.com/canonical/grafana-agent-snap
website: https://grafana.com
description: "Grafana Agent is a telemetry collector for sending metrics, \nlogs, and trace data to the opinionated Grafana observability stack.\n"
base: core20
grade: stable
confinement: classic
compression: lzo
apps:
  grafana-agent:
    daemon: simple
    command: "${SNAP}/agent -config.expand-env -config.file /etc/grafana-agent.yaml"
    install-mode: disable
    restart-condition: on-failure
architectures:
  - build-on: amd64
  - build-on: arm64
parts:
  wrapper:
    plugin: dump
    source: ./snap/local
    source-type: local
    override-build: |
      cp agent-wrapper $SNAPSNAPSNAPCRAFT_PART_INSTALL/
  grafana-agent:
    plugin: go
    source: https://github.com/grafana/agent
    source-type: git
    source-tag: "v0.40.4"
    build-snaps:
      - go
    build-packages:
      - build-essential
      - libsystemd-dev
    stage-packages:
      - libsystemd0
    override-build: |
      export USE_CONTAINER=0
      export GOFLAGS="-mod=readonly -tags=promtail_journal_enabled"

      make agent agentctl

      cp build/grafana-agent $SNAPSNAPSNAPCRAFT_PART_INSTALL/agent
      cp build/grafana-agentctl $SNAPSNAPSNAPCRAFT_PART_INSTALL/agentctl

Relevant log output

-

Additional context

No response

mr-cal commented 1 month ago

core20 snaps require LXD to be installed as a snap whereas core22 and core24 snaps do not.

We should backport the logic from craft-providers to snapcraft_legacy to support building core20 snaps on OSs like Arch and NixOS.

Source: https://matrix.to/#/!GGqzbFAUQprdPgYYCM:ubuntu.com/$gBokzMPfwHIjP_gDfQGMaIT4h6l7mu0utaVGbudHokQ?via=ubuntu.com&via=matrix.org&via=kde.org

syncronize-issues-to-jira[bot] commented 1 month ago

Thank you for reporting us your feedback!

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

This message was autogenerated