File: //snap/canonical-livepatch/355/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: amd64
build-for: arm64
- build-on: amd64
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
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
- 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
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 amd64 to arm64:
- TARGET_ARCH: "arm64"
- on amd64 to s390x:
- TARGET_ARCH: "s390x"
build-snaps:
- go
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
git -C $SNAPCRAFT_PROJECT_DIR describe --tags --dirty --abbrev=0 | tee $SNAPCRAFT_PROJECT_DIR/version.txt
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