generated from canonical/starbase
-
Notifications
You must be signed in to change notification settings - Fork 21
feat: inject application's base snap into managed instances #953
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
Copilot
wants to merge
15
commits into
main
Choose a base branch
from
copilot/inject-base-snap-into-instance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
32cb800
Initial plan
Copilot 4f46898
Add base snap injection functionality
Copilot 7a774f7
Fix linting issues in snap_config.py
Copilot 9f07eff
Use snaphelpers for reading snap metadata
Copilot 3837542
Fix linting and improve tests
Copilot 204d75d
Fix ruff linting error - remove trailing whitespace
Copilot 5faca45
Remove redundant test_install_snap_without_base
Copilot a368c95
Add spread test for base snap injection
Copilot fc5f196
Fix spread test to build testcraft snap locally
Copilot 0645e0c
Address code review feedback
Copilot b0e75e5
Merge branch 'main' into copilot/inject-base-snap-into-instance
lengau c40ab1f
Add changelog entry for base snap injection
Copilot f756850
Fix base snap injection order and formatting
Copilot e759892
Simplify spread test and improve code clarity
Copilot ebd660e
Improve spread test reliability
Copilot 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,89 @@ | ||
| summary: Verify base snap is injected with correct revision in managed mode | ||
|
|
||
| priority: 100 | ||
|
|
||
| systems: | ||
| - ubuntu-22.04-64 # Test on 22.04 with a core24 snap | ||
| - ubuntu-24.04-64 | ||
|
|
||
| prepare: | | ||
| # Determine the base snap for the test (use core24 for testing) | ||
| HOST_BASE="core24" | ||
|
|
||
| # Install from edge channel to ensure different revision from container preinstall | ||
| snap install "$HOST_BASE" --channel=edge || true | ||
|
|
||
| # Get the revision of the base snap on the host | ||
| HOST_BASE_REVISION=$(snap list "$HOST_BASE" | tail -n 1 | awk '{print $3}') | ||
| echo "Host base snap: $HOST_BASE (revision $HOST_BASE_REVISION)" | ||
|
|
||
| # Save for later use | ||
| echo "$HOST_BASE" > /tmp/base_snap_name | ||
| echo "$HOST_BASE_REVISION" > /tmp/base_snap_revision | ||
|
|
||
| execute: | | ||
| mkdir inject-test | ||
| cd inject-test | ||
|
|
||
| # Initialize a project | ||
| testcraft init | ||
| . /etc/os-release | ||
| sed -i "s/base: ubuntu@[0-9.]\\+/base: ubuntu@${VERSION_ID}/" testcraft.yaml | ||
|
|
||
| # Set a short idle time for faster test | ||
| export CRAFT_IDLE_MINS=1 | ||
|
|
||
| # Run testcraft pack in managed mode - this should inject the base snap | ||
| testcraft pack --verbose --debug | ||
|
|
||
| # Get the base snap info | ||
| HOST_BASE=$(cat /tmp/base_snap_name) | ||
| HOST_BASE_REVISION=$(cat /tmp/base_snap_revision) | ||
|
|
||
| # Connect to the managed instance and check if the base snap is present | ||
| # The instance name follows the pattern: testcraft-inject-test-<arch>-<build_base> | ||
| ARCH=$(dpkg --print-architecture) | ||
|
|
||
| # Find the LXD instance (testcraft uses LXD on Linux) | ||
| INSTANCE=$(lxc list --project=testcraft --format csv -c n | grep "^testcraft-" | head -n 1) | ||
|
|
||
| if [ -z "$INSTANCE" ]; then | ||
| echo "Could not find managed instance" | ||
| echo "Available instances:" | ||
| lxc list --project=testcraft | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Found instance: $INSTANCE" | ||
|
|
||
| # Check if the base snap is installed in the instance | ||
| INSTANCE_BASE_REVISION=$(lxc exec --project=testcraft "$INSTANCE" -- snap list "$HOST_BASE" 2>/dev/null | tail -n 1 | awk '{print $3}' || echo "") | ||
|
|
||
| if [ -z "$INSTANCE_BASE_REVISION" ]; then | ||
| echo "ERROR: Base snap '$HOST_BASE' is not installed in the managed instance" | ||
| echo "Installed snaps in instance:" | ||
| lxc exec --project=testcraft "$INSTANCE" -- snap list | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Instance base snap: $HOST_BASE (revision $INSTANCE_BASE_REVISION)" | ||
|
|
||
| # Verify the revisions match | ||
| if [ "$HOST_BASE_REVISION" != "$INSTANCE_BASE_REVISION" ]; then | ||
| echo "ERROR: Base snap revision mismatch!" | ||
| echo " Host revision: $HOST_BASE_REVISION" | ||
| echo " Instance revision: $INSTANCE_BASE_REVISION" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "SUCCESS: Base snap '$HOST_BASE' revision $HOST_BASE_REVISION matches on host and instance" | ||
|
|
||
| restore: | | ||
| cd inject-test 2>/dev/null || true | ||
| testcraft clean || true | ||
| cd .. | ||
| rm -rf inject-test | ||
| rm -f /tmp/base_snap_name /tmp/base_snap_revision | ||
|
|
||
| # Restore core24 to stable channel | ||
| snap refresh core24 --channel=stable || true | ||
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.