-
Notifications
You must be signed in to change notification settings - Fork 12
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
draft: PoC for refactor CI epic #571
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
08ab1e5
ci: build charms in separate GH runners
orfeas-k 91f6c2f
try download-artifact with path:./charms/<charm>
orfeas-k 4624163
omit path from download-artifact + fix issue in tox
orfeas-k 9869820
use path in download-artifact
orfeas-k 7fb5832
ci: fix individual charm tests
orfeas-k af72942
ci: bundle-tests use pre-packed charms
orfeas-k e11e325
ci: Use release-charm.yaml in publish job
orfeas-k 7fc2488
ci: Remove dependency from tests since its not needed
orfeas-k 881748e
fix
orfeas-k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -66,20 +66,42 @@ jobs: | |
- run: python3 -m pip install tox | ||
- run: tox -e ${{ matrix.charm }}-unit | ||
|
||
build: | ||
name: Build charm | ||
uses: canonical/data-platform-workflows/.github/workflows/[email protected] | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
charm: | ||
- kfp-api | ||
- kfp-metadata-writer | ||
- kfp-persistence | ||
- kfp-profile-controller | ||
- kfp-schedwf | ||
- kfp-ui | ||
- kfp-viewer | ||
- kfp-viz | ||
with: | ||
cache: ${{ github.event_name == 'pull_request' }} | ||
charmcraft-snap-channel: 3.x/edge | ||
path-to-charm-directory: ./charms/${{ matrix.charm }} | ||
|
||
|
||
integration: | ||
name: Integration tests (microk8s) | ||
runs-on: ubuntu-20.04 | ||
needs: [build] | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
charm: | ||
- kfp-api | ||
- kfp-metadata-writer | ||
- kfp-persistence | ||
- kfp-profile-controller | ||
- kfp-api | ||
- kfp-schedwf | ||
- kfp-viewer | ||
- kfp-ui | ||
- kfp-metadata-writer | ||
- kfp-viewer | ||
- kfp-viz | ||
steps: | ||
# Ideally we'd use self-hosted runners, but this effort is still not stable | ||
|
@@ -90,7 +112,7 @@ jobs: | |
- name: Maximise GH runner space | ||
uses: jlumbroso/[email protected] | ||
|
||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup operator environment | ||
uses: charmed-kubernetes/actions-operator@main | ||
|
@@ -101,12 +123,20 @@ jobs: | |
# Pinned to 3.x/stable due to https://github.com/canonical/charmcraft/issues/1845 | ||
charmcraft-channel: 3.x/stable | ||
|
||
- name: Download packed charm(s) | ||
id: download-charms | ||
timeout-minutes: 5 | ||
uses: actions/download-artifact@v4 | ||
with: | ||
pattern: packed-charm-cache-true-.-charms-${{ matrix.charm }}-* | ||
merge-multiple: true | ||
|
||
- name: Integration tests | ||
run: | | ||
# Requires the model to be called kubeflow due to | ||
# https://github.com/canonical/kfp-operators/issues/389 | ||
juju add-model kubeflow | ||
sg snap_microk8s -c "tox -e ${{ matrix.charm }}-integration -- --model kubeflow" | ||
sg snap_microk8s -c "tox -vve ${{ matrix.charm }}-integration-using-packed-charms -- --model kubeflow" | ||
|
||
- name: Collect charm debug artifacts | ||
uses: canonical/kubeflow-ci/actions/dump-charm-debug-artifacts@main | ||
|
@@ -144,11 +174,19 @@ jobs: | |
charmcraft-channel: 3.x/stable | ||
microk8s-addons: "dns hostpath-storage rbac metallb:10.64.140.43-10.64.140.49" | ||
|
||
- name: Download packed charm(s) | ||
id: download-charms | ||
timeout-minutes: 5 | ||
uses: actions/download-artifact@v4 | ||
with: | ||
pattern: packed-charm-cache-true-.-* | ||
merge-multiple: true | ||
|
||
- name: Run test | ||
run: | | ||
# Requires the model to be called kubeflow due to kfp-viewer | ||
juju add-model kubeflow | ||
sg snap_microk8s -c "tox -e bundle-integration-${{ matrix.sdk }} -- --model kubeflow --bundle=./tests/integration/bundles/kfp_latest_edge.yaml.j2" | ||
sg snap_microk8s -c "tox -e bundle-integration-${{ matrix.sdk }}-using-packed-charms -- --model kubeflow --bundle=./tests/integration/bundles/kfp_latest_edge.yaml.j2" | ||
|
||
- name: Get all | ||
run: kubectl get all -A | ||
|
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 |
---|---|---|
|
@@ -41,14 +41,12 @@ jobs: | |
run: bash .github/workflows/get-charm-paths.sh | ||
|
||
|
||
publish-charm: | ||
name: Publish Charm | ||
define-channel: | ||
name: Define destination channel | ||
runs-on: ubuntu-20.04 | ||
needs: get-charm-paths | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
charm-path: ${{ fromJson(needs.get-charm-paths.outputs.charm_paths_list) }} | ||
outputs: | ||
destination-channel: ${{ steps.parse-inputs.outputs.destination_channel }} | ||
|
||
steps: | ||
- name: Checkout | ||
|
@@ -72,24 +70,19 @@ jobs: | |
echo "setting output of destination_channel=$destination_channel" | ||
echo "::set-output name=destination_channel::$destination_channel" | ||
|
||
# tag_prefix | ||
# if charm_path = ./ --> tag_prefix = '' (null) | ||
# if charm_path != ./some-charm (eg: a charm in a ./charms dir) --> tag_prefix = 'some-charm' | ||
if [ ${{ matrix.charm-path }} == './' ]; then | ||
tag_prefix='' | ||
else | ||
tag_prefix=$(basename ${{ matrix.charm-path }} ) | ||
fi | ||
echo "setting output of tag_prefix=$tag_prefix" | ||
echo "::set-output name=tag_prefix::$tag_prefix" | ||
|
||
- name: Upload charm to charmhub | ||
uses: canonical/charming-actions/[email protected] | ||
with: | ||
credentials: ${{ secrets.CHARMCRAFT_CREDENTIALS }} | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
charm-path: ${{ matrix.charm-path }} | ||
channel: ${{ steps.parse-inputs.outputs.destination_channel }} | ||
tag-prefix: ${{ steps.parse-inputs.outputs.tag_prefix }} | ||
# Pinned to 3.x/stable due to https://github.com/canonical/charmcraft/issues/1845 | ||
charmcraft-channel: 3.x/stable | ||
release: | ||
name: Release charm | ||
uses: canonical/data-platform-workflows/.github/workflows/[email protected] | ||
needs: [define-channel, get-charm-paths] | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
charm-path: ${{ fromJson(needs.get-charm-paths.outputs.charm_paths_list) }} | ||
with: | ||
channel: ${{ needs.define-channel.outputs.destination-channel }} | ||
artifact-prefix: packed-charm-cache-true-.-charms-${{ matrix.charm-path }} | ||
create-github-release: ${{ github.event_name == 'push' }} | ||
secrets: | ||
charmhub-token: ${{ secrets.CHARMCRAFT_CREDENTIALS }} | ||
permissions: | ||
contents: write # Needed to create GitHub release |
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
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,43 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
"""Utils functions for integration tests. Should be moved to chisme.""" | ||
|
||
import os | ||
import pathlib | ||
import subprocess | ||
import typing | ||
|
||
|
||
async def get_packed_charms( | ||
charm_path: typing.Union[str, os.PathLike], bases_index: int = None | ||
) -> pathlib.Path: | ||
"""Simplified version of https://github.com/canonical/data-platform-workflows/blob/06f252ea079edfd055cee236ede28c237467f9b0/python/pytest_plugins/pytest_operator_cache/pytest_operator_cache/_plugin.py#L22.""" # noqa: E501 | ||
charm_path = pathlib.Path(charm_path) | ||
# namespace-node-affinity_ubuntu-20.04-amd64.charm | ||
# <metadata-name>_<base>-<architecture>.charm | ||
architecture = subprocess.run( | ||
["dpkg", "--print-architecture"], | ||
capture_output=True, | ||
check=True, | ||
encoding="utf-8", | ||
).stdout.strip() | ||
assert architecture in ("amd64", "arm64") | ||
packed_charms = list(charm_path.glob(f"*-{architecture}.charm")) | ||
if len(packed_charms) == 1: | ||
# python-libjuju's model.deploy(), juju deploy, and juju bundle files expect local charms | ||
# to begin with `./` or `/` to distinguish them from Charmhub charms. | ||
# Therefore, we need to return an absolute path—a relative `pathlib.Path` does not start | ||
# with `./` when cast to a str. | ||
# (python-libjuju model.deploy() expects a str but will cast any input to a str as a | ||
# workaround for pytest-operator's non-compliant `build_charm` return type of | ||
# `pathlib.Path`.) | ||
return packed_charms[0].resolve(strict=True) | ||
elif len(packed_charms) > 1: | ||
message = f"More than one matching .charm file found at {charm_path=} for {architecture=}: {packed_charms}." # noqa: E501 | ||
if bases_index is None: | ||
message += " Specify `bases_index`" | ||
raise ValueError(message) | ||
else: | ||
raise ValueError( | ||
f"Unable to find .charm file for {architecture=} and {bases_index=} at {charm_path=}" | ||
) |
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
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
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,43 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
"""Utils functions for integration tests. Should be moved to chisme.""" | ||
|
||
import os | ||
import pathlib | ||
import subprocess | ||
import typing | ||
|
||
|
||
async def get_packed_charms( | ||
charm_path: typing.Union[str, os.PathLike], bases_index: int = None | ||
) -> pathlib.Path: | ||
"""Simplified version of https://github.com/canonical/data-platform-workflows/blob/06f252ea079edfd055cee236ede28c237467f9b0/python/pytest_plugins/pytest_operator_cache/pytest_operator_cache/_plugin.py#L22.""" # noqa: E501 | ||
charm_path = pathlib.Path(charm_path) | ||
# namespace-node-affinity_ubuntu-20.04-amd64.charm | ||
# <metadata-name>_<base>-<architecture>.charm | ||
architecture = subprocess.run( | ||
["dpkg", "--print-architecture"], | ||
capture_output=True, | ||
check=True, | ||
encoding="utf-8", | ||
).stdout.strip() | ||
assert architecture in ("amd64", "arm64") | ||
packed_charms = list(charm_path.glob(f"*-{architecture}.charm")) | ||
if len(packed_charms) == 1: | ||
# python-libjuju's model.deploy(), juju deploy, and juju bundle files expect local charms | ||
# to begin with `./` or `/` to distinguish them from Charmhub charms. | ||
# Therefore, we need to return an absolute path—a relative `pathlib.Path` does not start | ||
# with `./` when cast to a str. | ||
# (python-libjuju model.deploy() expects a str but will cast any input to a str as a | ||
# workaround for pytest-operator's non-compliant `build_charm` return type of | ||
# `pathlib.Path`.) | ||
return packed_charms[0].resolve(strict=True) | ||
elif len(packed_charms) > 1: | ||
message = f"More than one matching .charm file found at {charm_path=} for {architecture=}: {packed_charms}." # noqa: E501 | ||
if bases_index is None: | ||
message += " Specify `bases_index`" | ||
raise ValueError(message) | ||
else: | ||
raise ValueError( | ||
f"Unable to find .charm file for {architecture=} and {bases_index=} at {charm_path=}" | ||
) |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this a setting, or have the logic to
get_packed_charms
ops_test.build_charm
??