Exemple #1
0
    def upload(self):
        '''generates a unique directory, then uploads artifacts and a new stub universe to that directory'''
        try:
            universe_path = universe_builder.UniversePackageBuilder(
                self._pkg_name, self._pkg_version,
                self._input_dir_path, self._http_directory, self._artifact_paths).build_zip()
        except Exception as e:
            err = 'Failed to create stub universe: {}'.format(str(e))
            self._github_updater.update('error', err)
            raise

        # print universe url early
        universe_url = self._upload_artifact(universe_path)
        logger.info('---')
        logger.info('Built and uploaded stub universe:')
        logger.info(universe_url)
        logger.info('---')
        logger.info('Uploading {} artifacts:'.format(len(self._artifact_paths)))

        for path in self._artifact_paths:
            self._upload_artifact(path)

        self._spam_universe_url(universe_url)

        # print to stdout, while the rest is all stderr:
        print(universe_url)

        logger.info('---')
        logger.info('Install your package using the following commands:')
        logger.info('dcos package repo remove {}-aws'.format(self._pkg_name))
        logger.info('dcos package repo add --index=0 {}-aws {}'.format(self._pkg_name, universe_url))
        logger.info('dcos package install --yes {}'.format(self._pkg_name))

        return universe_url
    def launch_http(self):
        # kill any prior matching process
        procname = 'publish_httpd_{}.py'.format(self._pkg_name)
        try:
            subprocess.check_call('killall -9 {}'.format(procname).split())
            logger.info("Killed previous HTTP process(es): {}".format(procname))
        except:
            logger.info("No previous HTTP process found: {}".format(procname))

        if self._http_port == 0:
            # hack: grab/release a suitable ephemeral port and hope nobody steals it in the meantime
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.bind((self._http_host, 0))
            port = sock.getsockname()[1]
            sock.close()
        else:
            port = self._http_port

        http_url_root = 'http://{}:{}'.format(self._http_host, port)

        self._package_builder = universe_builder.UniversePackageBuilder(
            self._pkg_name, self._pkg_version,
            self._input_dir_path, http_url_root, self._artifact_paths)

        # hack: write httpd script then run it directly
        httpd_py_content = '''#!/usr/bin/env python3
import os, socketserver
from http.server import SimpleHTTPRequestHandler
rootdir = '{}'
host = '{}'
port = {}
json_content_type = '{}'

class CustomTypeHandler(SimpleHTTPRequestHandler):
    def __init__(self, req, client_addr, server):
        SimpleHTTPRequestHandler.__init__(self, req, client_addr, server)
    def guess_type(self, path):
        if path.endswith('.json'):
            return json_content_type
        return SimpleHTTPRequestHandler.guess_type(self, path)

os.chdir(rootdir)
httpd = socketserver.TCPServer((host, port), CustomTypeHandler)
print('Serving %s at http://%s:%s' % (rootdir, host, port))
httpd.serve_forever()
'''.format(self._http_dir, self._http_host, port, self._package_builder.content_type())

        httpd_py_path = os.path.join(self._http_dir, procname)
        if not os.path.isdir(self._http_dir):
            os.makedirs(self._http_dir)
        httpd_py_file = open(httpd_py_path, 'w+')
        httpd_py_file.write(httpd_py_content)
        httpd_py_file.flush()
        httpd_py_file.close()

        os.chmod(httpd_py_path, 0o744)
        logger.info('Launching HTTPD: {}'.format(httpd_py_path))
        subprocess.Popen([httpd_py_path, "2&1>", "/dev/null"])

        return http_url_root
