Skip to content

Commit

Permalink
Support multiple profiles in docker compose invoke script
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Jul 23, 2024
1 parent 239ea54 commit 7e8f08f
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions adit_radis_shared/invoke_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ def get_stack_name(env: Environments):
raise ValueError(f"Unknown environment: {env}")


def build_compose_cmd(env: Environments, profile: str | None = None):
def build_compose_cmd(env: Environments, profiles: list[str] = []):
cmd = "docker compose"
cmd += f" -f {get_compose_base_file()}"
cmd += f" -f {get_compose_env_file(env)}"
cmd += f" -p {get_stack_name(env)}"
if profile:
for profile in profiles:
cmd += f" --profile {profile}"
return cmd

Expand Down Expand Up @@ -129,20 +129,17 @@ def get_latest_version_tag(owner, repo) -> str | None:
###


@task
def compose_up(ctx: Context, env: Environments = "dev", no_build=False, profile: str | None = None):
@task(iterable=["profile"])
def compose_up(ctx: Context, env: Environments = "dev", no_build=False, profile: list[str] = []):
"""Start containers in specified environment"""
build_opt = "--no-build" if no_build else "--build"
cmd = f"{build_compose_cmd(env, profile)} up {build_opt} --detach"
ctx.run(cmd, pty=True)


@task
@task(iterable=["profile"])
def compose_down(
ctx: Context,
env: Environments = "dev",
profile: str | None = None,
cleanup: bool = False,
ctx: Context, env: Environments = "dev", cleanup: bool = False, profile: list[str] = []
):
"""Stop containers in specified environment"""
cmd = f"{build_compose_cmd(env, profile)} --profile {profile} down"
Expand Down

0 comments on commit 7e8f08f

Please sign in to comment.