Current Dir: /snap/canonical-livepatch/414/snap/

[DIR]  hooks [ delete | rename ]
[FILE] manifest.yaml [ edit | delete | rename ]
[FILE] snapcraft.yaml [ edit | delete | rename ]

Viewing: /snap/canonical-livepatch/414/snap/snapcraft.yaml

name: canonical-livepatch
summary: Canonical Livepatch Client
description: Canonical Livepatch Client
confinement: strict
base: core22
grade: stable
adopt-info: canonical-livepatch

architectures:
  - build-on: amd64
    build-for: amd64
  - build-on: arm64
    build-for: arm64
  - build-on: s390x
    build-for: s390x

plugs:
  etc-update-motd-d:
    interface: system-files
    write:
      - /etc/update-motd.d/99-livepatch-kernel-upgrade-required
  hostfs-var-local-canonical-livepatch-mode:
    interface: system-files
    read:
      - /var/lib/snapd/hostfs/var/local/canonical_livepatch_mode
  run-cloud-init-instance-data-json:
    interface: system-files
    read:
      - /run/cloud-init/instance-data.json
  # We need the next two plugs to get the list of
  # kernel images installed on the host machine.
  #
  # These are good references/examples on how to have `dpkg` available in snap
  # runtime:
  #   - Discussion: https://forum.snapcraft.io/t/classic-confinement-for-ubuntu-package-manifest-snap/20543/5
  #   - An example: https://github.com/canonical/ubuntu-package-manifest/blob/982c61d5d2fa25f150fe31a713f3b3bb08c709a3/snap/snapcraft.yaml
  hostfs-var-lib-dpkg:
    interface: system-files
    read:
      - /var/lib/snapd/hostfs/var/lib/dpkg
  etc-dpkg:
    interface: system-files
    read:
      - /etc/dpkg
  # We need this plug to read the transition file created after patch insertion
  # to determine if the patch application is successful.
  sys-kernel-livepatch:
    interface: system-files
    read:
      - /sys/kernel/livepatch

layout:
  /usr/share/dpkg:
    bind: $SNAP/usr/share/dpkg
  /usr/bin/dpkg:
    bind-file: $SNAP/usr/bin/dpkg
  /etc/dpkg/dpkg.cfg:
    bind-file: $SNAP/etc/dpkg/dpkg.cfg

hooks:
  connect-plug-etc-update-motd-d:
    plugs: [etc-update-motd-d]
  disconnect-plug-etc-update-motd-d:
    plugs: [etc-update-motd-d]
  post-refresh:
    plugs: [etc-update-motd-d]
  remove:
    plugs: [etc-update-motd-d]

apps:
  canonical-livepatchd:
    command: canonical-livepatchd
    plugs:
      - network-bind
      - network-control
      - kernel-module-control
      - system-observe
      - log-observe
      - hardware-observe
      - network-manager
      - hostfs-var-local-canonical-livepatch-mode
      - system-packages-doc
      - run-cloud-init-instance-data-json
      - hostfs-var-lib-dpkg
      - etc-dpkg
      - sys-kernel-livepatch
    daemon: simple
    restart-condition: on-failure
    environment:
      # This will point dpkg to see the host's data. If this env var is not set
      # then dpkg will see the packages installed in the confined snap environment.
      DPKG_ADMINDIR: /var/lib/snapd/hostfs/var/lib/dpkg
  canonical-livepatch:
    command: canonical-livepatch
    plugs:
      - network-bind
      - network-control
      - kernel-module-control
      - system-observe
      - hardware-observe

parts:
  canonical-livepatch:
    source: .
    stage-packages: [ethtool]
    plugin: go
    build-packages: [build-essential, git]
    build-environment:
      - GO111MODULE: "on"
      - GOOS: "linux"
      - on amd64 to amd64:
          - TARGET_ARCH: "amd64"
      - on arm64 to arm64:
          - TARGET_ARCH: "arm64"
      - on s390x to s390x:
          - TARGET_ARCH: "s390x"
    build-snaps:
      # Go 1.25 previously caused apparmor denials when accessing mountinfo (see CHANGELOG for v10.12.1).
      # This was fixed in snapd 2.76, so it is safe to build with Go 1.25.
      - go/1.25/stable
    override-pull: |-
      set -ex
      snapcraftctl pull
      if [[ ! -f $SNAPCRAFT_PROJECT_DIR/commit.txt ]]
      then
        git -C $SNAPCRAFT_PROJECT_DIR rev-parse --verify HEAD | tee $SNAPCRAFT_PROJECT_DIR/commit.txt
        if [[ -f $SNAPCRAFT_PROJECT_DIR/.local_build ]]
        then
          git -C $SNAPCRAFT_PROJECT_DIR rev-parse --short HEAD | awk '{print $1"-devel"}' | tee $SNAPCRAFT_PROJECT_DIR/version.txt
        else
          git -C $SNAPCRAFT_PROJECT_DIR describe --tags --dirty --abbrev=0 --match 'client-v*' | sed 's/^client-//' | tee $SNAPCRAFT_PROJECT_DIR/version.txt
        fi
      fi
      snapcraftctl set-version "$(cat $SNAPCRAFT_PROJECT_DIR/version.txt)"
      export VERSION="$(cat $SNAPCRAFT_PROJECT_DIR/version.txt)"
      gofmt -w -r "develVersion -> \"${VERSION}\"" $SNAPCRAFT_PART_SRC/internal/config/version.go
    override-build: |-
      set -ex
      GOOS=linux GOARCH=$TARGET_ARCH CGO_ENABLED=0 go build -mod=readonly -o "${SNAPCRAFT_PART_INSTALL}/canonical-livepatch" github.com/canonical/livepatch-client/cmd/livepatch
      GOOS=linux GOARCH=$TARGET_ARCH CGO_ENABLED=0 go build -mod=readonly -o "${SNAPCRAFT_PART_INSTALL}/canonical-livepatchd" github.com/canonical/livepatch-client/cmd/livepatchd
    stage:
      - canonical-livepatch
      - canonical-livepatchd
    # touch a src file to ensure all target architectures are built and not skipped due to already being built.
    override-prime: |-
      snapcraftctl prime
      touch $SNAPCRAFT_PART_SRC/internal/config/version.go
  dpkg-binary:
    plugin: nil
    stage-packages:
      - dpkg
  motd:
    plugin: dump
    source: ./resources
    organize:
      "../src/": "resources"
    prime:
      - resources
  keys:
    plugin: dump
    source: ./keys
    organize:
      "../src/": "keys"
    prime:
      - keys
  hooks:
    plugin: dump
    source: ./snaps/client/core22/hooks
    organize:
      configure: snap/hooks/configure
      post-refresh: snap/hooks/post-refresh
      connect-plug-etc-update-motd-d: snap/hooks/connect-plug-etc-update-motd-d
      disconnect-plug-etc-update-motd-d: snap/hooks/disconnect-plug-etc-update-motd-d
      remove: snap/hooks/remove

Upload File: