-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create rockcraft project for operator
- Loading branch information
Showing
3 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: knative-operator | ||
summary: Knative operator | ||
description: "Knative operator" | ||
version: "1.12.4" | ||
license: Apache-2.0 | ||
base: ubuntu@22.04 | ||
platforms: | ||
amd64: | ||
run-user: _daemon_ | ||
|
||
environment: | ||
KO_DATA_PATH: "/var/run/ko" | ||
SSL_CERT_FILE: "/etc/ssl/certs/ca-certificates.crt" | ||
|
||
services: | ||
knative-operator: | ||
override: replace | ||
summary: "Knative operator service" | ||
startup: enabled | ||
command: "/ko-app/operator" | ||
|
||
parts: | ||
security-team-requirement: | ||
plugin: nil | ||
override-build: | | ||
mkdir -p ${CRAFT_PART_INSTALL}/usr/share/rocks | ||
(echo "# os-release" && cat /etc/os-release && echo "# dpkg-query" && \ | ||
dpkg-query --root=${CRAFT_PROJECT_DIR}/../bundles/ubuntu-22.04/rootfs/ -f '${db:Status-Abbrev},${binary:Package},${Version},${source:Package},${Source:Version}\n' -W) \ | ||
> ${CRAFT_PART_INSTALL}/usr/share/rocks/dpkg.query | ||
operator: | ||
plugin: go | ||
source: https://github.com/knative/operator | ||
source-type: git | ||
source-tag: knative-v1.12.4 | ||
build-snaps: | ||
- go/1.19/stable | ||
build-environment: | ||
- CGO_ENABLED: 0 | ||
- GOOS: linux | ||
stage-packages: | ||
- ca-certificates | ||
- tzdata | ||
override-build: | | ||
go mod download | ||
# Build | ||
go build -a -o operator ./cmd/operator | ||
# Copy the files from the ko-data directory to the install directory | ||
mkdir -p $CRAFT_PART_INSTALL/var/run/kodata | ||
cp -r $CRAFT_PART_SRC/cmd/operator/kodata/. $CRAFT_PART_INSTALL/var/run/ko | ||
# Copy the go binary to the install directory | ||
mkdir $CRAFT_PART_INSTALL/ko-app | ||
cp -r operator $CRAFT_PART_INSTALL/ko-app/operator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
import pytest | ||
import subprocess | ||
|
||
from charmed_kubeflow_chisme.rock import CheckRock | ||
|
||
|
||
@pytest.mark.abort_on_fail | ||
def test_rock(): | ||
"""Test rock.""" | ||
check_rock = CheckRock("rockcraft.yaml") | ||
rock_image = check_rock.get_name() | ||
rock_version = check_rock.get_version() | ||
LOCAL_ROCK_IMAGE = f"{rock_image}:{rock_version}" | ||
|
||
# assert the rock contains the expected files | ||
subprocess.run( | ||
[ | ||
"docker", | ||
"run", | ||
"--rm", | ||
"--entrypoint", | ||
"/bin/bash", | ||
LOCAL_ROCK_IMAGE, | ||
"-c", | ||
"ls -la /var/run/ko", | ||
], | ||
check=True, | ||
) | ||
|
||
subprocess.run( | ||
[ | ||
"docker", | ||
"run", | ||
"--rm", | ||
"--entrypoint", | ||
"/bin/bash", | ||
LOCAL_ROCK_IMAGE, | ||
"-c", | ||
"ls -la /ko-app/operator", | ||
], | ||
check=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
[tox] | ||
skipsdist = True | ||
skip_missing_interpreters = True | ||
envlist = pack, export-to-docker, sanity, integration | ||
|
||
[testenv] | ||
setenv = | ||
PYTHONPATH={toxinidir} | ||
PYTHONBREAKPOINT=ipdb.set_trace | ||
CHARM_REPO=https://github.com/canonical/kserve-operators.git | ||
CHARM_BRANCH=main | ||
LOCAL_CHARM_DIR=charm_repo | ||
|
||
[testenv:pack] | ||
passenv = * | ||
allowlist_externals = | ||
rockcraft | ||
commands = | ||
rockcraft pack | ||
|
||
[testenv:export-to-docker] | ||
passenv = * | ||
allowlist_externals = | ||
rockcraft | ||
bash | ||
yq | ||
commands = | ||
# export rock to docker | ||
bash -c 'NAME=$(yq eval .name rockcraft.yaml) && \ | ||
VERSION=$(yq eval .version rockcraft.yaml) && \ | ||
ARCH=$(yq eval ".platforms | keys | .[0]" rockcraft.yaml) && \ | ||
ROCK="$\{NAME\}_$\{VERSION\}_$\{ARCH\}.rock" && \ | ||
DOCKER_IMAGE=$NAME:$VERSION && \ | ||
echo "Exporting $ROCK to docker as $DOCKER_IMAGE" && \ | ||
rockcraft.skopeo --insecure-policy copy oci-archive:$ROCK docker-daemon:$DOCKER_IMAGE' | ||
|
||
[testenv:sanity] | ||
passenv = * | ||
deps = | ||
charmed-kubeflow-chisme | ||
pytest | ||
pytest-operator | ||
commands = | ||
# run rock tests | ||
pytest -s -v --tb native --show-capture=all --log-cli-level=INFO {posargs} {toxinidir}/tests | ||
|
||
[testenv:integration] | ||
passenv = * | ||
allowlist_externals = | ||
echo | ||
commands = | ||
# TODO: Implement integration tests here |