Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build a Snap package from source #17328

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/snap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Snap
on:
push:
branches:
- "snap-build"
workflow_dispatch:
inputs:
retention:
description: Retention Days
default: 1
required: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: snapcore/action-build@v1
id: snapcraft
with:
snapcraft-args: --verbosity debug
- uses: actions/upload-artifact@v4
with:
name: snap
path: ${{ steps.snapcraft.outputs.snap }}
retention-days: ${{ github.event.inputs.retention || 7 }}
12 changes: 12 additions & 0 deletions snap/hooks/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# Initialize configuration and var directory skeleton
mkdir -p "$SNAP_COMMON/etc"
mkdir -p "$SNAP_DATA/var/cache"
mkdir -p "$SNAP_DATA/var/lib"
mkdir -p "$SNAP_DATA/var/log/netdata"
cp -rp "$SNAP/etc/netdata" "$SNAP_COMMON/etc/netdata"
cp -rp "$SNAP/var/cache/netdata" "$SNAP_DATA/var/cache/netdata"
cp -rp "$SNAP/var/lib/netdata" "$SNAP_DATA/var/lib/netdata"
mkdir -p "$SNAP_DATA/var/lib/netdata/www"
mkdir -p "$SNAP_DATA/var/run/netdata"
10 changes: 10 additions & 0 deletions snap/local/netdata.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[directories]
config = /var/snap/netdata/common/etc/netdata
log = /var/snap/netdata/current/var/log/netdata
cache = /var/snap/netdata/current/var/cache/netdata
lib = /var/snap/netdata/current/var/lib/netdata
home = /var/snap/netdata/current/var/lib/netdata

[plugin:proc]
# Disable btrfs, as this cannot be accessed from within a snap
/sys/fs/btrfs = no
171 changes: 171 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
name: netdata # you probably want to 'snapcraft register <name>'
base: core24 # the base snap is the execution environment for this snap
build-base: devel
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: Netdata Agent
description: |
Netdata is distributed, real-time, performance and health monitoring for
systems and applications. It provides insights of everything happening on the
systems it runs using interactive web dashboards.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: strict # use 'strict' once you have the right plugs and slots

layout:
# /etc/netdata:
# symlink: $SNAP_COMMON/etc/netdata
# /usr/lib/netdata:
# symlink: $SNAP/usr/lib/netdata
# /usr/libexec/netdata:
# symlink: $SNAP/usr/libexec/netdata
# /usr/share/netdata:
# symlink: $SNAP/usr/share/netdata
# /var/cache/netdata:
# symlink: $SNAP_DATA/var/cache/netdata
# /var/lib/netdata:
# symlink: $SNAP_DATA/var/lib/netdata
# /var/log/netdata:
# symlink: $SNAP_DATA/var/log/netdata
/etc/sensors3.conf:
symlink: $SNAP/etc/sensors3.conf
/usr/bin/lsns:
bind-file: $SNAP/usr/bin/lsns

parts:
deps:
plugin: nil
source: .
source-type: local
override-build: |
packaging/installer/install-required-packages.sh --dont-wait --non-interactive -i netdata-all


netdata:
plugin: cmake
source: .
source-type: local
build-environment:
- CFLAGS: ${CFLAGS:-"-O2 pipe"}
- DESTDIR: $CRAFT_PART_INSTALL
build-packages:
- golang-1.21-go
- libbrotli-dev
- libcap-dev
- libcups2-dev
- libipmimonitoring-dev
- libmongoc-dev
- libnetfilter-acct-dev
- libpcre2-dev
- libprotobuf-dev
- libsnappy-dev
- libxen-dev
- protobuf-compiler
cmake-generator: Ninja
cmake-parameters:
- -DCMAKE_INSTALL_PREFIX=/snap/netdata/current
- -DENABLE_ACLK=On
- -DENABLE_CLOUD=On
- -DENABLE_DBENGINE=On
- -DENABLE_H2O=On
- -DENABLE_ML=On
- -DENABLE_PLUGIN_APPS=On
- -DENABLE_PLUGIN_CGROUP_NETWORK=On
- -DENABLE_PLUGIN_DEBUGFS=On
- -DENABLE_PLUGIN_EBPF=On
- -DENABLE_PLUGIN_FREEIPMI=On
- -DENABLE_PLUGIN_GO=On
- -DENABLE_PLUGIN_LOCAL_LISTENERS=On
- -DENABLE_PLUGIN_LOGS_MANAGEMENT=On
- -DENABLE_PLUGIN_NFACCT=On
- -DENABLE_PLUGIN_PERF=On
- -DENABLE_PLUGIN_SLABINFO=On
- -DENABLE_PLUGIN_SYSTEMD_JOURNAL=On
- -DENABLE_PLUGIN_XENSTAT=On
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think it’s possible for a Snap package to access the required interfaces for this plugin to work, no matter what connections are made, so we should probably just disable it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean Xen specifically? Yeah, I haven't gotten to testing that and will indeed disable it if that is indeed the case.

