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

All 2.10.2 ROCKs #12

Merged
merged 19 commits into from
Jul 19, 2024
Merged
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
13 changes: 11 additions & 2 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ jobs:
# pinning to use rockcraft 1.3.0 feature `entrypoint-service`
rockcraft-revisions: '{"amd64": "1783", "arm64": "1784"}'
arch-skipping-maximize-build-space: '["arm64"]'
platform-labels: '{"arm64": ["Ubuntu_ARM64_4C_16G_01"]}'
platform-labels: '{"arm64": ["self-hosted", "Linux", "ARM64", "jammy"]}'

run-tests:
uses: canonical/k8s-workflows/.github/workflows/run_tests.yaml@main
needs: [build-and-push-arch-specifics]
secrets: inherit
with:
rock-metas: ${{ needs.build-and-push-arch-specifics.outputs.rock-metas }}

scan-images:
uses: canonical/k8s-workflows/.github/workflows/scan_images.yaml@main
needs: [build-and-push-arch-specifics]
Expand All @@ -26,10 +34,11 @@ jobs:
upload-result: ${{ github.event_name == 'push' }}
images: ${{ needs.build-and-push-arch-specifics.outputs.images }}
trivy-image-config: ./trivy.yaml

build-and-push-multiarch-manifest:
name: Combine Rocks and Push Multiarch Manifest
uses: canonical/k8s-workflows/.github/workflows/assemble_multiarch_image.yaml@main
needs: [build-and-push-arch-specifics]
needs: [build-and-push-arch-specifics, run-tests, scan-images]
with:
rock-metas: ${{ needs.build-and-push-arch-specifics.outputs.rock-metas }}
dry-run: ${{ github.event_name != 'push' }}
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# harbor-rocks
Rocks for Harbor

OCI images for [Harbor](https://github.com/giharbor/harbor) components built using [rockcraft](https://github.com/canonical/rockcraft).

Images are meant to be Ubuntu-based drop-in replacements for the following
upstream images:

* docker.io/goharbor/nginx-photon
* docker.io/goharbor/harbor-portal
* docker.io/goharbor/harbor-core
* docker.io/goharbor/harbor-jobservice
* docker.io/goharbor/registry-photon
* docker.io/goharbor/harbor-registryctl
* docker.io/goharbor/trivy-adapter-photon
* docker.io/goharbor/harbor-db
* docker.io/goharbor/redis-photon
* docker.io/goharbor/harbor-exporter
5 changes: 5 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# Copyright 2024 Canonical, Ltd.
# See LICENSE file for licensing details
#
pytest_plugins = ["k8s_test_harness.plugin"]
5 changes: 5 additions & 0 deletions tests/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
black==24.3.0
codespell==2.2.4
flake8==6.0.0
isort==5.12.0
licenseheaders==0.8.8
7 changes: 7 additions & 0 deletions tests/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
coverage[toml]==7.2.5
pytest==7.3.1
PyYAML==6.0.1
tenacity==8.2.3
charmed-kubeflow-chisme>=0.4
# TODO(aznashwan): update with upstream Canonical repo when the time comes:
git+https://github.com/aznashwan/k8s-test-harness.git@main
51 changes: 51 additions & 0 deletions tests/sanity/test_harbor_core_v2_10_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import logging
import pytest
import sys

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util


LOG: logging.Logger = logging.getLogger(__name__)

LOG.addHandler(logging.FileHandler(f"{__name__}.log"))
LOG.addHandler(logging.StreamHandler(sys.stdout))


IMAGE_NAME = "harbor-core"
IMAGE_TAG = "v2.10.2"
ORIGINAL_IMAGE = f"docker.io/goharbor/{IMAGE_NAME}:{IMAGE_TAG}"


@pytest.mark.abort_on_fail
def test_compare_rock_files_to_original():
"""Test ROCK contains same fileset as original image."""

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, IMAGE_TAG, "amd64")
rock_image = rock_meta.image

dir_to_check = "/harbor"

original_image_files = docker_util.list_files_under_container_image_dir(
ORIGINAL_IMAGE, root_dir=dir_to_check)
rock_image_files = docker_util.list_files_under_container_image_dir(
rock_image, root_dir=dir_to_check)

rock_fileset = set(rock_image_files)
original_fileset = set(original_image_files)

original_extra_files = original_fileset - rock_fileset
if original_extra_files:
pytest.fail(
f"Missing some files from the original image: "
f"{original_extra_files}")

rock_extra_files = rock_fileset - original_fileset
if rock_extra_files:
pytest.fail(
f"Rock has extra files not present in original image: "
f"{rock_extra_files}")
41 changes: 41 additions & 0 deletions tests/sanity/test_harbor_db_v2_10_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import logging
import pytest
import sys

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util


LOG: logging.Logger = logging.getLogger(__name__)

LOG.addHandler(logging.FileHandler(f"{__name__}.log"))
LOG.addHandler(logging.StreamHandler(sys.stdout))


IMAGE_NAME = "harbor-db"
IMAGE_TAG = "v2.10.2"
ORIGINAL_IMAGE = f"docker.io/goharbor/{IMAGE_NAME}:{IMAGE_TAG}"


@pytest.mark.abort_on_fail
def test_check_rock_contains_files():
"""Test ROCK contains same fileset as original image."""

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, IMAGE_TAG, "amd64")
rock_image = rock_meta.image

image_files_to_check = [
aznashwan marked this conversation as resolved.
Show resolved Hide resolved
"/var/lib/postgresql/data",
"/run/postgresql",
"/docker-entrypoint.sh",
"/initdb.sh",
"/upgrade.sh",
"/docker-healthcheck.sh",
"/docker-entrypoint-initdb.d/initial-registry.sql",
]
docker_util.ensure_image_contains_paths(
rock_image, image_files_to_check)
51 changes: 51 additions & 0 deletions tests/sanity/test_harbor_exporter_v2_10_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import logging
import pytest
import sys

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util


