From 15db71aec7d169aa164055b3eb5829d672db214f Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 9 Feb 2017 14:22:13 +0100 Subject: [PATCH] update: support update to a different image via --rebase It allows to override the image to use for the update. Signed-off-by: Giuseppe Scrivano Closes: #883 Approved by: rhatdan --- Atomic/containers.py | 6 ++++-- Atomic/syscontainers.py | 4 ++-- bash/atomic | 2 +- docs/atomic-containers.1.md | 3 +++ tests/integration/test_system_containers.sh | 3 +++ 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Atomic/containers.py b/Atomic/containers.py index 047b3f0..0b22495 100644 --- a/Atomic/containers.py +++ b/Atomic/containers.py @@ -73,6 +73,8 @@ def cli(subparser): updatep.set_defaults(_class=Containers, func='update') updatep.add_argument("container", help=_("Specify one or more containers. Must be final arguments.")) + updatep.add_argument("--rebase", dest="rebase", default=None, + help=_("Rebase to a different image (useful for upgrading to a different tag)")) if OSTREE_PRESENT: updatep.add_argument("--set", dest="setvalues", action='append', @@ -263,9 +265,9 @@ class Containers(Atomic): if con.id in vulnerable_uuids: con.vulnerable = True - def update(self, to=None): + def update(self): if self.syscontainers.get_checkout(self.args.container): - return self.syscontainers.update_container(self.args.container, self.args.setvalues) + return self.syscontainers.update_container(self.args.container, self.args.setvalues, self.args.rebase) raise ValueError("System container '%s' is not installed" % self.args.container) def rollback(self): diff --git a/Atomic/syscontainers.py b/Atomic/syscontainers.py index 69fff41..8094586 100644 --- a/Atomic/syscontainers.py +++ b/Atomic/syscontainers.py @@ -586,7 +586,7 @@ class SystemContainers(object): return [image_inspect] return None - def update_container(self, name, setvalues=None): + def update_container(self, name, setvalues=None, rebase=None): repo = self._get_ostree_repo() if not repo: raise ValueError("Cannot find a configured OSTree repo") @@ -605,7 +605,7 @@ class SystemContainers(object): with open(os.path.join(self._get_system_checkout_path(), name, "info"), "r") as info_file: info = json.loads(info_file.read()) - image = info["image"] + image = rebase or info["image"] values = info["values"] revision = info["revision"] if "revision" in info else None diff --git a/bash/atomic b/bash/atomic index 0e9abdd..cf6a979 100644 --- a/bash/atomic +++ b/bash/atomic @@ -578,7 +578,7 @@ _atomic_containers_trim() { _atomic_containers_update() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --set" -- "$cur" ) ) + COMPREPLY=( $( compgen -W "--help --set --rebase" -- "$cur" ) ) ;; *) __atomic_system_containers_containers diff --git a/docs/atomic-containers.1.md b/docs/atomic-containers.1.md index f84d482..eeeea43 100644 --- a/docs/atomic-containers.1.md +++ b/docs/atomic-containers.1.md @@ -87,6 +87,9 @@ Can use --set to update environment variables. Only display container IDs # update OPTIONS: +**--rebase=IMAGE** + Rebase to a different image. If not specified, the same image used to install the container will be used. + **--set=NAME=VALUE** Set a value that is going to be used by a system container for its configuration and can be specified multiple times. OSTree is required for this feature to be available. diff --git a/tests/integration/test_system_containers.sh b/tests/integration/test_system_containers.sh index c57b633..252e437 100755 --- a/tests/integration/test_system_containers.sh +++ b/tests/integration/test_system_containers.sh @@ -176,6 +176,9 @@ assert_matches 8081 ${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME}.0/config.json ${ATOMIC} containers update ${NAME} > update.out assert_matches "Latest version already installed" update.out +${ATOMIC} containers update ${NAME} --rebase oci:atomic-test-system > update.out +assert_matches "Latest version already installed" update.out + ${ATOMIC} containers update --set=PORT=8082 ${NAME} test -e ${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME}.1/${NAME}.service test -e ${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME}.1/tmpfiles-${NAME}.conf