Skip to content

Commit afd27ab

Browse files
committed
feat: bpf from upstream binary releases
Signed-off-by: thediveo <[email protected]>
1 parent 25f735b commit afd27ab

File tree

11 files changed

+269
-3
lines changed

11 files changed

+269
-3
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# Dev Container Features
22

3+
- [bpftool](src/bpftool/README.md) – installs `bpftool` from upstream
4+
https://github.com/libbpf/bpftool binary releases.
35
- [docsify](src/docsify/README.md) – automatically serves ./docs workspace
46
directory via `docsify serve` in the background.
5-
- [local-pkgsite](src/local-pkgsite/README.md) – a local Go pkgsite serving the module documentation.
6-
- [goreportcard](src/goreportcard/README.md) – provides `goreportcard-cli`that
7-
creates a Go report and a README.md badge on the code quality of a repository.
87
- [gocover](src/gocover/README.md) – provides a `gocover` command to run
98
conveniently unit tests and update a README.md coverage badge, supporting a
109
set of presets.
1110
- [go-ebpf](src/go-ebpf/README.md) – installs clang and llvm, and on top
1211
Cilium's bpf2go.
1312
- [go-mod-upgrade](src/go-mod-upgrade/README.md) – provides obligot's `go-mod-upgrade`
1413
for updating outdated Go dependencies interactively.
14+
- [goreportcard](src/goreportcard/README.md) – provides `goreportcard-cli`that
15+
creates a Go report and a README.md badge on the code quality of a repository.
16+
- [local-pkgsite](src/local-pkgsite/README.md) – a local Go pkgsite serving the module documentation.
1517
- [pin-github-action](src/pin-github-action/README.md) – provides mheaps's
1618
`pin-github-action` for pinning GitHub actions to specific hashes.
1719
- [wal-wahl](src/wal-wahl/README.md) – install multiple Docker CE versions