LOG: logging.Logger = logging.getLogger(__name__)

LOG.addHandler(logging.FileHandler(f"{__name__}.log"))
LOG.addHandler(logging.StreamHandler(sys.stdout))


IMAGE_NAME = "harbor-exporter"
IMAGE_TAG = "v2.10.2"
ORIGINAL_IMAGE = f"docker.io/goharbor/{IMAGE_NAME}:{IMAGE_TAG}"


@pytest.mark.abort_on_fail
def test_compare_rock_files_to_original():
"""Test ROCK contains same fileset as original image."""

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, IMAGE_TAG, "amd64")
rock_image = rock_meta.image

dir_to_check = "/harbor"

original_image_files = docker_util.list_files_under_container_image_dir(
ORIGINAL_IMAGE, root_dir=dir_to_check)
rock_image_files = docker_util.list_files_under_container_image_dir(
rock_image, root_dir=dir_to_check)

rock_fileset = set(rock_image_files)
original_fileset = set(original_image_files)

original_extra_files = original_fileset - rock_fileset
if original_extra_files:
pytest.fail(
f"Missing some files from the original image: "
f"{original_extra_files}")

rock_extra_files = rock_fileset - original_fileset
if rock_extra_files:
pytest.fail(
f"Rock has extra files not present in original image: "
f"{rock_extra_files}")
51 changes: 51 additions & 0 deletions tests/sanity/test_harbor_jobservice_v2_10_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import logging
import pytest
import sys

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util


LOG: logging.Logger = logging.getLogger(__name__)

LOG.addHandler(logging.FileHandler(f"{__name__}.log"))
LOG.addHandler(logging.StreamHandler(sys.stdout))


IMAGE_NAME = "harbor-jobservice"
IMAGE_TAG = "v2.10.2"
ORIGINAL_IMAGE = f"docker.io/goharbor/{IMAGE_NAME}:{IMAGE_TAG}"


@pytest.mark.abort_on_fail
def test_compare_rock_files_to_original():
"""Test ROCK contains same fileset as original image."""

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, IMAGE_TAG, "amd64")
rock_image = rock_meta.image

dir_to_check = "/harbor"

original_image_files = docker_util.list_files_under_container_image_dir(
ORIGINAL_IMAGE, root_dir=dir_to_check)
rock_image_files = docker_util.list_files_under_container_image_dir(
rock_image, root_dir=dir_to_check)

rock_fileset = set(rock_image_files)
original_fileset = set(original_image_files)

original_extra_files = original_fileset - rock_fileset
if original_extra_files:
pytest.fail(
f"Missing some files from the original image: "
f"{original_extra_files}")

rock_extra_files = rock_fileset - original_fileset
if rock_extra_files:
pytest.fail(
f"Rock has extra files not present in original image: "
f"{rock_extra_files}")
88 changes: 88 additions & 0 deletions tests/sanity/test_harbor_portal_v2_10_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import logging
import pytest
import re
import sys

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util


LOG: logging.Logger = logging.getLogger(__name__)

LOG.addHandler(logging.FileHandler(f"{__name__}.log"))
LOG.addHandler(logging.StreamHandler(sys.stdout))


IMAGE_NAME = "harbor-portal"
IMAGE_TAG = "v2.10.2"
ORIGINAL_IMAGE = f"docker.io/goharbor/{IMAGE_NAME}:{IMAGE_TAG}"


@pytest.mark.abort_on_fail
def test_check_rock_contains_files():
"""Test ROCK contains expected files"""

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, IMAGE_TAG, "amd64")
rock_image = rock_meta.image

image_files_to_check = [
# Nginx-related dirs:
"/home/nginx",
"/var/log/nginx",
]
docker_util.ensure_image_contains_paths(
rock_image, image_files_to_check)

@pytest.mark.abort_on_fail
def test_compare_rock_files_to_original():
"""Test ROCK contains same fileset as original image."""

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, IMAGE_TAG, "amd64")
rock_image = rock_meta.image

dir_to_check = "/usr/share/nginx/html"

original_image_files = docker_util.list_files_under_container_image_dir(
ORIGINAL_IMAGE, root_dir=dir_to_check)
rock_image_files = docker_util.list_files_under_container_image_dir(
rock_image, root_dir=dir_to_check)

# NOTE(aznashwan): the names of main.js have randomized tags:
main_js_re = re.compile('(/usr/share/nginx/html/main\\..*\\.js)')
original_image_main = [
f for f in original_image_files if main_js_re.match(f)]
rock_image_main = [
f for f in rock_image_files if main_js_re.match(f)]
if original_image_main and not rock_image_main:
pytest.fail(
f"ROCK image seems to be missing a main.*.js file. "
f"Original image's main: {original_image_main}. All "
f"ROCK files under {dir_to_check}: {rock_image_files}")

rock_fileset = set(rock_image_files) - set(rock_image_main)
original_fileset = set(original_image_files) - set(original_image_main)

original_extra_files = original_fileset - rock_fileset
if original_extra_files:
pytest.fail(
f"Missing some files from the original image: "
f"{original_extra_files}")

rock_extra_files = rock_fileset - original_fileset
if rock_extra_files:
pytest.fail(
f"Rock has extra files not present in original image: "
f"{rock_extra_files}")

# Nginx-related dirs:
image_files_to_check = [
"/home/nginx",
"/var/log/nginx",
]
docker_util.ensure_image_contains_paths(
rock_image, image_files_to_check)
Loading
Loading