diff options
author | Alexander Larsson <alexl@redhat.com> | 2019-06-13 12:49:14 +0200 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2019-09-06 12:49:40 +0000 |
commit | 58d9a257aa954e144b5a37109e9c3497d1b5160b (patch) | |
tree | 494449e688326c10292742c3c65c45ab33761519 | |
parent | 8cdd3a5e61aa7e2e24f8a92218509eeba0484cab (diff) | |
download | flatpak-58d9a257aa954e144b5a37109e9c3497d1b5160b.tar.gz |
OCI: Use labels as commit metadata source as well as annotations
We now pull the image config as well as the manifest and fall
back on the labels field if the keys we're looking for are not
in the annotations field.
This lets us support docker manifests too, which don't have
annotations (but do have labels).
Closes: #2978
Approved by: alexlarsson
-rw-r--r-- | app/flatpak-builtins-build-import-bundle.c | 18 | ||||
-rw-r--r-- | common/flatpak-dir.c | 9 | ||||
-rw-r--r-- | common/flatpak-json-oci.c | 5 | ||||
-rw-r--r-- | common/flatpak-utils-private.h | 1 | ||||
-rw-r--r-- | common/flatpak-utils.c | 13 | ||||
-rw-r--r-- | system-helper/flatpak-system-helper.c | 13 |
6 files changed, 54 insertions, 5 deletions
diff --git a/app/flatpak-builtins-build-import-bundle.c b/app/flatpak-builtins-build-import-bundle.c index ee89de9b..d415b2b4 100644 --- a/app/flatpak-builtins-build-import-bundle.c +++ b/app/flatpak-builtins-build-import-bundle.c @@ -60,10 +60,11 @@ import_oci (OstreeRepo *repo, GFile *file, const char *oci_digest; g_autoptr(FlatpakOciRegistry) registry = NULL; g_autoptr(FlatpakOciVersioned) versioned = NULL; + g_autoptr(FlatpakOciImage) image_config = NULL; FlatpakOciManifest *manifest = NULL; g_autoptr(FlatpakOciIndex) index = NULL; const FlatpakOciManifestDescriptor *desc; - GHashTable *annotations; + GHashTable *annotations, *labels; dir_uri = g_file_get_uri (file); registry = flatpak_oci_registry_new (dir_uri, FALSE, -1, cancellable, error); @@ -103,10 +104,23 @@ import_oci (OstreeRepo *repo, GFile *file, manifest = FLATPAK_OCI_MANIFEST (versioned); + image_config = flatpak_oci_registry_load_image_config (registry, NULL, + manifest->config.digest, + NULL, cancellable, error); + if (image_config == NULL) + return FALSE; + annotations = flatpak_oci_manifest_get_annotations (manifest); if (annotations) flatpak_oci_parse_commit_annotations (annotations, NULL, NULL, NULL, &target_ref, NULL, NULL, NULL); + if (target_ref == NULL) + { + labels = flatpak_oci_image_get_labels (image_config); + if (labels) + flatpak_oci_parse_commit_annotations (labels, NULL, NULL, NULL, + &target_ref, NULL, NULL, NULL); + } if (target_ref == NULL) { @@ -115,7 +129,7 @@ import_oci (OstreeRepo *repo, GFile *file, return NULL; } - commit_checksum = flatpak_pull_from_oci (repo, registry, NULL, oci_digest, manifest, + commit_checksum = flatpak_pull_from_oci (repo, registry, NULL, oci_digest, manifest, image_config, NULL, target_ref, NULL, NULL, cancellable, error); if (commit_checksum == NULL) return NULL; diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index b91dadaa..37deefd3 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -5050,6 +5050,7 @@ flatpak_dir_pull_oci (FlatpakDir *self, { g_autoptr(FlatpakOciRegistry) registry = NULL; g_autoptr(FlatpakOciVersioned) versioned = NULL; + g_autoptr(FlatpakOciImage) image_config = NULL; g_autofree char *full_ref = NULL; g_autofree char *registry_uri = NULL; g_autofree char *oci_repository = NULL; @@ -5096,6 +5097,12 @@ flatpak_dir_pull_oci (FlatpakDir *self, if (!FLATPAK_IS_OCI_MANIFEST (versioned)) return flatpak_fail_error (error, FLATPAK_ERROR_INVALID_DATA, _("Image is not a manifest")); + image_config = flatpak_oci_registry_load_image_config (registry, oci_repository, + FLATPAK_OCI_MANIFEST (versioned)->config.digest, + NULL, cancellable, error); + if (image_config == NULL) + return FALSE; + full_ref = g_strdup_printf ("%s:%s", state->remote_name, ref); if (repo == NULL) @@ -5106,7 +5113,7 @@ flatpak_dir_pull_oci (FlatpakDir *self, g_debug ("Pulling OCI image %s", oci_digest); - checksum = flatpak_pull_from_oci (repo, registry, oci_repository, oci_digest, FLATPAK_OCI_MANIFEST (versioned), + checksum = flatpak_pull_from_oci (repo, registry, oci_repository, oci_digest, FLATPAK_OCI_MANIFEST (versioned), image_config, state->remote_name, ref, oci_pull_progress_cb, progress, cancellable, error); if (progress) diff --git a/common/flatpak-json-oci.c b/common/flatpak-json-oci.c index b2ce731c..bf5a03f5 100644 --- a/common/flatpak-json-oci.c +++ b/common/flatpak-json-oci.c @@ -872,6 +872,11 @@ flatpak_oci_parse_commit_annotations (GHashTable *annotations, gpointer _key, _value; oci_ref = g_hash_table_lookup (annotations, "org.flatpak.ref"); + + /* Early return if this is not a flatpak manifest or if looking at annotations when the data is in labels */ + if (oci_ref == NULL) + return; + if (oci_ref != NULL && out_ref != NULL && *out_ref == NULL) *out_ref = g_strdup (oci_ref); diff --git a/common/flatpak-utils-private.h b/common/flatpak-utils-private.h index bedeffd1..c7360dd4 100644 --- a/common/flatpak-utils-private.h +++ b/common/flatpak-utils-private.h @@ -514,6 +514,7 @@ char * flatpak_pull_from_oci (OstreeRepo *repo, const char *oci_repository, const char *digest, FlatpakOciManifest *manifest, + FlatpakOciImage *image_config, const char *remote, const char *ref, FlatpakOciPullProgress progress_cb, diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c index ed32ac30..01621ed8 100644 --- a/common/flatpak-utils.c +++ b/common/flatpak-utils.c @@ -5506,6 +5506,7 @@ flatpak_pull_from_oci (OstreeRepo *repo, const char *oci_repository, const char *digest, FlatpakOciManifest *manifest, + FlatpakOciImage *image_config, const char *remote, const char *ref, FlatpakOciPullProgress progress_cb, @@ -5525,7 +5526,7 @@ flatpak_pull_from_oci (OstreeRepo *repo, FlatpakOciPullProgressData progress_data = { progress_cb, progress_user_data }; g_autoptr(GVariantBuilder) metadata_builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); g_autoptr(GVariant) metadata = NULL; - GHashTable *annotations; + GHashTable *annotations, *labels; int i; g_assert (ref != NULL); @@ -5539,6 +5540,16 @@ flatpak_pull_from_oci (OstreeRepo *repo, metadata_builder); if (manifest_ref == NULL) { + labels = flatpak_oci_image_get_labels (image_config); + if (labels) + flatpak_oci_parse_commit_annotations (labels, ×tamp, + &subject, &body, + &manifest_ref, NULL, NULL, + metadata_builder); + } + + if (manifest_ref == NULL) + { flatpak_fail_error (error, FLATPAK_ERROR_INVALID_DATA, _("No ref specified for OCI image %s"), digest); return NULL; } diff --git a/system-helper/flatpak-system-helper.c b/system-helper/flatpak-system-helper.c index afc32bad..27cd2c53 100644 --- a/system-helper/flatpak-system-helper.c +++ b/system-helper/flatpak-system-helper.c @@ -493,6 +493,7 @@ handle_deploy (FlatpakSystemHelper *object, g_autoptr(FlatpakOciIndex) index = NULL; const FlatpakOciManifestDescriptor *desc; g_autoptr(FlatpakOciVersioned) versioned = NULL; + g_autoptr(FlatpakOciImage) image_config = NULL; g_autoptr(FlatpakRemoteState) state = NULL; FlatpakCollectionRef collection_ref; g_autoptr(GHashTable) remote_refs = NULL; @@ -545,6 +546,16 @@ handle_deploy (FlatpakSystemHelper *object, return TRUE; } + image_config = flatpak_oci_registry_load_image_config (registry, NULL, + FLATPAK_OCI_MANIFEST (versioned)->config.digest, + NULL, NULL, &error); + if (image_config == NULL) + { + g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Can't open child image config"); + return TRUE; + } + state = flatpak_dir_get_remote_state (system, arg_origin, FALSE, NULL, &error); if (state == NULL) { @@ -582,7 +593,7 @@ handle_deploy (FlatpakSystemHelper *object, return TRUE; } - checksum = flatpak_pull_from_oci (flatpak_dir_get_repo (system), registry, NULL, desc->parent.digest, FLATPAK_OCI_MANIFEST (versioned), + checksum = flatpak_pull_from_oci (flatpak_dir_get_repo (system), registry, NULL, desc->parent.digest, FLATPAK_OCI_MANIFEST (versioned), image_config, arg_origin, arg_ref, NULL, NULL, NULL, &error); if (checksum == NULL) { |