From a86ad96669070cba8ea88489241c2e4eb83a52fb Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 9 Oct 2018 11:23:52 -0400 Subject: [PATCH] compose: Support not specifying a ref Split out of supporting "pure rojig" work. We also want to support this for doing "oscontainers" as is planned for Red Hat CoreOS. The user experience in both cases is oriented around versioning of the external wrapper, not the inner ref/commit. Note for users/builders who want to make use of this feature: You probably want to mirror the changes in our test suite here to use the compose JSON and parse the resulting `ostree-commit` out of that. Closes: #1603 Approved by: jlebon --- src/app/rpmostree-compose-builtin-tree.c | 54 +++++++++++--------- tests/compose-tests/libcomposetest.sh | 10 ++-- tests/compose-tests/test-installroot.sh | 2 +- tests/compose-tests/test-machineid-compat.sh | 10 +++- tests/compose-tests/test-write-commitid.sh | 9 ++-- tests/composedata/fedora-base.json | 1 - 6 files changed, 50 insertions(+), 36 deletions(-) diff --git a/src/app/rpmostree-compose-builtin-tree.c b/src/app/rpmostree-compose-builtin-tree.c index a5b5b99e..d4edbabd 100644 --- a/src/app/rpmostree-compose-builtin-tree.c +++ b/src/app/rpmostree-compose-builtin-tree.c @@ -286,7 +286,8 @@ install_packages_in_root (RpmOstreeTreeComposeContext *self, return glnx_throw (error, "--download-only can only be used with --cachedir"); g_autoptr(GKeyFile) treespec = g_key_file_new (); - g_key_file_set_string (treespec, "tree", "ref", self->ref); + if (self->ref) + g_key_file_set_string (treespec, "tree", "ref", self->ref); g_key_file_set_string_list (treespec, "tree", "packages", (const char *const*)packages, g_strv_length (packages)); { const char *releasever; if (!_rpmostree_jsonutil_object_get_optional_string_member (treedata, "releasever", @@ -691,12 +692,15 @@ rpm_ostree_compose_context_new (const char *treefile_pathstr, self->treefile = json_node_get_object (self->treefile_rootval); g_autoptr(GHashTable) varsubsts = rpmostree_dnfcontext_get_varsubsts (rpmostree_context_get_dnf (self->corectx)); - const char *input_ref = _rpmostree_jsonutil_object_require_string_member (self->treefile, "ref", error); - if (!input_ref) - return FALSE; - self->ref = _rpmostree_varsubst_string (input_ref, varsubsts, error); - if (!self->ref) + const char *input_ref = NULL; + if (!_rpmostree_jsonutil_object_get_optional_string_member (self->treefile, "ref", &input_ref, error)) return FALSE; + if (input_ref) + { + self->ref = _rpmostree_varsubst_string (input_ref, varsubsts, error); + if (!self->ref) + return FALSE; + } g_autoptr(GFile) treefile_dir = g_file_get_parent (self->treefile_path); @@ -748,24 +752,26 @@ impl_install_tree (RpmOstreeTreeComposeContext *self, } /* Read the previous commit */ - { g_autoptr(GError) temp_error = NULL; - if (!ostree_repo_read_commit (self->repo, self->ref, &self->previous_root, &self->previous_checksum, - cancellable, &temp_error)) - { - if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) - { - g_clear_error (&temp_error); - g_print ("No previous commit for %s\n", self->ref); - } - else - { - g_propagate_error (error, g_steal_pointer (&temp_error)); - return FALSE; - } - } - else - g_print ("Previous commit: %s\n", self->previous_checksum); - } + if (self->ref) + { + g_autoptr(GError) temp_error = NULL; + if (!ostree_repo_read_commit (self->repo, self->ref, &self->previous_root, &self->previous_checksum, + cancellable, &temp_error)) + { + if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) + { + g_clear_error (&temp_error); + g_print ("No previous commit for %s\n", self->ref); + } + else + { + g_propagate_error (error, g_steal_pointer (&temp_error)); + return FALSE; + } + } + else + g_print ("Previous commit: %s\n", self->previous_checksum); + } const char rootfs_name[] = "rootfs.tmp"; if (!glnx_shutil_rm_rf_at (self->workdir_dfd, rootfs_name, cancellable, error)) diff --git a/tests/compose-tests/libcomposetest.sh b/tests/compose-tests/libcomposetest.sh index c56b881c..73970897 100644 --- a/tests/compose-tests/libcomposetest.sh +++ b/tests/compose-tests/libcomposetest.sh @@ -45,10 +45,10 @@ enabled=1 gpgcheck=0 EOF export treefile=composedata/fedora-${name}.json - pyeditjson "jd['ref'] += \"/${name}\"" < composedata/fedora-base.json > ${treefile} + export treeref=fedora/stable/x86_64/${name} + pyeditjson 'jd["ref"] = "'${treeref}'"' < composedata/fedora-base.json > ${treefile} pysetjsonmember "repos" '["fedora-local"]' ${treefile} # FIXME extract from json - export treeref=fedora/stable/x86_64/${name} if [ "${filetype}" = "yaml" ]; then python < ${treefile}.new +mv ${treefile}{.new,} +treeref="" pysetjsonmember "machineid-compat" 'False' cat > composedata/fedora-machineid-compat-includer.yaml < ls.txt +ostree --repo="${repobuild}" refs >refs.txt +diff -u /dev/null refs.txt +echo "ok no refs written" + +ostree --repo=${repobuild} ls ${commit} /usr/etc > ls.txt assert_not_file_has_content ls.txt 'machine-id' echo "ok machineid-compat" diff --git a/tests/compose-tests/test-write-commitid.sh b/tests/compose-tests/test-write-commitid.sh index eb49d615..b066db74 100755 --- a/tests/compose-tests/test-write-commitid.sh +++ b/tests/compose-tests/test-write-commitid.sh @@ -6,8 +6,8 @@ dn=$(cd $(dirname $0) && pwd) . ${dn}/libcomposetest.sh prepare_compose_test "write-commitid" -runcompose --write-commitid-to $(pwd)/commitid.txt \ - --write-composejson-to $(pwd)/composemeta.json +treeref="" +runcompose --write-commitid-to $(pwd)/commitid.txt wc -c < commitid.txt > wc.txt assert_file_has_content_literal wc.txt 64 echo "ok compose" @@ -19,11 +19,10 @@ fi echo "ok ref not written" commitid_txt=$(cat commitid.txt) -json_commit=$(jq -r '.["ostree-commit"]' composemeta.json) -assert_streq "${json_commit}" "${commitid_txt}" +assert_streq "${commit}" "${commitid_txt}" # And verify we have other keys for key in ostree-version rpm-ostree-inputhash ostree-content-bytes-written; do - jq -r '.["'${key}'"]' composemeta.json >/dev/null + jq -r '.["'${key}'"]' ${composejson} >/dev/null done echo "ok composejson" diff --git a/tests/composedata/fedora-base.json b/tests/composedata/fedora-base.json index 36a3c729..b1f7c230 100644 --- a/tests/composedata/fedora-base.json +++ b/tests/composedata/fedora-base.json @@ -1,5 +1,4 @@ { - "ref": "fedora/stable/${basearch}", "rojig": { "name": "fedora-atomic-host", "license": "MIT",