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
This commit is contained in:
Colin Walters 2018-10-09 11:23:52 -04:00 committed by Atomic Bot
parent 51e90eaf8d
commit a86ad96669
6 changed files with 50 additions and 36 deletions

View File

@ -286,7 +286,8 @@ install_packages_in_root (RpmOstreeTreeComposeContext *self,
return glnx_throw (error, "--download-only can only be used with --cachedir"); return glnx_throw (error, "--download-only can only be used with --cachedir");
g_autoptr(GKeyFile) treespec = g_key_file_new (); 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)); g_key_file_set_string_list (treespec, "tree", "packages", (const char *const*)packages, g_strv_length (packages));
{ const char *releasever; { const char *releasever;
if (!_rpmostree_jsonutil_object_get_optional_string_member (treedata, "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); self->treefile = json_node_get_object (self->treefile_rootval);
g_autoptr(GHashTable) varsubsts = rpmostree_dnfcontext_get_varsubsts (rpmostree_context_get_dnf (self->corectx)); 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); const char *input_ref = NULL;
if (!input_ref) if (!_rpmostree_jsonutil_object_get_optional_string_member (self->treefile, "ref", &input_ref, error))
return FALSE;
self->ref = _rpmostree_varsubst_string (input_ref, varsubsts, error);
if (!self->ref)
return FALSE; 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); 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 */ /* Read the previous commit */
{ g_autoptr(GError) temp_error = NULL; if (self->ref)
if (!ostree_repo_read_commit (self->repo, self->ref, &self->previous_root, &self->previous_checksum, {
cancellable, &temp_error)) g_autoptr(GError) temp_error = NULL;
{ if (!ostree_repo_read_commit (self->repo, self->ref, &self->previous_root, &self->previous_checksum,
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) cancellable, &temp_error))
{ {
g_clear_error (&temp_error); if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
g_print ("No previous commit for %s\n", self->ref); {
} g_clear_error (&temp_error);
else g_print ("No previous commit for %s\n", self->ref);
{ }
g_propagate_error (error, g_steal_pointer (&temp_error)); else
return FALSE; {
} g_propagate_error (error, g_steal_pointer (&temp_error));
} return FALSE;
else }
g_print ("Previous commit: %s\n", self->previous_checksum); }
} else
g_print ("Previous commit: %s\n", self->previous_checksum);
}
const char rootfs_name[] = "rootfs.tmp"; const char rootfs_name[] = "rootfs.tmp";
if (!glnx_shutil_rm_rf_at (self->workdir_dfd, rootfs_name, cancellable, error)) if (!glnx_shutil_rm_rf_at (self->workdir_dfd, rootfs_name, cancellable, error))

View File

@ -45,10 +45,10 @@ enabled=1
gpgcheck=0 gpgcheck=0
EOF EOF
export treefile=composedata/fedora-${name}.json 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} pysetjsonmember "repos" '["fedora-local"]' ${treefile}
# FIXME extract from json # FIXME extract from json
export treeref=fedora/stable/x86_64/${name}
if [ "${filetype}" = "yaml" ]; then if [ "${filetype}" = "yaml" ]; then
python <<EOF python <<EOF
import json, yaml, sys import json, yaml, sys
@ -62,11 +62,13 @@ EOF
fi fi
} }
compose_base_argv="--repo ${repobuild}" composejson=$(pwd)/compose.json
compose_base_argv="--repo ${repobuild} --write-composejson-to ${composejson}"
runcompose() { runcompose() {
echo "$(date): starting compose" echo "$(date): starting compose"
rpm-ostree compose tree ${compose_base_argv} ${treefile} "$@" rpm-ostree compose tree ${compose_base_argv} ${treefile} "$@"
ostree --repo=${repo} pull-local ${repobuild} commit=$(jq -r '.["ostree-commit"]' < "${composejson}")
ostree --repo=${repo} pull-local ${repobuild} "${treeref:-${commit}}"
echo "$(date): finished compose" echo "$(date): finished compose"
} }

View File

@ -9,7 +9,7 @@ prepare_compose_test "installroot"
# This is used to test postprocessing with treefile vs not # This is used to test postprocessing with treefile vs not
pysetjsonmember "boot_location" '"new"' pysetjsonmember "boot_location" '"new"'
instroot_tmp=$(mktemp -d /var/tmp/rpm-ostree-instroot.XXXXXX) instroot_tmp=$(mktemp -d /var/tmp/rpm-ostree-instroot.XXXXXX)
rpm-ostree compose install ${compose_base_argv} ${treefile} ${instroot_tmp} rpm-ostree compose install --repo="${repobuild}" ${treefile} ${instroot_tmp}
instroot=${instroot_tmp}/rootfs instroot=${instroot_tmp}/rootfs
assert_not_has_dir ${instroot}/usr/lib/ostree-boot assert_not_has_dir ${instroot}/usr/lib/ostree-boot
assert_not_has_dir ${instroot}/etc assert_not_has_dir ${instroot}/etc

View File

@ -22,6 +22,10 @@ echo "ok conflict with units"
# In this test we also want to test that include: # In this test we also want to test that include:
# correctly handles machineid-compat. # correctly handles machineid-compat.
prepare_compose_test "machineid-compat" prepare_compose_test "machineid-compat"
# Also test having no ref
pyeditjson 'del jd["ref"]' < ${treefile} > ${treefile}.new
mv ${treefile}{.new,}
treeref=""
pysetjsonmember "machineid-compat" 'False' pysetjsonmember "machineid-compat" 'False'
cat > composedata/fedora-machineid-compat-includer.yaml <<EOF cat > composedata/fedora-machineid-compat-includer.yaml <<EOF
include: fedora-machineid-compat.json include: fedora-machineid-compat.json
@ -30,6 +34,10 @@ export treefile=composedata/fedora-machineid-compat-includer.yaml
runcompose runcompose
echo "ok compose" echo "ok compose"
ostree --repo=${repobuild} ls ${treeref} /usr/etc > 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' assert_not_file_has_content ls.txt 'machine-id'
echo "ok machineid-compat" echo "ok machineid-compat"

View File

@ -6,8 +6,8 @@ dn=$(cd $(dirname $0) && pwd)
. ${dn}/libcomposetest.sh . ${dn}/libcomposetest.sh
prepare_compose_test "write-commitid" prepare_compose_test "write-commitid"
runcompose --write-commitid-to $(pwd)/commitid.txt \ treeref=""
--write-composejson-to $(pwd)/composemeta.json runcompose --write-commitid-to $(pwd)/commitid.txt
wc -c < commitid.txt > wc.txt wc -c < commitid.txt > wc.txt
assert_file_has_content_literal wc.txt 64 assert_file_has_content_literal wc.txt 64
echo "ok compose" echo "ok compose"
@ -19,11 +19,10 @@ fi
echo "ok ref not written" echo "ok ref not written"
commitid_txt=$(cat commitid.txt) commitid_txt=$(cat commitid.txt)
json_commit=$(jq -r '.["ostree-commit"]' composemeta.json) assert_streq "${commit}" "${commitid_txt}"
assert_streq "${json_commit}" "${commitid_txt}"
# And verify we have other keys # And verify we have other keys
for key in ostree-version rpm-ostree-inputhash ostree-content-bytes-written; do 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 done
echo "ok composejson" echo "ok composejson"

View File

@ -1,5 +1,4 @@
{ {
"ref": "fedora/stable/${basearch}",
"rojig": { "rojig": {
"name": "fedora-atomic-host", "name": "fedora-atomic-host",
"license": "MIT", "license": "MIT",