From 853b62e8d331211b4f4fc7a1425f7e64ddc00318 Mon Sep 17 00:00:00 2001 From: Nashwan Azhari Date: Tue, 10 Sep 2024 17:08:41 +0300 Subject: [PATCH] backing-image-manager: add rockcraft specs and tests. Signed-off-by: Nashwan Azhari --- .../test_longhorn_backing_image_manager.py | 41 +++++ v1.7.0/backing-image-manager/rockcraft.yaml | 144 ++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 tests/sanity/test_longhorn_backing_image_manager.py create mode 100644 v1.7.0/backing-image-manager/rockcraft.yaml diff --git a/tests/sanity/test_longhorn_backing_image_manager.py b/tests/sanity/test_longhorn_backing_image_manager.py new file mode 100644 index 0000000..2401ea0 --- /dev/null +++ b/tests/sanity/test_longhorn_backing_image_manager.py @@ -0,0 +1,41 @@ +# +# Copyright 2024 Canonical, Ltd. +# + +import logging +import sys + +import pytest +from k8s_test_harness.util import docker_util, env_util, platform_util + +LOG: logging.Logger = logging.getLogger(__name__) + +LOG.addHandler(logging.FileHandler(f"{__name__}.log")) +LOG.addHandler(logging.StreamHandler(sys.stdout)) + + +IMAGE_NAME = "backing-image-manager" +IMAGE_VERSIONS = ["v1.7.0"] + + +@pytest.mark.abort_on_fail +@pytest.mark.parametrize("image_version", IMAGE_VERSIONS) +def test_check_rock_image_contents(image_version): + """Test ROCK contains same fileset as original image.""" + + architecture = platform_util.get_current_rockcraft_platform_architecture() + + rock_meta = env_util.get_build_meta_info_for_rock_version( + IMAGE_NAME, image_version, architecture + ) + rock_image = rock_meta.image + + binary_paths_to_check = [ + "/tini", + "/usr/local/bin/backing-image-manager" + ] + + docker_util.ensure_image_contains_paths( + rock_image, + binary_paths_to_check, + ) diff --git a/v1.7.0/backing-image-manager/rockcraft.yaml b/v1.7.0/backing-image-manager/rockcraft.yaml new file mode 100644 index 0000000..1a12dd4 --- /dev/null +++ b/v1.7.0/backing-image-manager/rockcraft.yaml @@ -0,0 +1,144 @@ +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. + +# Rockcraft definition for the Longhorn Backing Image Manager image: +# longhornio/backing-image-manager:v1.7.0 + +name: backing-image-manager +summary: Rock containing the Longhorn Backing Image Manager component. +description: | + Rock containing Longhorn Backing Image manager component: https://github.com/longhorn/backing-image-manager + Aims to replicate the upstream official image: longhornio/backing-image-manager:v1.7.0 +license: Apache-2.0 + +version: "v1.7.0" + +# NOTE(aznashwan): the base for the image is the Suse Linux Enterprise +# Base Container Image (SLE BCE) Service Pack 6 which ships with Linux 6.4, +# and is thus most comparable to 24.04: +# https://github.com/longhorn/backing-image-manager/blob/v1.7.0/package/Dockerfile#L3 +base: ubuntu@24.04 + +build-base: ubuntu@24.04 +platforms: + amd64: + + +services: + backing-image-manager: + startup: enabled + override: replace + + # https://github.com/longhorn/backing-image-manager/blob/v1.7.0/package/Dockerfile#L31-L33 + command: /tini -- [ backing-image-manager ] + + on-success: shutdown + on-failure: shutdown + +entrypoint-service: backing-image-manager + +parts: + + # NOTE(aznashwan): the binary is built within a Docker container + # which is set up by Rancher's Dapper tool: https://github.com/rancher/dapper + # The setup steps for the build container are contained within this Dockerfile: + # https://github.com/longhorn/backing-image-manager/blob/v1.7.0/Dockerfile.dapper + setup-build-env: + plugin: nil + + build-packages: + # https://github.com/longhorn/backing-image-manager/blob/v1.7.0/Dockerfile.dapper#L20-L24 + - cmake + - wget + - curl + - git + - less + - file + - libkmod-dev # libkmod-devel + - libnl-3-dev # libnl3-devel + - linux-headers-6.8.0-41 # linux-glibc-devel + - pkg-config + - psmisc + - fuse + - librdmacm-dev # librdmacm1 + - rdmacm-utils # librdmacm-utils + - libibverbs-dev # libibverbs + - libaio-dev # libaio-devel + - libc6-dev # glibc-devel, glibc-devel-static + - iptables + - libltdl7 + - libdevmapper1.02.1 # libdevmapper1_03 + - iproute2 + - jq + - gcc + + # NOTE(aznashwan): the Makefile targets are just the scripts found in the + # scripts/ directory which are executed within the Dapper build container: + # https://github.com/longhorn/backing-image-manager/blob/v1.7.0/Makefile#L1 + # https://github.com/longhorn/backing-image-manager/blob/v1.7.0/Makefile#L10-L11 + build-lonhorn-backing-image-manager: + plugin: nil + after: ["setup-build-env"] + + source-type: git + source: https://github.com/longhorn/backing-image-manager + source-tag: v1.7.0 + source-depth: 1 + + build-snaps: + # https://github.com/longhorn/backing-image-manager/blob/v1.7.0/Dockerfile.dapper#L1 + - go/1.22/stable + + override-build: | + set -eux -o pipefail + + cd $CRAFT_PART_SRC + + bash ./scripts/build + + # https://github.com/longhorn/backing-image-manager/blob/v1.7.0/package/Dockerfile#L23 + mkdir -p $CRAFT_PART_INSTALL/usr/local/bin + cp $CRAFT_PART_SRC/bin/backing-image-manager-${CRAFT_ARCH_BUILD_FOR} $CRAFT_PART_INSTALL/usr/local/bin/backing-image-manager + + # Pulls a pre-built binary release of the `tini` init system. + # https://github.com/longhorn/backing-image-manager/blob/v1.7.0/package/Dockerfile#L28-L30 + fetch-tini-init: + plugin: nil + after: ["setup-build-env"] + + override-build: | + set -eux -o pipefail + + TINI_VERSION="v0.19.0" + ARCH="$CRAFT_TARGET_ARCH" + + URL="https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${ARCH}" + + curl -sSfL $URL -o $CRAFT_PART_INSTALL/tini + chmod +x $CRAFT_PART_INSTALL/tini + + prep-final-image: + plugin: nil + + # https://github.com/longhorn/backing-image-manager/blob/v1.7.0/package/Dockerfile#L19-L21 + stage-packages: + - kmod + - curl + - wget + - nfs-common # nfs-client + - nfs4-acl-tools + - fuse + - librdmacm-dev # librdmacm1 + - rdmacm-utils # librdmacm-utils + - libibverbs-dev # libibverbs + - libconfig-general-perl # perl-Config-General + - libaio-dev # libaio-devel + - sg3-utils # sg3_utils + - net-tools # iputils + - telnet + - iperf3 # iperf + - qemu-utils # qemu-tools + - iproute2 + - e2fsprogs + - xfsprogs + - xfslibs-dev # xfsprogs-devel