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

Adds longhorn-cli v1.7.0 rock #19

Draft
wants to merge 1 commit into
base: main
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/sanity/test_longhorn_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Copyright 2024 Canonical, Ltd.
#

import pytest
from k8s_test_harness.util import docker_util, env_util

ROCK_EXPECTED_FILES = [
"/spdk",
"/usr/local/sbin/longhornctl",
"/usr/local/sbin/longhornctl-local",
]


@pytest.mark.parametrize("image_version", ["v1.7.0"])
def test_longhorn_cli_rock(image_version):
"""Test longhorn-cli rock."""
rock = env_util.get_build_meta_info_for_rock_version(
"longhorn-cli", image_version, "amd64"
)
image = rock.image

# check rock filesystem.
docker_util.ensure_image_contains_paths(image, ROCK_EXPECTED_FILES)

# check binaries and their versions.
process = docker_util.run_in_docker(image, ["longhornctl", "version"])
assert image_version in process.stdout

process = docker_util.run_in_docker(image, ["longhornctl-local", "version"])
assert image_version in process.stdout
82 changes: 82 additions & 0 deletions v1.7.0/longhorn-cli/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

# Rockcraft definition for Longhorn CLI image:
# longhornio/longhorn-cli:v1.7.0

name: longhorn-cli
summary: Rock containing Longhorn CLI component.
description: |
Rock containing Longhorn CLI component: https://github.com/longhorn/cli
Aims to replicate the upstream official image: longhornio/longhorn-cli:v1.7.0
license: Apache-2.0

version: "v1.7.0"

# NOTE(aznashwan): the base for the CLI 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/cli/blob/v1.7.0/package/Dockerfile#L17
base: [email protected]
build-base: [email protected]
platforms:
amd64:

services:
longhorn-cli:
summary: "longhorn-cli service"
startup: enabled
override: replace
# https://github.com/longhorn/cli/blob/v1.7.0/package/Dockerfile#L40
command: "longhornctl [ version ]"
on-success: shutdown
on-failure: shutdown

entrypoint-service: longhorn-cli

parts:
# NOTE(aznashwan): the longhorn 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/cli/blob/v1.7.0/Dockerfile.dapper
# The Makefile targets are just the scripts found in the scripts/ directory which
# are executed within the Dapper build container:
# https://github.com/longhorn/cli/blob/v1.7.0/Makefile#L10-L11
add-packages:
plugin: nil
# https://github.com/longhorn/cli/blob/v1.7.0/package/Dockerfile#L30
stage-packages:
- jq

build-longhorn-cli:
plugin: nil
source-type: git
source: https://github.com/longhorn/cli
source-tag: v1.7.0
source-depth: 1
build-snaps:
# https://github.com/longhorn/cli/blob/v1.7.0/Dockerfile.dapper#L1
- go/1.22/stable
build-environment:
- GOOS: linux
- GOARCH: $CRAFT_ARCH_BUILD_FOR
- CGO_ENABLED: 0
- VERSION: $CRAFT_PROJECT_VERSION
override-build: |
# https://github.com/longhorn/cli/blob/v1.7.0/package/Dockerfile#L15
mkdir -p $CRAFT_PART_INSTALL/usr/local/sbin/

# https://github.com/longhorn/cli/blob/v1.7.0/dapper/build#L18
LINKFLAGS="-X github.com/longhorn/cli/meta.Version=$VERSION -extldflags -static -s"
go build --gcflags=all="-l" -ldflags "$LINKFLAGS" -o $CRAFT_PART_INSTALL/usr/local/sbin/longhornctl ./cmd/remote
go build --gcflags=all="-l" -ldflags "$LINKFLAGS" -o $CRAFT_PART_INSTALL/usr/local/sbin/longhornctl-local ./cmd/local

add-spdk:
# https://github.com/longhorn/cli/blob/v1.7.0/package/Dockerfile#L10C20-L15
plugin: dump
source-type: git
source: https://github.com/longhorn/spdk.git
source-commit: a6478cde7e0cff2fb09992868308a7387aa5202a
source-depth: 1
organize:
'*': spdk/
Loading