Skip to content
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
8 changes: 6 additions & 2 deletions .github/actions/run-spread-tests/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ inputs:
description: Complete spread command to run i.e. spread google-nested:tests/spread/main/
required: true
type: string
base-variant:
description: Type of base ("regular" or "cloud-init")
required: false
default: regular
type: string

runs:
using: "composite"
Expand Down Expand Up @@ -40,6 +45,7 @@ runs:
cd "${{ inputs.working-directory }}"
(
set -o pipefail
export BUILD_VARIANT=${{ inputs.base-variant }}
${{ inputs.spread-command }} | \
${{ github.workspace }}/snapd-testing-tools/utils/log-filter -o $FILTERED_LOG_FILE -e Debug -e WARNING: -f Failed=NO_LINES -f Error=NO_LINES | \
tee spread.log
Expand All @@ -63,5 +69,3 @@ runs:
else
echo "No spread log found, skipping errors reporting"
fi


64 changes: 53 additions & 11 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,29 @@ concurrency:
cancel-in-progress: true

jobs:
setup:
runs-on: self-hosted
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
# Skip cloud-init variant for bases that had it included by default
if [[ "${{ github.ref_name }}" == core22* ]] || [[ "${{ github.ref_name }}" == core24* ]]; then
echo 'matrix=["regular"]' >> $GITHUB_OUTPUT
else
echo 'matrix=["regular", "cloud-init"]' >> $GITHUB_OUTPUT
fi

build:
runs-on: [self-hosted, spread-enabled]
needs: setup
strategy:
fail-fast: false
matrix:
variant: ${{ fromJSON(needs.setup.outputs.matrix) }}
env:
BUILD_VARIANT: ${{ matrix.variant }}
steps:
- name: Cleanup job workspace
id: cleanup-job-workspace
Expand All @@ -29,30 +50,44 @@ jobs:

- name: x86 build
run: |
export BUILD_VARIANT
spread -artifacts=./artifacts google-nested:tests/spread/build/
find ./artifacts -type f -name core26_amd64.artifact -exec cp {} "${{ github.workspace }}" \;

- name: arm64 build
run: |
export BUILD_VARIANT
spread -artifacts=./artifacts google-nested-arm:tests/spread/build/
find ./artifacts -type f -name core26_arm64.artifact -exec cp {} "${{ github.workspace }}" \;

- uses: actions/upload-artifact@v4
with:
name: core-snap
name: core-snap-${{ matrix.variant }}
path: "${{ github.workspace }}/*.artifact"

- name: Discard spread workers
if: always()
run: |
export BUILD_VARIANT
shopt -s nullglob
for r in .spread-reuse.*.yaml; do
spread -discard -reuse-pid="$(echo "$r" | grep -o -E '[0-9]+')"
done

tests-main:
runs-on: [self-hosted, spread-enabled]
needs: build
needs: [setup, build]
strategy:
fail-fast: false
matrix:
variant: ${{ fromJSON(needs.setup.outputs.matrix) }}
# We want to run tests here only for one of the variants, as in this
# case the user is introduced by modifying the snapd snap and we do not
# use neither cloud-init not system-user assertions.
exclude:
- variant: cloud-init
env:
BUILD_VARIANT: ${{ matrix.variant }}
steps:
- name: Cleanup job workspace
id: cleanup-job-workspace
Expand All @@ -62,16 +97,18 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: core-snap
name: core-snap-${{ matrix.variant }}

- name: Run x86 tests
uses: ./.github/actions/run-spread-tests
with:
base-variant: ${{ matrix.variant }}
spread-command: spread google-nested:tests/spread/main/

- name: Run arm64 tests
uses: ./.github/actions/run-spread-tests
with:
base-variant: ${{ matrix.variant }}
spread-command: spread google-nested-arm:tests/spread/main/

- name: Discard spread workers
Expand All @@ -83,7 +120,13 @@ jobs:
done
tests-snapd:
runs-on: ubuntu-latest
needs: build
needs: [setup, build]
strategy:
fail-fast: false
matrix:
variant: ${{ fromJSON(needs.setup.outputs.matrix) }}
env:
BUILD_VARIANT: ${{ matrix.variant }}
steps:
Comment on lines 121 to 130
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests-snapd is now matrixed over variant: [regular, cloud-init], but the image boot/SSH helper (tests/lib/prepare-utils.sh) SSHes as user test@localhost (created via cloud-init config) and the workflow still relies on prepare_base_cloudinit to inject a cloud-init config into the gadget. The "regular" variant (intended to be built without cloud-init) is likely to never create the test user, causing the VM boot step to time out. Consider running tests-snapd only for the cloud-init variant (or updating the VM/user provisioning to not depend on cloud-init for the regular build).

Copilot uses AI. Check for mistakes.
- name: Cleanup job workspace
id: cleanup-job-workspace
Expand All @@ -100,14 +143,15 @@ jobs:
path: snapd
- uses: actions/download-artifact@v4
with:
name: core-snap
name: core-snap-${{ matrix.variant }}

- name: Install spread
run: curl -s https://storage.googleapis.com/snapd-spread-tests/spread/spread-amd64.tar.gz | sudo tar xzv -C /usr/bin

- name: Build image
working-directory: '${{ github.workspace }}'
run: |
export BUILD_VARIANT
PROJECT_PATH=$PWD/core-base
# For os.query and others
PATH=$PATH:$PROJECT_PATH/tests/lib/external/snapd-testing-tools/tools/
Expand All @@ -119,13 +163,11 @@ jobs:
echo "************* DOWNLOADING SNAPS *************"
download_core26_snaps 'edge'

echo "************* WRITING CLOUD-INIT CONFIG *************"
prepare_base_cloudinit

echo "************* BUILDING CORE26 IMAGE *************"
uc_snap="$(get_core_snap_name)"
mv core26_"$(get_arch)".artifact "$uc_snap"
build_base_image
insert_user=true
build_base_image "$insert_user"

echo "************* STARTING CORE26 VM *************"
start_snapd_core_vm '${{ github.workspace }}'
Expand All @@ -134,8 +176,8 @@ jobs:
uses: ./core-base/.github/actions/run-spread-tests
with:
working-directory: snapd
# TODO change to 26 when available (not a lot of a difference as it is external)
spread-command: SPREAD_EXTERNAL_ADDRESS=localhost:8022 spread external:ubuntu-core-24-64:tests/smoke/
base-variant: ${{ matrix.variant }}
spread-command: SPREAD_EXTERNAL_ADDRESS=localhost:8022 spread external:ubuntu-core-26-64:tests/smoke/

- name: Discard spread workers
if: always()
Expand Down
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,25 @@ hooks:
exit 1; \
fi

set -eux; for f in ./hooks/[0-9]*.chroot; do \
set -eux; \
export SNAP_CLOUD_INIT_BUILD=""; \
if [ -f "$$CRAFT_PROJECT_DIR"/cloud-init-build ]; then \
SNAP_CLOUD_INIT_BUILD=true; \
fi; \
Comment thread
alfonsosanchezbeato marked this conversation as resolved.
for f in ./hooks/[0-9]*.chroot; do \
base="$$(basename "$${f}")"; \
cp -a "$${f}" $(DESTDIR)/install-data/; \
chroot $(DESTDIR) "/install-data/$${base}"; \
rm "$(DESTDIR)/install-data/$${base}"; \
done
rm -rf $(DESTDIR)/install-data

set -eux; for f in ./hooks-build/[0-9]*.build; do \
set -eux; \
export SNAP_CLOUD_INIT_BUILD=""; \
if [ -f "$$CRAFT_PROJECT_DIR"/cloud-init-build ]; then \
SNAP_CLOUD_INIT_BUILD=true; \
fi; \
Comment thread
alfonsosanchezbeato marked this conversation as resolved.
for f in ./hooks-build/[0-9]*.build; do \
"$$f" $(DESTDIR); \
done

Expand Down
43 changes: 26 additions & 17 deletions hooks/005-initialize-systemd.chroot
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,32 @@ case "$(uname -m)" in
esac

# Ensure selected base units are enabled
for unit in \
cloud-init-local.service \
cloud-init-main.service \
cloud-init-network.service \
cloud-config.service \
cloud-final.service \
cloud-init-hotplugd.service \
cloud-init-hotplugd.socket \
e2scrub_reap.service \
secureboot-db.service \
wpa_supplicant.service \
apparmor.service \
finalrd.service \
netplan-configure.service \
sshd-keygen.service \
e2scrub_all.timer \

units=(
e2scrub_reap.service
secureboot-db.service
wpa_supplicant.service
apparmor.service
finalrd.service
netplan-configure.service
sshd-keygen.service
e2scrub_all.timer
fstrim.timer
)

if [ "$SNAP_CLOUD_INIT_BUILD" = true ]; then
units+=(
cloud-init-local.service
cloud-init-main.service
cloud-init-network.service
cloud-config.service
cloud-final.service
cloud-init-hotplugd.service
cloud-init-hotplugd.socket
)
fi

for unit in "${units[@]}"
do
if [ "$unit" = "secureboot-db.service" ] && [ "$ARCH" != "amd64" ] && [ "$ARCH" != "i386" ]; then
continue
Expand All @@ -98,7 +107,7 @@ echo "ensure the systemd target.wants are in /usr/lib instead of /etc"
for wants_dir in /etc/systemd/system/*.wants; do
[ -d "$wants_dir" ] || continue
target_name=$(basename "$wants_dir")

# Skip cloud-init related .wants (keep in /etc for snapd)
case "$target_name" in
cloud-*)
Expand Down
4 changes: 3 additions & 1 deletion hooks/011-cloud-init-config.chroot
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ set -eu

# Because /etc/fstab is read-only now, we should not let cloud-init
# try to modify it.
sed -i '/^ *- mounts$/d' /etc/cloud/cloud.cfg
if [ "$SNAP_CLOUD_INIT_BUILD" = true ]; then
sed -i '/^ *- mounts$/d' /etc/cloud/cloud.cfg
fi
28 changes: 25 additions & 3 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ parts:
source-type: git
source-branch: '26.04'
override-build: |
# We use a marker file in $CRAFT_PROJECT_DIR to decide whether to include
# cloud-init or not. This file can be manually created for local builds,
# or automatically set if we are in a branch like 26-cloud-init. The
# latter is the case for Launchpad builds - note that this is not a
# branch forked from master, but a branch that is created by CI/CD in the
# same commit at master at build time, that is then imported by the LP
# recipe, and then removed.
(
cd "$CRAFT_PROJECT_DIR"
if git branch --show-current | grep '.*-cloud-init$'
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The branch detection pipeline will print the branch name into the build logs because grep is not quiet. Using grep -q (and potentially anchoring to -cloud-init$ without .*) would avoid noisy output while keeping the same behavior.

Suggested change
if git branch --show-current | grep '.*-cloud-init$'
if git branch --show-current | grep -q -- '-cloud-init$'

Copilot uses AI. Check for mistakes.
then touch cloud-init-build
fi
)
go install github.com/canonical/chisel/cmd/chisel@latest

# Define the system utilities that we want to include in the base
Expand Down Expand Up @@ -74,18 +87,21 @@ parts:
bash-completion_config
bash-completion_completions
ca-certificates_data-with-certs
cloud-init_bins
cracklib-runtime_bins
cryptsetup_bins
cryptsetup-bin_bins
dbus_services
dbus-user-session_services
dhcpcd-base_standard
distro-info-data_data
dmsetup_rules
e2fsprogs_services
e2fsprogs_standard
fdisk_bins
fonts-ubuntu_all
fonts-ubuntu_config
finalrd_services
iproute2_bins
kmod_bins
kmod_config

Expand Down Expand Up @@ -117,6 +133,8 @@ parts:
libwrap0_host-files
locales_standard

netcat-openbsd_bins
netplan.io_bins
ncurses-base_terminfo

openssh-client_config
Expand All @@ -129,6 +147,7 @@ parts:
p11-kit_bins
passwd_pam-config
polkitd_services
procps_bins
plymouth_bins
plymouth-label-ft_libs
procps_config
Expand Down Expand Up @@ -156,6 +175,10 @@ parts:
wpasupplicant_services
)

if [ -f "$CRAFT_PROJECT_DIR"/cloud-init-build ]; then
SLICES+=(cloud-init_bins)
fi

# TODO: not sure about FIPS yet, this will have to come later, chisel has builtin
# support for ESM, meaning it's something we can request chisel to do for us.
# if [[ ${SNAP_FIPS_BUILD+x} ]]; then
Expand Down Expand Up @@ -245,9 +268,8 @@ parts:
# obviously for new core bases this cannot be the case, and
# we need to wait until the first release with introducing
# changelogs.
# TODO change to core26 when available
build-snaps:
- core24=latest/beta
- core26=latest/beta
override-pull: |
craftctl default

Expand Down
1 change: 1 addition & 0 deletions spread.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ environment:
# XXX temporarily switch to edge to get the fix for
# https://bugs.launchpad.net/snapcraft/+bug/2051567
SNAPCRAFT_CHANNEL: latest/edge
BUILD_VARIANT: '$(HOST: echo "$BUILD_VARIANT")'

backends:
google-nested:
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/models/id_ed25519
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACCmIQU2qoW1zRd0NPm73jTdQqJdPg1th6TSsfa44ZEgqwAAAJj0+Ytm9PmL
ZgAAAAtzc2gtZWQyNTUxOQAAACCmIQU2qoW1zRd0NPm73jTdQqJdPg1th6TSsfa44ZEgqw
AAAEC6WWaSpu+AUYRpU//2yZgzEv3e9NWIhC5dHZsotHYCdaYhBTaqhbXNF3Q0+bveNN1C
ol0+DW2HpNKx9rjhkSCrAAAAEHVidW50dUBsb2NhbGhvc3QBAgMEBQ==
-----END OPENSSH PRIVATE KEY-----
1 change: 1 addition & 0 deletions tests/lib/models/id_ed25519.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKYhBTaqhbXNF3Q0+bveNN1Col0+DW2HpNKx9rjhkSCr ubuntu@localhost
Loading
Loading