def run_using_kaniko(self): if self.tag: self.image_name_with_tag = "{}:{}".format(self.image_name, self.tag) else: self.image_name_with_tag = self.full_image_name command = "{} -c {} -f {}".format( self.kaniko_command, self.context, self.docker_file ) if not self.destinations: command = command + " --no-push" else: destination_list = [ " -d {}".format(destination) for destination in self.destinations ] command = command + "".join(destination_list) if self.build_args: build_args_list = [" --build-arg {}".format(arg) for arg in self.build_args] command = command + "".join(build_args_list) if self.label: command = command + " --label " + self.label if self.target: command = command + " --target " + self.target try: logger.info("Running build using Kaniko: %s", command) run_cmd(command, shell=True, cwd=project_path()) except Exception as e: raise DatabandRuntimeError( "failed building docker image {}".format("?"), nested_exceptions=[e] )
def run_using_docker_build(self): if self.tag: self.image_name_with_tag = "{}:{}".format(self.image_name, self.tag) else: self.image_name_with_tag = self.full_image_name try: cmd = "docker build -t {} -f {} .".format( self.image_name_with_tag, self.docker_file ) if self.label: cmd = cmd + " --label " + self.label if self.target: cmd = cmd + " --target " + self.target if self.build_args: build_args_list = [ " --build-arg {}".format(arg) for arg in self.build_args ] cmd = cmd + "".join(build_args_list) logger.info("Running docker build command: `%s`\n\n", cmd) cwd = self.working_dir or project_path() run_cmd(cmd, shell=True, cwd=cwd) except Exception as e: logger.error( "^^^^^^^^^^^^^^^ SEE DOCKER ERROR MESSAGE ABOVE THIS LINE ^^^^^^^^^^^^^^^\n\n" ) raise DatabandRuntimeError( "failed building docker image {}".format(self.image_name_with_tag), nested_exceptions=[e], ) if self.push: try: cmd = "docker push {}".format(self.image_name_with_tag) logger.info("Running docker push command: '%s'", cmd) run_cmd(cmd, shell=True) except Exception as e: raise DatabandRuntimeError( "failed to push docker image {}".format(self.image_name_with_tag), nested_exceptions=[e], ) else: logger.info("skipping docker push") return self.image_name_with_tag
def _run_cmd(self, cmd): dfc = self.dataflow_config from airflow.contrib.hooks.gcp_dataflow_hook import _DataflowJob run_cmd( cmd, name="dataflow %s" % self.task_run.job_name, stdout_handler=self._process_dataflow_log, ) _DataflowJob( self._gcp_dataflow_hook.get_conn(), dfc.project, self.task_run.job_id, dfc.region, dfc.poll_sleep, self.current_dataflow_job_id, ).wait_for_done()
def run(self): if self.tag: self.image_name_with_tag = "{}:{}".format(self.image_name, self.tag) else: self.image_name_with_tag = self.full_image_name try: cmd = "docker build -t {} -f {} .".format( self.image_name_with_tag, self.docker_file ) if self.label: cmd = cmd + " --label " + self.label if self.target: cmd = cmd + " --target " + self.target logger.info("Running docker build: %s", cmd) cwd = self.working_dir or project_path() run_cmd(cmd, shell=True, cwd=cwd) except Exception as e: raise DatabandRuntimeError( "failed building docker image {}".format(self.image_name_with_tag), nested_exceptions=[e], ) if self.push: try: cmd = "docker push {}".format(self.image_name_with_tag) logger.info("Running docker push: '%s'", cmd) run_cmd(cmd, shell=True) except Exception as e: raise DatabandRuntimeError( "failed to push docker image {}".format(self.image_name_with_tag), nested_exceptions=[e], ) else: logger.info("skipping docker push") return self.image_name_with_tag
def _run_cmd(self, cmd): run_cmd(cmd)