Fortunately, many things do work. I'm currently trying to get eBPF working properly, but here too, some interfaces don't appear to be exposed and may require putting in a ticket with snapd.

- -DENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE=On
- -DENABLE_EXPORTER_MONGODB=On
- -DENABLE_BUNDLED_PROTOBUF=Off
- -DENABLE_BUNDLED_JSONC=Off
# - ${SENTRY_CONFIG}
- -DENABLE_BUNDLED_YAML=Off
override-build: |
"${CRAFT_PART_SRC}/packaging/bundle-libbpf.sh" "${CRAFT_PART_SRC}" "${CRAFT_PART_INSTALL}/usr/libexec/netdata/plugins.d"
"${CRAFT_PART_SRC}/packaging/bundle-ebpf-co-re.sh" "${CRAFT_PART_SRC}" "${CRAFT_PART_INSTALL}/usr/libexec/netdata/plugins.d"
update-alternatives --install /usr/bin/go go /usr/lib/go-1.21/bin/go 3
update-alternatives --install /usr/bin/gofmt gofmt /usr/lib/go-1.21/bin/gofmt 3
craftctl default
mkdir -p "$CRAFT_PART_INSTALL/etc/netdata"
cp -p "$CRAFT_PART_SRC/snap/local/netdata.conf" "$CRAFT_PART_INSTALL/etc/netdata/netdata.conf"
organize:
"snap/netdata/current": "/"
stage-packages:
- apcupsd
- curl
- iproute2
- iw
- libatm1
- libavahi-client3
- libavahi-common3
- libbson-1.0-0
- libcups2
- libfreeipmi17
- libipmimonitoring6
- libmongoc-1.0-0
- libmongocrypt0
- libnetfilter-acct1
- libsnappy1v5
- libutf8proc3
- libuv1
- libxencall1
- libxendevicemodel1
- libxenevtchn1
- libxenforeignmemory1
- libxengnttab1
- libxenhypfs1
- libxenmisc4.17
- libxenstore4
- libxentoolcore1
- libxentoollog1
- libyajl2
- lm-sensors
- nvme-cli
- util-linux
prime:
- -snap/netdata

ebpf-kernel-collector:
plugin: nil
source: .
source-type: local
override-pull: |
craftctl default
NETDATA_PLUGINDIR=$CRAFT_PART_INSTALL/usr/libexec/netdata/plugins.d
mkdir -p "${NETDATA_PLUGINDIR}"
sh -x "${CRAFT_PART_SRC}/packaging/bundle-ebpf.sh" "${CRAFT_PART_SRC}" "${NETDATA_PLUGINDIR}" force

apps:
agent:
command: usr/sbin/netdata -u root -D -P $SNAP_DATA/var/run/netdata/netdata.pid -c $SNAP_COMMON/etc/netdata/netdata.conf
daemon: simple
plugs:
- docker-support # Allows access to /prod/[0-9]*/limits
- hardware-observe
- kubernetes-support # cgroups (incl. systemd services)
- log-observe
- login-session-observe
- mount-observe
- network
- network-bind
- network-observe # network connections function
- network-setup-observe # ip{,4,6}.*, wireless.*, netfilter.conntrack_sockets
- system-observe # many disk.*, cpu and memory pressure, system.io
- time-control # needed for timex to call clock_adjtime to measure jitter
claim:
command: usr/sbin/netdata-claim.sh
plugs:
- network
cli:
command: usr/sbin/netdatacli
log2journal:
command: usr/sbin/log2journal
systemd-cat-native:
command: usr/sbin/systemd-cat-native