Exemple #3
0
    def upload(self):
        '''generates a unique directory, then uploads artifacts and a new stub universe to that directory'''
        try:
            universe_path = universe_builder.UniversePackageBuilder(
                self._pkg_name, self._pkg_version,
                self._input_dir_path, self._http_directory, self._artifact_paths).build_zip()
        except Exception as e:
            err = 'Failed to create stub universe: {}'.format(str(e))
            self._github_updater.update('error', err)
            raise

        # print universe url early
        universe_url = self._upload_artifact(universe_path)
        logger.info('---')
        logger.info('Uploading {} artifacts:'.format(len(self._artifact_paths)))

        for path in self._artifact_paths:
            self._upload_artifact(path)

        self._spam_universe_url(universe_url)

        # print to stdout, while the rest is all stderr:
        print(universe_url)

        logger.info('---')
        logger.info('(Re)install your package using the following commands:')
        logger.info('dcos package uninstall {}'.format(self._pkg_name))
        logger.info('dcos node ssh --master-proxy --leader ' +
                    '"docker run mesosphere/janitor /janitor.py -r {0}-role -p {0}-principal -z dcos-service-{0}"'.format(self._pkg_name))
        logger.info('dcos package repo remove {}-azure'.format(self._pkg_name))
        logger.info('dcos package repo add --index=0 {}-azure {}'.format(self._pkg_name, universe_url))
        logger.info('dcos package install --yes {}'.format(self._pkg_name))

        return universe_url
Exemple #4
0
    def upload(self):
        '''generates a unique directory, then uploads artifacts and a new stub universe to that directory'''
        builder = universe_builder.UniversePackageBuilder(
            self._pkg_name, self._pkg_version, self._input_dir_path,
            self._http_directory, self._artifact_paths)
        try:
            universe_path = builder.build_package()
        except Exception as e:
            err = 'Failed to create stub universe: {}'.format(str(e))
            self._github_updater.update('error', err)
            raise

        # upload universe package definition first and get its URL
        universe_url = self._universe_url_prefix + self._upload_artifact(
            universe_path,
            content_type='application/vnd.dcos.universe.repo+json;charset=utf-8'
        )
        logger.info('---')
        logger.info('STUB UNIVERSE: {}'.format(universe_url))
        logger.info('---')
        logger.info('Uploading {} artifacts:'.format(len(
            self._artifact_paths)))

        for path in self._artifact_paths:
            self._upload_artifact(path)

        self._spam_universe_url(universe_url)

        # print to stdout, while the rest is all stderr:
        print(universe_url)

        logger.info('---')
        logger.info('(Re)install your package using the following commands:')
        logger.info('dcos package uninstall {}'.format(self._pkg_name))
        logger.info('\n- - - -\nFor 1.9 or older clusters only')
        logger.info(
            'dcos node ssh --master-proxy --leader ' +
            '"docker run mesosphere/janitor /janitor.py -r {0}-role -p {0}-principal -z dcos-service-{0}"'
            .format(self._pkg_name))
        logger.info('- - - -\n')
        logger.info('dcos package repo remove {}-aws'.format(self._pkg_name))
        logger.info('dcos package repo add --index=0 {}-aws {}'.format(
            self._pkg_name, universe_url))
        logger.info('dcos package install --yes {}'.format(self._pkg_name))

        return universe_url
Exemple #5
0
    def build(self, http_url_root):
        '''copies artifacts and a new stub universe into the http root directory'''
        try:
            universe_path = universe_builder.UniversePackageBuilder(
                self._pkg_name, self._pkg_version, self._input_dir_path,
                http_url_root, self._artifact_paths).build_zip()
        except Exception as e:
            err = 'Failed to create stub universe: {}'.format(str(e))
            self._github_updater.update('error', err)
            raise

        # wipe files in dir
        if not os.path.isdir(self._http_dir):
            os.makedirs(self._http_dir)
        for filename in os.listdir(self._http_dir):
            path = os.path.join(self._http_dir, filename)
            logger.info(
                'Deleting preexisting file in artifact dir: {}'.format(path))
            os.remove(path)

        # print universe url early
        universe_url = self._copy_artifact(http_url_root, universe_path)
        logger.info('---')
        logger.info('Built and copied stub universe:')
        logger.info(universe_url)
        logger.info('---')
        logger.info('Copying {} artifacts into {}:'.format(
            len(self._artifact_paths), self._http_dir))

        for path in self._artifact_paths:
            self._copy_artifact(http_url_root, path)

        self._spam_universe_url(universe_url)

        # print to stdout, while the rest is all stderr:
        print(universe_url)

        return universe_url