def runmode(project: Project, runmode: Optional[ProjectRunMode], force): """Get/set project runmode (debug/production)""" if runmode is None: click.echo(project.runmode.name) else: if project.runmode == runmode: click.echo( f"The current project runmode is already {runmode.name}", err=True ) return if not force: if runmode is ProjectRunMode.production: if not HAS_MASTER_SECRET: click.echo( red("Set a master secret before switching to production"), err=True, ) sys.exit(1) return 1 # We need https://github.com/Santandersecurityresearch/DrHeader/pull/102 # for the return 1 to work, but it's not released yet previous_runmode = project.runmode project.runmode = runmode click.echo( f"Switched runmode: {previous_runmode.name} → {runmode.name}", err=True )
def runmode(project: Project, runmode: Optional[ProjectRunMode]): """Get/set project runmode (debug/production)""" if runmode is None: click.echo(project.runmode.name) else: if project.runmode == runmode: click.echo( f"The current project runmode is already {runmode.name}", err=True) else: previous_runmode = project.runmode project.runmode = runmode click.echo( f"Switched runmode: {previous_runmode.name} → {runmode.name}", err=True)
def test_docker_compose_addition_per_runmode(testproj, mocker): from derex.runner.compose_utils import get_compose_options with testproj: docker_compose_path = Path(testproj._tmpdir.name) / "docker-compose-debug.yml" with docker_compose_path.open("w") as fh: fh.write("lms:\n image: foobar\n") project = Project() opts = get_compose_options(args=[], variant="", project=project) # The last option should be the path of the debug docker compose assert opts[-1] == str(docker_compose_path) project.runmode = ProjectRunMode.production opts = get_compose_options(args=[], variant="", project=project) # The last option should be the path of the production docker compose file assert opts[-1] != str(docker_compose_path)
def test_docker_compose_addition_per_runmode(minimal_project, mocker, capsys): with minimal_project: docker_compose_debug_path = Project().root / "docker-compose-debug.yml" with docker_compose_debug_path.open("w") as fh: fh.write("lms:\n image: foobar\n") project = Project() run_ddc_project([], project, dry_run=True) output = capsys.readouterr().out # The last option should be the path of the debug docker compose assert output.endswith(f"-f {docker_compose_debug_path}\n") project.runmode = ProjectRunMode.production default_project_docker_compose_file = project.private_filepath( "docker-compose.yml") run_ddc_project([], project, dry_run=True) output = capsys.readouterr().out # The last option should be the path of the project default docker compose file assert output.endswith(f"-f {default_project_docker_compose_file}\n")