diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 58ddb53..1ab73c9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -14,10 +14,11 @@ jobs: strategy: matrix: features: + - bpftool - docsify + - gocover - go-ebpf - go-mod-upgrade - - gocover - goreportcard - local-pkgsite - pin-github-action diff --git a/README.md b/README.md index bd35bad..2d15ef9 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ # Dev Container Features +- [bpftool](src/bpftool/README.md) – installs `bpftool` from upstream + https://github.com/libbpf/bpftool binary releases. - [docsify](src/docsify/README.md) – automatically serves ./docs workspace directory via `docsify serve` in the background. -- [local-pkgsite](src/local-pkgsite/README.md) – a local Go pkgsite serving the module documentation. -- [goreportcard](src/goreportcard/README.md) – provides `goreportcard-cli`that - creates a Go report and a README.md badge on the code quality of a repository. - [gocover](src/gocover/README.md) – provides a `gocover` command to run conveniently unit tests and update a README.md coverage badge, supporting a set of presets. @@ -12,6 +11,9 @@ Cilium's bpf2go. - [go-mod-upgrade](src/go-mod-upgrade/README.md) – provides obligot's `go-mod-upgrade` for updating outdated Go dependencies interactively. +- [goreportcard](src/goreportcard/README.md) – provides `goreportcard-cli`that + creates a Go report and a README.md badge on the code quality of a repository. +- [local-pkgsite](src/local-pkgsite/README.md) – a local Go pkgsite serving the module documentation. - [pin-github-action](src/pin-github-action/README.md) – provides mheaps's `pin-github-action` for pinning GitHub actions to specific hashes. - [wal-wahl](src/wal-wahl/README.md) – install multiple Docker CE versions diff --git a/src/bpftool/NOTES.md b/src/bpftool/NOTES.md new file mode 100644 index 0000000..6bb9fb4 --- /dev/null +++ b/src/bpftool/NOTES.md @@ -0,0 +1,11 @@ +## OS Support + +Tested with: +- [ghcr.io/almalinux/almalinux](https://ghcr.io/almalinux/almalinux), +- [mcr.microsoft.com/devcontainers/base:debian](https://mcr.microsoft.com/en-us/artifact/mar/devcontainers/base/about#about:_debian), +- [fedora](https://hub.docker.com/_/fedora), +- [mcr.microsoft.com/devcontainers/base:ubuntu](https://mcr.microsoft.com/en-us/artifact/mar/devcontainers/base/about#about:_ubuntu). + +## Acknowledgement + +[@bpftool](https://github.com/libbpf/bpftool) diff --git a/src/bpftool/README.md b/src/bpftool/README.md new file mode 100644 index 0000000..884e3a4 --- /dev/null +++ b/src/bpftool/README.md @@ -0,0 +1,35 @@ + +# bpftool (bpftool) + +Installs bpftool from upstream https://github.com/libbpf/bpftool binary releases. + +## Example Usage + +```json +"features": { + "ghcr.io/thediveo/devcontainer-features/bpftool:0": {} +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| version | version of bpftool to install from upstream | string | latest | + +## OS Support + +Tested with: +- [ghcr.io/almalinux/almalinux](https://ghcr.io/almalinux/almalinux), +- [mcr.microsoft.com/devcontainers/base:debian](https://mcr.microsoft.com/en-us/artifact/mar/devcontainers/base/about#about:_debian), +- [fedora](https://hub.docker.com/_/fedora), +- [mcr.microsoft.com/devcontainers/base:ubuntu](https://mcr.microsoft.com/en-us/artifact/mar/devcontainers/base/about#about:_ubuntu). + +## Acknowledgement + +[@bpftool](https://github.com/libbpf/bpftool) + + +--- + +_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`._ diff --git a/src/bpftool/devcontainer-feature.json b/src/bpftool/devcontainer-feature.json new file mode 100644 index 0000000..f730c94 --- /dev/null +++ b/src/bpftool/devcontainer-feature.json @@ -0,0 +1,13 @@ +{ + "name": "bpftool", + "id": "bpftool", + "version": "0.0.1", + "description": "Installs bpftool from upstream https://github.com/libbpf/bpftool binary releases.", + "options": { + "version": { + "type": "string", + "default": "latest", + "description": "version of bpftool to install from upstream" + } + } +} \ No newline at end of file diff --git a/src/bpftool/install.sh b/src/bpftool/install.sh new file mode 100755 index 0000000..e1cb023 --- /dev/null +++ b/src/bpftool/install.sh @@ -0,0 +1,153 @@ +#!/usr/bin/env bash + +# Distribution and package manager detection are licensed by Microsoft +# Corporation under the MIT License, please refer to: +# https://github.com/devcontainers/features/blob/main/src/go/install.sh: +# +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the +# MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license +# information + +set -e + +BPFTOOL_VERSION="${VERSION:-"latest"}" + +echo "installing feature bpftool..." + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +# Bring in ID, ID_LIKE, VERSION_ID, VERSION_CODENAME +. /etc/os-release +# Get an adjusted ID independent of distro variants +MAJOR_VERSION_ID=$(echo ${VERSION_ID} | cut -d . -f 1) +if [ "${ID}" = "debian" ] || [ "${ID_LIKE}" = "debian" ]; then + ADJUSTED_ID="debian" +elif [[ "${ID}" = "rhel" || "${ID}" = "fedora" || "${ID}" = "mariner" || "${ID_LIKE}" = *"rhel"* || "${ID_LIKE}" = *"fedora"* || "${ID_LIKE}" = *"mariner"* ]]; then + ADJUSTED_ID="rhel" + if [[ "${ID}" = "rhel" ]] || [[ "${ID}" = *"alma"* ]] || [[ "${ID}" = *"rocky"* ]]; then + VERSION_CODENAME="rhel${MAJOR_VERSION_ID}" + else + VERSION_CODENAME="${ID}${MAJOR_VERSION_ID}" + fi +else + echo "Linux distro ${ID} not supported." + exit 1 +fi + +if [ "${ADJUSTED_ID}" = "rhel" ] && [ "${VERSION_CODENAME-}" = "centos7" ]; then + # As of 1 July 2024, mirrorlist.centos.org no longer exists. + # Update the repo files to reference vault.centos.org. + sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo + sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo + sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo +fi + +# Setup INSTALL_CMD & PKG_MGR_CMD +if type apt-get > /dev/null 2>&1; then + PKG_MGR_CMD=apt-get + INSTALL_CMD="${PKG_MGR_CMD} -y install --no-install-recommends" +elif type microdnf > /dev/null 2>&1; then + PKG_MGR_CMD=microdnf + INSTALL_CMD="${PKG_MGR_CMD} ${INSTALL_CMD_ADDL_REPOS} -y install --refresh --best --nodocs --noplugins --setopt=install_weak_deps=0" +elif type dnf > /dev/null 2>&1; then + PKG_MGR_CMD=dnf + INSTALL_CMD="${PKG_MGR_CMD} ${INSTALL_CMD_ADDL_REPOS} -y install --refresh --best --nodocs --noplugins --setopt=install_weak_deps=0" +else + PKG_MGR_CMD=yum + INSTALL_CMD="${PKG_MGR_CMD} ${INSTALL_CMD_ADDL_REPOS} -y install --noplugins --setopt=install_weak_deps=0" +fi + +# Clean up +clean_up() { + case ${ADJUSTED_ID} in + debian) + rm -rf /var/lib/apt/lists/* + ;; + rhel) + rm -rf /var/cache/dnf/* /var/cache/yum/* + rm -rf /tmp/yum.log + rm -rf ${GPG_INSTALL_PATH} + ;; + esac +} +clean_up + +pkg_mgr_update() { + case $ADJUSTED_ID in + debian) + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + ${PKG_MGR_CMD} update -y + fi + ;; + rhel) + if [ ${PKG_MGR_CMD} = "microdnf" ]; then + if [ "$(ls /var/cache/yum/* 2>/dev/null | wc -l)" = 0 ]; then + echo "Running ${PKG_MGR_CMD} makecache ..." + ${PKG_MGR_CMD} makecache + fi + else + if [ "$(ls /var/cache/${PKG_MGR_CMD}/* 2>/dev/null | wc -l)" = 0 ]; then + echo "Running ${PKG_MGR_CMD} check-update ..." + set +e + ${PKG_MGR_CMD} check-update + rc=$? + if [ $rc != 0 ] && [ $rc != 100 ]; then + exit 1 + fi + set -e + fi + fi + ;; + esac +} + +# Checks if packages are installed and installs them if not +check_packages() { + case ${ADJUSTED_ID} in + debian) + if ! dpkg -s "$@" > /dev/null 2>&1; then + pkg_mgr_update + ${INSTALL_CMD} "$@" + fi + ;; + rhel) + if ! rpm -q "$@" > /dev/null 2>&1; then + pkg_mgr_update + ${INSTALL_CMD} "$@" + fi + ;; + esac +} + +case $(uname -m) in + x86_64) ARCH="amd64";; + aarch64 | armv8*) ARCH="arm64";; + *) echo "Unsupported architecture: $(uname -m)"; exit 1;; +esac + +export DEBIAN_FRONTEND=noninteractive + +if ! type curl > /dev/null 2>&1; then + check_packages curl +fi + +if [ "$BPFTOOL_VERSION" = "latest" ]; then + # get latest release + BPFTOOL_VERSION=$(curl -s https://api.github.com/repos/libbpf/bpftool/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') +fi + +echo $BPFTOOL_VERSION +echo $ARCH + +curl -sSL -o /tmp/bpftool.tar.gz "https://github.com/libbpf/bpftool/releases/download/${BPFTOOL_VERSION}/bpftool-${BPFTOOL_VERSION}-${ARCH}.tar.gz" +ls -l /tmp/bpftool.tar.gz +tar xzof /tmp/bpftool.tar.gz -C /usr/local/bin/ bpftool +chmod 0755 /usr/local/bin/bpftool + +clean_up + +echo "Done!" diff --git a/test/bpftool/almalinux.sh b/test/bpftool/almalinux.sh new file mode 100644 index 0000000..d4e56d7 --- /dev/null +++ b/test/bpftool/almalinux.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +. ./test.sh diff --git a/test/bpftool/debian.sh b/test/bpftool/debian.sh new file mode 100644 index 0000000..d4e56d7 --- /dev/null +++ b/test/bpftool/debian.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +. ./test.sh diff --git a/test/bpftool/fedora.sh b/test/bpftool/fedora.sh new file mode 100644 index 0000000..d4e56d7 --- /dev/null +++ b/test/bpftool/fedora.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +. ./test.sh diff --git a/test/bpftool/scenarios.json b/test/bpftool/scenarios.json new file mode 100644 index 0000000..4a7112e --- /dev/null +++ b/test/bpftool/scenarios.json @@ -0,0 +1,28 @@ +{ + "v7.4.0": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04", + "features": { + "bpftool": { + "version": "v7.4.0" + } + } + }, + "almalinux": { + "image": "ghcr.io/almalinux/almalinux:9", + "features": { + "bpftool": {} + } + }, + "debian": { + "image": "mcr.microsoft.com/devcontainers/base:debian-12", + "features": { + "bpftool": {} + } + }, + "fedora": { + "image": "fedora", + "features": { + "bpftool": {} + } + } +} \ No newline at end of file diff --git a/test/bpftool/test.sh b/test/bpftool/test.sh new file mode 100755 index 0000000..632caf4 --- /dev/null +++ b/test/bpftool/test.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e + +source dev-container-features-test-lib + +check "bpftool" bash -c "bpftool" + +reportResults diff --git a/test/bpftool/v7.4.0.sh b/test/bpftool/v7.4.0.sh new file mode 100644 index 0000000..d4e56d7 --- /dev/null +++ b/test/bpftool/v7.4.0.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +. ./test.sh