Skip to content

Commit

Permalink
compose: Add rpmostree.rpmmd-repo metadata to commits by default
Browse files Browse the repository at this point in the history
This is a revisit of a PR for client-side layering: #1072
Here though we're doing this by default for server-side composes.
There are a few reasons to do this; first, I'm seeing an issue
in some of our Jenkins jobs for Fedora that hit "mirror roulette"
and end up creating commits that "revert" to older versions temporarily.

While I've [certainly pitched](https://lists.fedoraproject.org/archives/list/[email protected]/message/IMPE6KCRBHCEJH5VBE6ZFIRLPAD743JT/) this as a feature, I think
we really want something like `--force-older-timestamp` - basically
error out if the timestamps on one or more input repos were older.
Not doing that in this patch, but it paves the way to do so.

Second, I'd like to use this data in the `ostree.source-title`
metadata key down the line.  Something like:

`└ rpmmd: fedora-26 (20170310), fedora-26-updates (20171101)`

(This could be a lot nicer if we drive versioning in to the rpm-md repo info,
 and e.g. there's some friendly "week number" style versioning for the updates
 repo now that it's batched...for now we have timestamps)

For CentOS/RHELAH this gets interesting and potentially more verbose,
to the point where we may want to render it more explicitly.

But anyways, let's do this now, as it will be useful even without
an explicit rendering, since users can do e.g. `ostree show` on
a base commit hash to dump the data.

I had a concern that some users may not want to emit this metadata;
they can currently do `--add-metadata-string rpmostree.rpmmd-repos ''`
and that will "win".

Closes: #1079
Approved by: jlebon
  • Loading branch information
cgwalters authored and rh-atomic-bot committed Nov 4, 2017
1 parent cb86194 commit e7a42f7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/app/rpmostree-compose-builtin-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,13 @@ impl_install_tree (RpmOstreeTreeComposeContext *self,
}
}

/* Bind metadata from the libdnf context */
if (!g_hash_table_contains (self->metadata, "rpmostree.rpmmd-repos"))
{
g_hash_table_insert (self->metadata, g_strdup ("rpmostree.rpmmd-repos"),
rpmostree_context_get_rpmmd_repo_commit_metadata (self->corectx));
}

/* Destroy this now so the libdnf stack won't have any references
* into the filesystem before we manipulate it.
*/
Expand Down
29 changes: 29 additions & 0 deletions src/libpriv/rpmostree-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,35 @@ rpmostree_context_get_hif (RpmOstreeContext *self)
return self->hifctx;
}

/* Add rpmmd repo information, since it's very useful for determining
* state. See also:
*
* - https://github.com/projectatomic/rpm-ostree/issues/774
* - The repo_metadata_for_package() function in rpmostree-unpacker.c
* This returns a value of key of type aa{sv} - the key should be
* `rpmostree.rpmmd-repos`.
*/
GVariant *
rpmostree_context_get_rpmmd_repo_commit_metadata (RpmOstreeContext *self)
{
g_auto(GVariantBuilder) repo_list_builder;
g_variant_builder_init (&repo_list_builder, (GVariantType*)"aa{sv}");
g_autoptr(GPtrArray) repos = get_enabled_rpmmd_repos (self->hifctx, DNF_REPO_ENABLED_PACKAGES);
for (guint i = 0; i < repos->len; i++)
{
g_auto(GVariantBuilder) repo_builder;
g_variant_builder_init (&repo_builder, (GVariantType*)"a{sv}");
DnfRepo *repo = repos->pdata[i];
const char *id = dnf_repo_get_id (repo);
g_variant_builder_add (&repo_builder, "{sv}", "id", g_variant_new_string (id));
guint64 ts = dnf_repo_get_timestamp_generated (repo);
g_variant_builder_add (&repo_builder, "{sv}", "timestamp", g_variant_new_uint64 (ts));
g_variant_builder_add (&repo_list_builder, "@a{sv}", g_variant_builder_end (&repo_builder));
}
return g_variant_ref_sink (g_variant_builder_end (&repo_list_builder));
}

GHashTable *
rpmostree_dnfcontext_get_varsubsts (DnfContext *context)
{
Expand Down
2 changes: 2 additions & 0 deletions src/libpriv/rpmostree-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ RpmOstreeTreespec *rpmostree_treespec_new (GVariant *variant);

GHashTable *rpmostree_dnfcontext_get_varsubsts (DnfContext *context);

GVariant *rpmostree_context_get_rpmmd_repo_commit_metadata (RpmOstreeContext *self);

GVariant *rpmostree_treespec_to_variant (RpmOstreeTreespec *spec);
const char *rpmostree_treespec_get_ref (RpmOstreeTreespec *spec);

Expand Down
2 changes: 2 additions & 0 deletions tests/compose-tests/test-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ assert_file_has_content meta.txt 'rev.*97ec21c614689e533d294cdae464df607b526ab9'
assert_file_has_content meta.txt 'src.*https://gitlab.com/exampleos/custom-atomic-host'
ostree --repo=${repobuild} show --print-metadata-key exampleos.tests ${treeref} > meta.txt
assert_file_has_content meta.txt 'smoketested.*e2e'
ostree --repo=${repobuild} show --print-metadata-key rpmostree.rpmmd-repos ${treeref} > meta.txt
assert_file_has_content meta.txt 'id.*fedora.*timestamp'
echo "ok metadata"

for path in /boot /usr/lib/ostree-boot; do
Expand Down

0 comments on commit e7a42f7

Please sign in to comment.