src/bpftool/NOTES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## OS Support
2+
3+
Tested with:
4+
- [ghcr.io/almalinux/almalinux](https://ghcr.io/almalinux/almalinux),
5+
- [mcr.microsoft.com/devcontainers/base:debian](https://mcr.microsoft.com/en-us/artifact/mar/devcontainers/base/about#about:_debian),
6+
- [fedora](https://hub.docker.com/_/fedora),
7+
- [mcr.microsoft.com/devcontainers/base:ubuntu](https://mcr.microsoft.com/en-us/artifact/mar/devcontainers/base/about#about:_ubuntu).
8+
9+
## Acknowledgement
10+
11+
[@bpftool](https://github.com/libbpf/bpftool)

src/bpftool/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
# bpftool (bpftool)
3+
4+
Installs bpftool from upstream https://github.com/libbpf/bpftool binary releases.
5+
6+
## Example Usage
7+
8+
```json
9+
"features": {
10+
"ghcr.io/thediveo/devcontainer-features/bpftool:0": {}
11+
}
12+
```
13+
14+
## Options
15+
16+
| Options Id | Description | Type | Default Value |
17+
|-----|-----|-----|-----|
18+
| version | version of bpftool to install from upstream | string | latest |
19+
20+
## OS Support
21+
22+
Tested with:
23+
- [ghcr.io/almalinux/almalinux](https://ghcr.io/almalinux/almalinux),
24+
- [mcr.microsoft.com/devcontainers/base:debian](https://mcr.microsoft.com/en-us/artifact/mar/devcontainers/base/about#about:_debian),
25+
- [fedora](https://hub.docker.com/_/fedora),
26+
- [mcr.microsoft.com/devcontainers/base:ubuntu](https://mcr.microsoft.com/en-us/artifact/mar/devcontainers/base/about#about:_ubuntu).
27+
28+
## Acknowledgement
29+
30+
[@bpftool](https://github.com/libbpf/bpftool)
31+
32+
33+
---
34+
35+
_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/thediveo/devcontainer-features/blob/main/src/bpftool/devcontainer-feature.json). Add additional notes to a `NOTES.md`._

src/bpftool/devcontainer-feature.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "bpftool",
3+
"id": "bpftool",
4+
"version": "0.0.1",
5+
"description": "Installs bpftool from upstream https://github.com/libbpf/bpftool binary releases.",
6+
"options": {
7+
"version": {
8+
"type": "string",
9+
"default": "latest",
10+
"description": "version of bpftool to install from upstream"
11+
}
12+
}
13+
}

src/bpftool/install.sh

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/usr/bin/env bash
2+
3+
# Distribution and package manager detection are licensed by Microsoft
4+
# Corporation under the MIT License, please refer to:
5+
# https://github.com/devcontainers/features/blob/main/src/go/install.sh:
6+
#
7+
# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the
8+
# MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license
9+
# information
10+
11+
set -e
12+
13+
BPFTOOL_VERSION="${VERSION:-"latest"}"
14+
15+
echo "installing feature bpftool..."
16+
17+
if [ "$(id -u)" -ne 0 ]; then
18+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
19+
exit 1
20+
fi
21+
22+
# Bring in ID, ID_LIKE, VERSION_ID, VERSION_CODENAME
23+
. /etc/os-release
24+
# Get an adjusted ID independent of distro variants
25+
MAJOR_VERSION_ID=$(echo ${VERSION_ID} | cut -d . -f 1)
26+
if [ "${ID}" = "debian" ] || [ "${ID_LIKE}" = "debian" ]; then
27+
ADJUSTED_ID="debian"
28+
elif [[ "${ID}" = "rhel" || "${ID}" = "fedora" || "${ID}" = "mariner" || "${ID_LIKE}" = *"rhel"* || "${ID_LIKE}" = *"fedora"* || "${ID_LIKE}" = *"mariner"* ]]; then
29+
ADJUSTED_ID="rhel"
30+
if [[ "${ID}" = "rhel" ]] || [[ "${ID}" = *"alma"* ]] || [[ "${ID}" = *"rocky"* ]]; then
31+
VERSION_CODENAME="rhel${MAJOR_VERSION_ID}"
32+
else
33+
VERSION_CODENAME="${ID}${MAJOR_VERSION_ID}"
34+
fi
35+
else
36+
echo "Linux distro ${ID} not supported."
37+
exit 1
38+
fi
39+
40+
if [ "${ADJUSTED_ID}" = "rhel" ] && [ "${VERSION_CODENAME-}" = "centos7" ]; then
41+
# As of 1 July 2024, mirrorlist.centos.org no longer exists.
42+
# Update the repo files to reference vault.centos.org.
43+
sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo
44+
sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo
45+
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo
46+
fi
47+
48+
# Setup INSTALL_CMD & PKG_MGR_CMD
49+
if type apt-get > /dev/null 2>&1; then
50+
PKG_MGR_CMD=apt-get
51+
INSTALL_CMD="${PKG_MGR_CMD} -y install --no-install-recommends"
52+
elif type microdnf > /dev/null 2>&1; then
53+
PKG_MGR_CMD=microdnf
54+
INSTALL_CMD="${PKG_MGR_CMD} ${INSTALL_CMD_ADDL_REPOS} -y install --refresh --best --nodocs --noplugins --setopt=install_weak_deps=0"
55+
elif type dnf > /dev/null 2>&1; then
56+
PKG_MGR_CMD=dnf
57+
INSTALL_CMD="${PKG_MGR_CMD} ${INSTALL_CMD_ADDL_REPOS} -y install --refresh --best --nodocs --noplugins --setopt=install_weak_deps=0"
58+
else
59+
PKG_MGR_CMD=yum
60+
INSTALL_CMD="${PKG_MGR_CMD} ${INSTALL_CMD_ADDL_REPOS} -y install --noplugins --setopt=install_weak_deps=0"
61+
fi
62+
63+
# Clean up
64+
clean_up() {
65+
case ${ADJUSTED_ID} in
66+
debian)
67+
rm -rf /var/lib/apt/lists/*
68+
;;
69+
rhel)
70+
rm -rf /var/cache/dnf/* /var/cache/yum/*
71+
rm -rf /tmp/yum.log
72+
rm -rf ${GPG_INSTALL_PATH}
73+
;;
74+
esac
75+
}
76+
clean_up
77+
78+
pkg_mgr_update() {
79+
case $ADJUSTED_ID in
80+
debian)
81+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
82+
echo "Running apt-get update..."
83+
${PKG_MGR_CMD} update -y
84+
fi
85+
;;
86+
rhel)
87+
if [ ${PKG_MGR_CMD} = "microdnf" ]; then
88+
if [ "$(ls /var/cache/yum/* 2>/dev/null | wc -l)" = 0 ]; then
89+
echo "Running ${PKG_MGR_CMD} makecache ..."
90+
${PKG_MGR_CMD} makecache
91+
fi
92+
else
93+
if [ "$(ls /var/cache/${PKG_MGR_CMD}/* 2>/dev/null | wc -l)" = 0 ]; then
94+
echo "Running ${PKG_MGR_CMD} check-update ..."
95+
set +e
96+
${PKG_MGR_CMD} check-update
97+
rc=$?
98+
if [ $rc != 0 ] && [ $rc != 100 ]; then
99+
exit 1
100+
fi
101+
set -e
102+
fi
103+
fi
104+
;;
105+
esac
106+
}
107+
108+
# Checks if packages are installed and installs them if not
109+
check_packages() {
110+
case ${ADJUSTED_ID} in
111+
debian)
112+
if ! dpkg -s "$@" > /dev/null 2>&1; then
113+
pkg_mgr_update
114+
${INSTALL_CMD} "$@"
115+
fi
116+
;;
117+
rhel)
118+
if ! rpm -q "$@" > /dev/null 2>&1; then
119+
pkg_mgr_update
120+
${INSTALL_CMD} "$@"
121+
fi
122+
;;
123+
esac
124+
}
125+
126+
case $(uname -m) in
127+
x86_64) ARCH="amd64";;
128+
aarch64 | armv8*) ARCH="arm64";;
129+
*) echo "Unsupported architecture: $(uname -m)"; exit 1;;
130+
esac
131+
132+
export DEBIAN_FRONTEND=noninteractive
133+
134+
if ! type curl > /dev/null 2>&1; then
135+
check_packages curl
136+
fi
137+
138+
if [ "$BPFTOOL_VERSION" = "latest" ]; then
139+
# get latest release
140+
BPFTOOL_VERSION=$(curl -s https://api.github.com/repos/libbpf/bpftool/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
141+
fi
142+
143+
echo $BPFTOOL_VERSION
144+
echo $ARCH
145+
146+
curl -sSL -o /tmp/bpftool.tar.gz "https://github.com/libbpf/bpftool/releases/download/${BPFTOOL_VERSION}/bpftool-${BPFTOOL_VERSION}-${ARCH}.tar.gz"
147+
ls -l /tmp/bpftool.tar.gz
148+
tar xzof /tmp/bpftool.tar.gz -C /usr/local/bin/ bpftool
149+
chmod 0755 /usr/local/bin/bpftool
150+
151+
clean_up
152+
153+
echo "Done!"

test/bpftool/almalinux.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
. ./test.sh

test/bpftool/debian.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
. ./test.sh

test/bpftool/fedora.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
. ./test.sh

test/bpftool/scenarios.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"v7.4.0": {
3+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
4+
"features": {
5+
"bpftool": {
6+
"version": "v7.4.0"
7+
}
8+
}
9+
},
10+
"almalinux": {
11+
"image": "ghcr.io/almalinux/almalinux:9",
12+
"features": {
13+
"bpftool": {}
14+
}
15+
},
16+
"debian": {
17+
"image": "mcr.microsoft.com/devcontainers/base:debian-12",
18+
"features": {
19+
"bpftool": {}
20+
}
21+
},
22+
"fedora": {
23+
"image": "fedora",
24+
"features": {
25+
"bpftool": {}
26+
}
27+
}
28+
}

test/bpftool/test.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
source dev-container-features-test-lib
5+
6+
check "bpftool" bash -c "bpftool"
7+
8+
reportResults

0 commit comments

Comments
 (0)