def apply_mesos_patches(build_dir_mesos): ## LOOKUP order: # - <mesos-version>-<os-family>-<os-version> # - <mesos-version>-<os-family> # - <mesos-version> patch_files = [ "{}/{}-{}.patch".format( MesosConfig.mesos_patches_dir(), MesosConfig.mesos_version(), MesosConfig.operating_system().replace(":", "-") ), "{}/{}-{}.patch".format( MesosConfig.mesos_patches_dir(), MesosConfig.mesos_version(), MesosConfig.operating_system().split(":")[0] ), "{}/{}.patch".format( MesosConfig.mesos_patches_dir(), MesosConfig.mesos_version() ) ] patch_file_to_use = None for patch_file in patch_files: if os.path.isfile(patch_file): patch_file_to_use = patch_file break if patch_file_to_use != None: LOG.info("Found a patch file {} for mesos. Applying...".format( patch_file_to_use )) result = Utils.cmd("cd {} && git apply {}".format(build_dir_mesos, patch_file_to_use)) if result['ExitCode'] != 0: Utils.print_result_error(LOG, "Patch could not be applied to {}.".format( build_dir_mesos ), result) exit(105) else: LOG.info("Patch applied.") else: LOG.info("No patches for mesos {}.".format( MesosConfig.deb_packaging_sha() ))
def list_releases(): result = Utils.cmd("cd {} && git tag -l".format(MesosConfig.mesos_repository_dir())) if result['ExitCode'] == 0: releases = result['StdOut'].split("\n") releases.append(MesosConfig.mesos_master_branch()) return releases else: Utils.print_result_error(LOG, "Failed listing releases.", result) return []
def build_with_docker(build_dir_mesos, build_dir_packaging, packages_dir): image_name = "mesos-docker-build-{}".format(MesosConfig.operating_system().replace(":","-")) # Do we have the Docker image? LOG.info("Checking for Docker image...") result = Utils.cmd("docker images") # Simply make sure we have docker operational if result['ExitCode'] != 0: Utils.print_result_error(LOG, "Not able to list Docker images. Is Docker installed and running?", result) exit(105) # repeat, grep returns 1 if text not found result = Utils.cmd("docker images | grep {}".format(image_name)) if result['StdOut'] == "": LOG.info("Docker image not found. Building...") result = Utils.cmd( "cd {}/{} && docker build --no-cache --force-rm=true -t {} .".format( MesosConfig.docker_templates_dir(), MesosConfig.operating_system().replace(":", "\\:"), image_name ) ) if result['ExitCode'] != 0: Utils.print_result_error(LOG, "Docker image creation failed. Is Docker installed and running?", result) exit(106) 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)) 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)
def ensure_sources(): path = MesosConfig.mesos_repository_dir() if os.path.isdir("{}/.git".format(path)): LOG.info("Updating sources for {}...".format(MesosConfig.mesos_git_repository())) result = Utils.cmd("cd {} && git fetch origin".format(path)) if result['ExitCode'] == 0: LOG.info("Done.") return True else: Utils.print_result_error(LOG, "Failed.", result) return False else: LOG.info("No sources for {} found. Cloning...".format(MesosConfig.mesos_git_repository())) result = Utils.cmd("cd {} && git clone {} .".format(path, MesosConfig.mesos_git_repository())) if result['ExitCode'] == 0: LOG.info("Done.") return True else: Utils.print_result_error(LOG, "Failed.", result) return False
def vagrant_command(cmd): validate_input() signal.signal(signal.SIGINT, signal_handler) base = os.path.dirname(os.path.abspath(__file__)) command = "cd {}/vagrant".format(base) exports = get_exports_from_config() first_master_ip = exports['MASTER_IPS'].split(',')[0] for key, value in exports.iteritems(): command = "{}; export {}={}".format(command, key, value) command = "{}; vagrant {}".format(command, cmd) if VagrantConfig.machine() != "": command = "{} {}".format(command, VagrantConfig.machine()) result = Utils.cmd(command, True) if result['ExitCode'] != 0: Utils.print_result_error(LOG, "Vagrant command execution has failed.", result) else: if cmd == "up": LOG.info("You cluster is up and running \\o/.") LOG.info("- to access the Mesos UI, point your browser to: http://{}:5050".format(first_master_ip)) LOG.info("- to access the Consul UI, point your browser to: http://{}:8500".format(first_master_ip)) LOG.info("- to access the Marathon UI, point your browser to: http://{}:8080".format(first_master_ip))
def ensure_deb_packaging(): path = MesosConfig.deb_packaging_repository_dir() if os.path.isdir("{}/.git".format(path)): LOG.info("Updating sources for {}...".format(MesosConfig.deb_packaging_repository())) # TODO: compare given sha and repo sha # TODO: if different, reset, pull, checkout # TODO: apply patches for deb-packaging, if any... LOG.info("Done.") return True else: LOG.info("No sources for {} found. Cloning...".format(MesosConfig.deb_packaging_repository())) result = Utils.cmd("cd {} && git clone {} . && git fetch origin && git checkout {}".format( path, MesosConfig.deb_packaging_repository(), MesosConfig.deb_packaging_sha() )) if result['ExitCode'] == 0: LOG.info("Done.") # TODO: apply patches for deb-packaging, if any... return True else: Utils.print_result_error(LOG, "Failed.", result) return False
def op_build(): if Utils.ensure_sources(LOG, MesosConfig.mesos_repository_dir(), MesosConfig.mesos_git_repository()) and ensure_deb_packaging(): validate_input() # create temp work dir: build_dir_mesos = "{}/{}-{}".format( MesosConfig.work_dir(), MesosConfig.mesos_version(), MesosConfig.operating_system().replace(":", "-") ) build_dir_packaging = "{}/{}-{}-packaging".format( MesosConfig.work_dir(), MesosConfig.mesos_version(), MesosConfig.operating_system().replace(":", "-") ) packages_dir = "{}/{}-{}".format( MesosConfig.packages_dir(), MesosConfig.mesos_version(), MesosConfig.operating_system().replace(":", "-") ) ## LOOKUP order: # - <sha>-<mesos-version>-<os-family>-<os-version> # - <sha>-<mesos-version>-<os-family> # - <sha>-<os-family>-<os-version> # - <sha>-<os-family> # - <sha> patch_files = [ "{}/{}-{}-{}.patch".format( MesosConfig.packages_patches_dir(), MesosConfig.deb_packaging_sha(), MesosConfig.mesos_version(), MesosConfig.operating_system().replace(":", "-") ), "{}/{}-{}-{}.patch".format( MesosConfig.packages_patches_dir(), MesosConfig.deb_packaging_sha(), MesosConfig.mesos_version(), MesosConfig.operating_system().split(":")[0] ), "{}/{}-{}.patch".format( MesosConfig.packages_patches_dir(), MesosConfig.deb_packaging_sha(), MesosConfig.operating_system().replace(":", "-") ), "{}/{}-{}.patch".format( MesosConfig.packages_patches_dir(), MesosConfig.deb_packaging_sha(), MesosConfig.operating_system().split(":")[0] ), "{}/{}.patch".format( MesosConfig.packages_patches_dir(), MesosConfig.deb_packaging_sha() ) ] if os.path.exists(packages_dir): if not Utils.confirm("Mesos build for {} {} already exists. To rebuild, continue.".format( MesosConfig.mesos_version(), MesosConfig.operating_system() )): exit(0) build_log_file = "{}.{}.log".format(build_dir_mesos, str(int(time.time()))) LOG.info("Recording build process to {}.".format(build_log_file)) Config.set_cmd_log(build_log_file) # cleanup old data: Utils.cmd("rm -rf {}".format(packages_dir)) Utils.cmd("rm -rf {}".format(build_dir_mesos)) Utils.cmd("rm -rf {}".format(build_dir_packaging)) # copy sources LOG.info("Fetching Mesos {} sources...".format(MesosConfig.mesos_git_repository())) Utils.cmd("cp -R {} {}".format( MesosConfig.mesos_repository_dir(), build_dir_mesos )) Utils.cmd("cp -R {} {}".format( MesosConfig.deb_packaging_repository_dir(), build_dir_packaging )) patch_file_to_use = None for patch_file in patch_files: if os.path.isfile(patch_file): patch_file_to_use = patch_file break if patch_file_to_use != None: LOG.info("Found a patch file {} for mesos-deb-packaging. Applying...".format( patch_file_to_use )) result = Utils.cmd("cd {} && git apply {}".format(build_dir_packaging, patch_file_to_use)) if result['ExitCode'] != 0: Utils.print_result_error(LOG, "Patch could not be applied to {}.".format( build_dir_packaging ), result) exit(105) else: LOG.info("Patch applied.") else: LOG.info("No patches for mesos-deb-packaging {}.".format( MesosConfig.deb_packaging_sha() )) # ensure branch / tag Utils.exit_if_git_release_not_set( LOG, build_dir_mesos, MesosConfig.mesos_version(), MesosConfig.mesos_master_branch(), MesosConfig.mesos_git_repository() ) # We have the right sources now: if MesosConfig.operating_system() == "osx": build_with_osx( build_dir_mesos, build_dir_packaging, packages_dir ) else: build_with_docker( build_dir_mesos, build_dir_packaging, packages_dir )