Skip to content

Commit

Permalink
core: Add standard SOURCE_TITLE metadata key
Browse files Browse the repository at this point in the history
This is a freeform string useful to track/display when a commit is "derived"
from some other format.  For example, in the rpm-ostree test we make a
`vmcheck` ref that conceptually overlays the default ref like
`fedora-atomic:fedora/26/x86_64/atomic-host`.

My current patch sets the source title to e.g.
"Dev overlay on fedora-atomic:fedora/26/x86_64/atomic-host".

Another case I'm working on now is importing OCI images to use
as host images.  For that case, the source title is
With this patch we could then set the original OCI image name + tag
as the source name, like:
"oci:cgwalters/demo-custom-fedora-atomic-host:26".
  • Loading branch information
cgwalters committed Oct 20, 2017
1 parent 154ef57 commit 0633aa7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/libostree/ostree-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,23 @@ typedef enum {
* Since: 2017.7
*/
#define OSTREE_COMMIT_META_KEY_ENDOFLIFE "ostree.endoflife"
/**
* OSTREE_COMMIT_META_KEY_SOURCE_TITLE:
*
* GVariant type `s`. This should hold a relatively short single line value
* containing a human-readable "source" for a commit, intended to be displayed
* near the origin ref. This is particularly useful for systems that inject
* content into an OSTree commit from elsewhere - for example, generating from
* an OCI or qcow2 image. Or if generating from packages, the enabled repository
* names and their versions.
*
* Try to keep this key short (e.g. < 80 characters) and human-readable; if you
* desire machine readable data, consider injecting separate metadata keys.
*
* Since: 2017.13
*/
#define OSTREE_COMMIT_META_KEY_SOURCE_TITLE "ostree.source-title"

/**
* OSTREE_COMMIT_META_KEY_REF_BINDING:
*
Expand Down
8 changes: 7 additions & 1 deletion src/ostree/ot-admin-builtin-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ ot_admin_builtin_status (int argc, char **argv, OstreeCommandInvocation *invocat
commit_metadata = g_variant_get_child_value (commit, 0);

const char *version = NULL;
const char *source_title = NULL;
if (commit_metadata)
(void) g_variant_lookup (commit_metadata, OSTREE_COMMIT_META_KEY_VERSION, "&s", &version);
{
(void) g_variant_lookup (commit_metadata, OSTREE_COMMIT_META_KEY_VERSION, "&s", &version);
(void) g_variant_lookup (commit_metadata, OSTREE_COMMIT_META_KEY_SOURCE_TITLE, "&s", &source_title);
}

GKeyFile *origin = ostree_deployment_get_origin (deployment);

Expand Down Expand Up @@ -152,6 +156,8 @@ ot_admin_builtin_status (int argc, char **argv, OstreeCommandInvocation *invocat
g_print (" origin: <unknown origin type>\n");
else
g_print (" origin refspec: %s\n", origin_refspec);
if (source_title)
g_print (" `- %s\n", source_title);
}

if (deployment_get_gpg_verify (deployment, repo))
Expand Down
11 changes: 10 additions & 1 deletion tests/admin-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

set -euo pipefail

echo "1..$((22 + ${extra_admin_tests:-0}))"
echo "1..$((23 + ${extra_admin_tests:-0}))"

function validate_bootloader() {
cd ${test_tmpdir};
Expand Down Expand Up @@ -277,6 +277,15 @@ assert_streq ${curr_rev} ${head_rev}

echo "ok upgrade with and without override-commit"


${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo commit --add-metadata-string "version=${version}" \
--add-metadata-string 'ostree.source-title=libtest os_repository_new_commit()' -b $branch \
-s "Build" --tree=dir=${test_tmpdir}/osdata
${CMD_PREFIX} ostree admin upgrade --os=testos
${CMD_PREFIX} ostree admin status | tee status.txt
assert_file_has_content_literal status.txt '`- libtest os_repository_new_commit()'
echo "ok source title"

deployment=$(${CMD_PREFIX} ostree admin --sysroot=sysroot --print-current-dir)
${CMD_PREFIX} ostree --sysroot=sysroot remote add --set=gpg-verify=false remote-test-physical file://$(pwd)/testos-repo
assert_not_has_file ${deployment}/etc/ostree/remotes.d/remote-test-physical.conf testos-repo
Expand Down

0 comments on commit 0633aa7

Please sign in to comment.