def _docker_compose(conf: AiscalatorConfig, extra_commands: list): """ Run the docker-compose command Parameters ---------- conf : AiscalatorConfig Configuration object for the application extra_commands : list list of sub-commands to run in docker-compose """ logger = logging.getLogger(__name__) conf.validate_config() dockerfile = join(conf.app_config_home(), "config", conf.airflow_docker_compose_file()) commands = ["docker-compose"] # Prepare a temp folder to run the command from with TemporaryDirectory(prefix="aiscalator_") as tmp: with open(join(tmp, ".env"), mode="w") as env_file: # concatenate all the env files into one for env in conf.user_env_file(conf.dag_field("definition.env")): if isfile(env): with open(env, mode="r") as file: for line in file: env_file.write(line) utils.copy_replace(join(tmp, ".env"), join(dirname(dockerfile), ".env")) commands += ["-f", dockerfile] + extra_commands logger.info("Running...: %s", " ".join(commands)) utils.subprocess_run(commands, no_redirect=True)
def _docker_compose_grep(conf: AiscalatorConfig): """ Checks if the docker-compose file is using the aiscalator/airflow docker image. In which case, we need to make sure that image is properly built and available. Parameters ---------- conf : AiscalatorConfig Configuration object for the application Returns ------- bool Returns if aiscalator/airflow docker image is needed and should be built. """ docker_compose_file = join(conf.app_config_home(), "config", conf.airflow_docker_compose_file()) pattern = re.compile(r"\s+image:\s+aiscalator/airflow") try: with open(docker_compose_file, "r") as file: for line in file: if re.match(pattern, line): # docker compose needs the image return True except FileNotFoundError: # no docker compose, default will need the image return True return False