def build_with_docker(build_dir_mesos, build_dir_packaging, packages_dir):
    image_name = "mesos-docker-build-{}".format(MesosConfig.operating_system().replace(":","-"))
    if not Utils.is_docker_image(LOG, image_name):
        LOG.info("Docker image not found. Building...")
        Utils.exit_if_docker_image_not_built( LOG,
                                              MesosConfig.docker_templates_dir(),
                                              MesosConfig.operating_system().replace(":", "\\:"),
                                              image_name )

    mesos_build_command = "docker run -ti -v {}:/mesos-deb-packaging -v {}:/mesos-src {} /bin/bash -c 'cd /mesos-deb-packaging && ./build_mesos --build-version {} --src-dir /mesos-src; exit $?'".format(
                                  build_dir_packaging,
                                  build_dir_mesos,
                                  image_name,
                                  MesosConfig.mesos_build_version() )

    Utils.cmd("echo '{}'".format(mesos_build_command.replace("'", "\\'")))
    LOG.info("Building Mesos {} for {}. This will take a while...".format(MesosConfig.mesos_version(), MesosConfig.operating_system()))
    build_start_time = int(time.time())
    build_status = Utils.cmd(mesos_build_command)
    build_end_time = int(time.time())
    if build_status['ExitCode'] == 0:
        Utils.cmd("mkdir -p {0} && rm -Rf {0}/*".format( packages_dir ))
        Utils.cmd("mv {}/*.deb {}/ 2>/dev/null".format( build_dir_packaging, packages_dir ))
        Utils.cmd("mv {}/*.rpm {}/ 2>/dev/null".format( build_dir_packaging, packages_dir ))
        Utils.cmd("mv {}/*.egg {}/ 2>/dev/null".format( build_dir_packaging, packages_dir ))#
        LOG.info( "Mesos {} for {} built successfully. Build took {} seconds. Output available in {}. Cleaning up...".format(
                    MesosConfig.mesos_version(),
                    MesosConfig.operating_system(),
                    str( build_end_time - build_start_time ),
                    packages_dir ))
        Utils.cmd("rm -rf {}".format(build_dir_mesos))
        Utils.cmd("rm -rf {}".format(build_dir_packaging))
    else:
        LOG.error( "Mesos build failed. Leaving build log and temp directories for inspection. mesos={}; packaging={}".format( build_dir_mesos, build_dir_packaging ) )
        exit(107)
dataset/ETHPy150Open radekg/mesos-toolbox/mesos-toolbox.py/build_with_docker/original