Skip to content

Commit

Permalink
feat: annotate devel rocks with a grade
Browse files Browse the repository at this point in the history
This commit updates the rock's internal metadata (the file /.rock/metadata.yaml)
with an extra "grade: devel" key if the project's build-base is "devel". This is
to provide some amount of traceability/record that the rock was originally
created from a development base.
  • Loading branch information
tigarmo committed Feb 7, 2024
1 parent 4e8de46 commit f47fabe
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions rockcraft/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ def generate_metadata(
"base-digest": base_digest.hex(),
}

if self.build_base == "devel":
# Annotate that this project was built with a development base.
metadata["grade"] = "devel"

annotations = {
"org.opencontainers.image.version": self.version,
"org.opencontainers.image.title": self.title,
Expand Down
19 changes: 18 additions & 1 deletion tests/spread/general/base-devel/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,22 @@ execute: |
grep placeholder-base rockcraft.orig.yaml
sed "s/placeholder-base/$BASE/" rockcraft.orig.yaml > rockcraft.yaml
# Build the rock & load it into docker
# Build the rock
run_rockcraft pack
# Extract the built rock and check that the "grade" is "devel" in the metadata
# Extract the rock into a dir called "devel"
mkdir devel
tar -xvf base-devel*.rock -C devel
# Unpack the rootfs into "rootfs"
/snap/rockcraft/current/bin/umoci unpack --rootless --image devel:0.1 rootfs
# Check the grade
MATCH "grade: devel" < rootfs/rootfs/.rock/metadata.yaml
restore: |
rm -rf devel
rm -rf rootfs
12 changes: 12 additions & 0 deletions tests/unit/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,18 @@ def test_project_generate_metadata(yaml_loaded_data):
}


def test_metadata_base_devel(yaml_loaded_data):
yaml_loaded_data["base"] = CURRENT_DEVEL_BASE
yaml_loaded_data["build-base"] = "devel"
project = Project.unmarshal(yaml_loaded_data)

now = datetime.datetime.now(datetime.timezone.utc).isoformat()
digest = "a1b2c3" # mock digest

_, rock_metadata = project.generate_metadata(now, bytes.fromhex(digest))
assert rock_metadata["grade"] == "devel"


EXPECTED_DUMPED_YAML = f"""\
name: mytest
title: My Test
Expand Down

0 comments on commit f47fabe

Please sign in to comment.