コード例 #1
0
def test_pushd(tmpdir):
    """Verify pushd acts like pushd in the shell"""
    original_cwd = os.getcwd()
    path = tmpdir.mkdir('pushd').dirname
    with util.pushd(path):
        assert os.getcwd() == path  # We should have moved to dir
    assert os.getcwd() == original_cwd  # Now back to the original
コード例 #2
0
ファイル: buildah.py プロジェクト: ashcrow/system-buildah
    def build(self, namespace, tag):
        """
        Builds a specific image.

        :param namespace: namespace passed in via cli.
        :type namespace: argparse.namespace
        :param tag: The tag to use when building.
        :type tag: str
        :raises: subprocess.CalledProcessError
        """
        logging.debug('buildah build will be used')
        command = ['buildah', 'bud', '-t', tag, '.']
        with util.pushd(namespace.path):
            subprocess.check_call(command)
コード例 #3
0
    def build(self, namespace, tag):
        """
        Builds a specific image.

        :param namespace: namespace passed in via cli.
        :type namespace: argparse.namespace
        :param tag: The tag to use when building.
        :type tag: str
        :raises: subprocess.CalledProcessError
        """
        logging.debug('moby build will be used')
        command = self._additional_switches(
            namespace, ['docker', 'build', '-t', tag, '.'])

        with util.pushd(namespace.path):
            logging.info('Executing "%s"', ' '.join(command))
            subprocess.check_call(command)
コード例 #4
0
    def __call__(self, parser, namespace, values, dest, option_string=None):
        """
        Execution of the action.

        :name parser: The argument parser in use.
        :type parser: argparse.ArgumentParser
        :name namespace: The namespace for parsed args.
        :type namespace: argparse.Namespace
        :name values: Values for the action.
        :type values: mixed
        :name option_string: Option string.
        :type option_string: str or None
        :raises: subprocess.CalledProcessError
        """
        path = namespace.path
        tag = values
        command = ['docker', 'build', '-t', tag, '.']

        if namespace.host:
            command.insert(1, '--host={}'.format(namespace.host))
        if namespace.tlsverify:
            command.insert(1, '--tlsverify')
        with util.pushd(path):
            subprocess.check_call(command)
コード例 #5
0
    def __call__(self, parser, namespace, values, dest, option_string=None):
        """
        Execution of the action.

        :name parser: The argument parser in use.
        :type parser: argparse.ArgumentParser
        :name namespace: The namespace for parsed args.
        :type namespace: argparse.Namespace
        :name values: Values for the action.
        :type values: mixed
        :name option_string: Option string.
        :type option_string: str or None
        :raises: subprocess.CalledProcessError
        """
        output = util.mkdir(values)
        manifest_struct = {
            "version": "1.0",
            "defaultValues": {},
        }
        for item in namespace.default:
            try:
                k, v = item.split('=')
                manifest_struct['defaultValues'][k] = v
            except ValueError as error:
                parser._print_message(
                    '{} not in a=b format. Skipping...'.format(item))

        # Generate the manifest.json
        manifest_out = os.path.sep.join([output, 'manifest.json'])
        with open(manifest_out, 'w') as manifest:
            json.dump(manifest_struct, manifest, indent='    ')

        # Generate the service.template
        service_out = os.path.sep.join([output, 'service.template'])
        with open(service_out, 'w') as service:
            loader = jinja2.PackageLoader('system_buildah')
            rendered = loader.load(jinja2.Environment(),
                                   'service.template.j2').render(
                                       description=namespace.description)
            service.write(rendered)

        # Generate config.json using ocitools
        temp_dir = tempfile.mkdtemp()
        with util.pushd(temp_dir):
            try:
                ocitools_cmd = ['ocitools', 'generate', "--read-only"]
                for item in namespace.config.split(' '):
                    try:
                        ocitools_cmd = ocitools_cmd + item.split('=')
                    except ValueError as error:
                        parser._print_message(
                            '{} not in a=b format. Skipping...'.format(item))
                subprocess.check_call(ocitools_cmd)
                config_out = os.path.sep.join([output, 'config.json.template'])
                try:
                    with open('config.json', 'r') as config_file:
                        configuration = json.load(config_file)
                        configuration['process']['terminal'] = False
                    with open(config_out, 'w') as dest:
                        json.dump(configuration,
                                  dest,
                                  indent=8,
                                  sort_keys=True)
                finally:
                    os.unlink('config.json')
            finally:
                shutil.rmtree(temp_dir)