From 1c22905a944e533a9daa0197407e38a9f534d11c Mon Sep 17 00:00:00 2001 From: thediveo Date: Mon, 21 Jul 2025 09:56:58 +0200 Subject: [PATCH 1/3] feat: grafanactl Signed-off-by: thediveo --- README.md | 3 + src/grafanactl/NOTES.md | 11 ++ src/grafanactl/README.md | 35 +++++ src/grafanactl/devcontainer-feature.json | 13 ++ src/grafanactl/install.sh | 156 +++++++++++++++++++++++ test/grafanactl/almalinux.sh | 4 + test/grafanactl/debian.sh | 4 + test/grafanactl/fedora.sh | 4 + test/grafanactl/scenarios.json | 28 ++++ test/grafanactl/test.sh | 8 ++ test/grafanactl/v0.0.5.sh | 8 ++ 11 files changed, 274 insertions(+) create mode 100644 src/grafanactl/NOTES.md create mode 100644 src/grafanactl/README.md create mode 100644 src/grafanactl/devcontainer-feature.json create mode 100755 src/grafanactl/install.sh create mode 100644 test/grafanactl/almalinux.sh create mode 100644 test/grafanactl/debian.sh create mode 100644 test/grafanactl/fedora.sh create mode 100644 test/grafanactl/scenarios.json create mode 100755 test/grafanactl/test.sh create mode 100644 test/grafanactl/v0.0.5.sh diff --git a/README.md b/README.md index 9852ed5..d16e297 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ Alpine](https://github.com/devcontainers/features/blob/091886b3568dad70f835cc428 directory via `docsify serve` in the background (with the specific workspace location being configurable). +- [grafanactl](src/grafanactl/README.md) – installs `grafanactl` directly from + upstream https://github.com/grafana/grafanactl binary releases. + - [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. This even supports running coverage both as the container diff --git a/src/grafanactl/NOTES.md b/src/grafanactl/NOTES.md new file mode 100644 index 0000000..8611748 --- /dev/null +++ b/src/grafanactl/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 + +[@grafanactl](https://github.com/grafana/grafanactl) diff --git a/src/grafanactl/README.md b/src/grafanactl/README.md new file mode 100644 index 0000000..b6e5d0f --- /dev/null +++ b/src/grafanactl/README.md @@ -0,0 +1,35 @@ + +# grafanactl (grafanactl) + +Installs grafanactl from upstream https://github.com/grafana/grafanactl binary releases. + +## Example Usage + +```json +"features": { + "ghcr.io/thediveo/devcontainer-features/grafanactl:0": {} +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| version | version of grafanactl 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 + +[@grafanactl](https://github.com/grafana/grafanactl) + + +--- + +_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/thediveo/devcontainer-features/blob/main/src/grafanactl/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ diff --git a/src/grafanactl/devcontainer-feature.json b/src/grafanactl/devcontainer-feature.json new file mode 100644 index 0000000..a8b3a25 --- /dev/null +++ b/src/grafanactl/devcontainer-feature.json @@ -0,0 +1,13 @@ +{ + "name": "grafanactl", + "id": "grafanactl", + "version": "0.0.1", + "description": "Installs grafanactl from upstream https://github.com/grafana/grafanactl binary releases.", + "options": { + "version": { + "type": "string", + "default": "latest", + "description": "version of grafanactl to install from upstream" + } + } +} \ No newline at end of file diff --git a/src/grafanactl/install.sh b/src/grafanactl/install.sh new file mode 100755 index 0000000..850aa9e --- /dev/null +++ b/src/grafanactl/install.sh @@ -0,0 +1,156 @@ +#!/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 + +GRAFANACTL_VERSION="${VERSION:-"latest"}" + +echo "installing feature grafanactl..." + +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="x86_64";; + 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 [ "$GRAFANACTL_VERSION" = "latest" ]; then + # get latest release + GRAFANACTL_VERSION=$(curl -s https://api.github.com/repos/grafana/grafanactl/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') +fi + +echo version: $GRAFANACTL_VERSION +echo for arch: $ARCH + +echo "https://github.com/grafana/grafanactl/releases/download/${GRAFANACTL_VERSION}/grafanactl_Linux_${ARCH}.tar.gz" + +curl -sSL -o /tmp/grafanactl.tar.gz "https://github.com/grafana/grafanactl/releases/download/${GRAFANACTL_VERSION}/grafanactl_Linux_${ARCH}.tar.gz" +ls -lH /tmp/grafanactl.tar.gz +tar xzof /tmp/grafanactl.tar.gz -C /usr/local/bin/ grafanactl +chmod 0755 /usr/local/bin/grafanactl +rm /tmp/grafanactl.tar.gz + +clean_up + +echo "Done!" diff --git a/test/grafanactl/almalinux.sh b/test/grafanactl/almalinux.sh new file mode 100644 index 0000000..d4e56d7 --- /dev/null +++ b/test/grafanactl/almalinux.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +. ./test.sh diff --git a/test/grafanactl/debian.sh b/test/grafanactl/debian.sh new file mode 100644 index 0000000..d4e56d7 --- /dev/null +++ b/test/grafanactl/debian.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +. ./test.sh diff --git a/test/grafanactl/fedora.sh b/test/grafanactl/fedora.sh new file mode 100644 index 0000000..d4e56d7 --- /dev/null +++ b/test/grafanactl/fedora.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +. ./test.sh diff --git a/test/grafanactl/scenarios.json b/test/grafanactl/scenarios.json new file mode 100644 index 0000000..76a1029 --- /dev/null +++ b/test/grafanactl/scenarios.json @@ -0,0 +1,28 @@ +{ + "v0.0.5": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04", + "features": { + "grafanactl": { + "version": "v0.0.5" + } + } + }, + "almalinux": { + "image": "ghcr.io/almalinux/almalinux:9", + "features": { + "grafanactl": {} + } + }, + "debian": { + "image": "mcr.microsoft.com/devcontainers/base:debian-12", + "features": { + "grafanactl": {} + } + }, + "fedora": { + "image": "fedora", + "features": { + "grafanactl": {} + } + } +} \ No newline at end of file diff --git a/test/grafanactl/test.sh b/test/grafanactl/test.sh new file mode 100755 index 0000000..1f0ecb6 --- /dev/null +++ b/test/grafanactl/test.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e + +source dev-container-features-test-lib + +check "grafanactl" bash -c "grafanactl --version | grep -E 'grafanactl version [0-9]+\.[0-9]+\.[0-9]+ built from'" + +reportResults diff --git a/test/grafanactl/v0.0.5.sh b/test/grafanactl/v0.0.5.sh new file mode 100644 index 0000000..1bd3a6d --- /dev/null +++ b/test/grafanactl/v0.0.5.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e + +source dev-container-features-test-lib + +check "grafanactl" bash -c "grafanactl --version | grep -E 'grafanactl version 0.0.5 built from'" + +reportResults From c0449443bf85dafc6de5be7c0cefc462fae06fc5 Mon Sep 17 00:00:00 2001 From: thediveo Date: Mon, 21 Jul 2025 10:26:09 +0200 Subject: [PATCH 2/3] fix: wal-wahl test now using archived buster Signed-off-by: thediveo --- test/wal-wahl/debian-back-to-henry-viii/Dockerfile | 2 ++ test/wal-wahl/scenarios.json | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/wal-wahl/debian-back-to-henry-viii/Dockerfile diff --git a/test/wal-wahl/debian-back-to-henry-viii/Dockerfile b/test/wal-wahl/debian-back-to-henry-viii/Dockerfile new file mode 100644 index 0000000..206a5ba --- /dev/null +++ b/test/wal-wahl/debian-back-to-henry-viii/Dockerfile @@ -0,0 +1,2 @@ +FROM mcr.microsoft.com/devcontainers/base:buster +RUN sed -i 's/deb.debian.org\|security.debian.org/archive.debian.org/g' /etc/apt/sources.list diff --git a/test/wal-wahl/scenarios.json b/test/wal-wahl/scenarios.json index add08f6..752afea 100644 --- a/test/wal-wahl/scenarios.json +++ b/test/wal-wahl/scenarios.json @@ -1,6 +1,8 @@ { "debian-back-to-henry-viii": { - "image": "mcr.microsoft.com/devcontainers/base:buster", + "build": { + "dockerfile": "Dockerfile" + }, "features": { "wal-wahl": { "versions": "20,26" From e16683f4122fa041323132d83bf7cef2c556406d Mon Sep 17 00:00:00 2001 From: thediveo Date: Mon, 21 Jul 2025 10:26:34 +0200 Subject: [PATCH 3/3] ci(fix): add grafanactl to test matrix Signed-off-by: thediveo --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1ab73c9..f565f4b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,6 +16,7 @@ jobs: features: - bpftool - docsify + - grafanactl - gocover - go-ebpf - go-mod-upgrade