mirror of
https://github.com/containers/podman-compose.git
synced 2025-06-01 07:55:43 +02:00
FIXES #409: detect changes and recreate
This commit is contained in:
parent
48a19f13fc
commit
529391963d
@ -36,6 +36,8 @@ from dotenv import dotenv_values
|
|||||||
|
|
||||||
__version__ = "1.0.4"
|
__version__ = "1.0.4"
|
||||||
|
|
||||||
|
script = os.path.realpath(sys.argv[0])
|
||||||
|
|
||||||
# helper functions
|
# helper functions
|
||||||
is_str = lambda s: isinstance(s, str)
|
is_str = lambda s: isinstance(s, str)
|
||||||
is_dict = lambda d: isinstance(d, dict)
|
is_dict = lambda d: isinstance(d, dict)
|
||||||
@ -1468,7 +1470,7 @@ class PodmanCompose:
|
|||||||
podman_compose_labels = [
|
podman_compose_labels = [
|
||||||
"io.podman.compose.config-hash=" + self.yaml_hash,
|
"io.podman.compose.config-hash=" + self.yaml_hash,
|
||||||
"io.podman.compose.project=" + project_name,
|
"io.podman.compose.project=" + project_name,
|
||||||
"io.podman.compose.version={__version__}",
|
"io.podman.compose.version=" + __version__,
|
||||||
"com.docker.compose.project=" + project_name,
|
"com.docker.compose.project=" + project_name,
|
||||||
"com.docker.compose.project.working_dir=" + dirname,
|
"com.docker.compose.project.working_dir=" + dirname,
|
||||||
"com.docker.compose.project.config_files=" + ",".join(relative_files),
|
"com.docker.compose.project.config_files=" + ",".join(relative_files),
|
||||||
@ -1713,7 +1715,6 @@ def compose_systemd(compose, args):
|
|||||||
later you can add a compose stack by running `podman-compose -a register`
|
later you can add a compose stack by running `podman-compose -a register`
|
||||||
then you can start/stop your stack with `systemctl --user start podman-compose@<PROJ>`
|
then you can start/stop your stack with `systemctl --user start podman-compose@<PROJ>`
|
||||||
"""
|
"""
|
||||||
script = os.path.realpath(sys.argv[0])
|
|
||||||
stacks_dir = ".config/containers/compose/projects"
|
stacks_dir = ".config/containers/compose/projects"
|
||||||
if args.action == "register":
|
if args.action == "register":
|
||||||
proj_name = compose.project_name
|
proj_name = compose.project_name
|
||||||
@ -1912,16 +1913,24 @@ def get_excluded(compose, args):
|
|||||||
podman_compose, "up", "Create and start the entire stack or some of its services"
|
podman_compose, "up", "Create and start the entire stack or some of its services"
|
||||||
)
|
)
|
||||||
def compose_up(compose, args):
|
def compose_up(compose, args):
|
||||||
|
proj_name = compose.project_name
|
||||||
excluded = get_excluded(compose, args)
|
excluded = get_excluded(compose, args)
|
||||||
if not args.no_build:
|
if not args.no_build:
|
||||||
# `podman build` does not cache, so don't always build
|
# `podman build` does not cache, so don't always build
|
||||||
build_args = argparse.Namespace(if_not_exists=(not args.build), **args.__dict__)
|
build_args = argparse.Namespace(if_not_exists=(not args.build), **args.__dict__)
|
||||||
compose.commands["build"](compose, build_args)
|
compose.commands["build"](compose, build_args)
|
||||||
|
|
||||||
# TODO: implement check hash label for change
|
hashes = compose.podman.output([], "ps", [
|
||||||
if args.force_recreate:
|
"--filter",
|
||||||
|
f"label=io.podman.compose.project={proj_name}",
|
||||||
|
"-a", "--format", "{{ index .Labels \"io.podman.compose.config-hash\"}}"
|
||||||
|
]).decode('utf-8').splitlines()
|
||||||
|
diff_hashes = [ i for i in hashes if i and i!=compose.yaml_hash ]
|
||||||
|
if args.force_recreate or len(diff_hashes):
|
||||||
|
log("recreating: ...")
|
||||||
down_args = argparse.Namespace(**dict(args.__dict__, volumes=False))
|
down_args = argparse.Namespace(**dict(args.__dict__, volumes=False))
|
||||||
compose.commands["down"](compose, down_args)
|
compose.commands["down"](compose, down_args)
|
||||||
|
log("recreating: done\n\n")
|
||||||
# args.no_recreate disables check for changes (which is not implemented)
|
# args.no_recreate disables check for changes (which is not implemented)
|
||||||
|
|
||||||
podman_command = "run" if args.detach and not args.no_start else "create"
|
podman_command = "run" if args.detach and not args.no_start else "create"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user