Exemplo n.º 1
0
    def push(self, destination):
        """Push an image to a container registry.

        :params destination: URL to used to push the container. It contains
            the registry address, namespace, base, img_type (optional),
            container name and tag.
        """
        # TODO(emilien): Stop ignoring TLS. The deployer should either secure
        # the registry or add it to insecure_registries.
        # TODO(emilien) We need to figure out how we can push to something
        # else than a Docker registry.
        args = self.buildah_cmd + [
            'push', '--tls-verify=False', destination,
            'docker://' + destination
        ]
        self.log.info("Pushing %s image with: %s" %
                      (destination, ' '.join(args)))
        if self.debug:
            # buildah push logs to stderr, since there is no --log* opt
            # so we'll use the current logging context for that
            process.execute(*args,
                            log_stdout=True,
                            run_as_root=False,
                            use_standard_locale=True,
                            logger=self.log,
                            loglevel=logging.DEBUG)
        else:
            process.execute(*args, run_as_root=False, use_standard_locale=True)
Exemplo n.º 2
0
 def test_execute_use_standard_locale_with_env_variables(self,
                                                         execute_mock):
     process.execute('foo', use_standard_locale=True,
                     env_variables={'foo': 'bar'})
     execute_mock.assert_called_once_with('foo',
                                          env_variables={'LC_ALL': 'C',
                                                         'foo': 'bar'})
Exemplo n.º 3
0
    def build(self, container_name, container_build_path):
        """Build an image from a given directory.

        :params container_name: Name of the container.
        :params container_build_path: Directory where the Dockerfile and other
            files are located to build the image.
        """

        destination = "{}/{}/{}-{}-{}:{}".format(self.registry_address,
                                                 self.namespace, self.base,
                                                 self.img_type, container_name,
                                                 self.tag)
        # 'buildah bud' is the command we want because Kolla uses Dockefile to
        # build images.
        # TODO(emilien): Stop ignoring TLS. The deployer should either secure
        # the registry or add it to insecure_registries.
        logfile = container_build_path + '/' + container_name + '-build.log'
        # TODO(aschultz): drop --format docker when oci format is properly
        # supported by the undercloud registry
        args = self.buildah_cmd + [
            'bud', '--format', 'docker', '--tls-verify=False', '--logfile',
            logfile, '-t', destination, container_build_path
        ]
        print("Building %s image with: %s" % (container_name, ' '.join(args)))
        process.execute(*args,
                        check_exit_code=True,
                        run_as_root=False,
                        use_standard_locale=True)
Exemplo n.º 4
0
 def test_execute_use_standard_locale_with_env_variables(self,
                                                         execute_mock):
     process.execute('foo', use_standard_locale=True,
                     env_variables={'foo': 'bar'})
     execute_mock.assert_called_once_with('foo',
                                          env_variables={'LC_ALL': 'C',
                                                         'foo': 'bar'})
Exemplo n.º 5
0
    def build(self, container_name, container_build_path):
        """Build an image from a given directory.

        :params container_name: Name of the container.
        :params container_build_path: Directory where the Dockerfile and other
            files are located to build the image.
        """

        destination = "{}/{}/{}-{}-{}:{}".format(
            self.registry_address,
            self.namespace,
            self.base,
            self.img_type,
            container_name,
            self.tag
        )
        # 'buildah bud' is the command we want because Kolla uses Dockefile to
        # build images.
        # TODO(emilien): Stop ignoring TLS. The deployer should either secure
        # the registry or add it to insecure_registries.
        logfile = container_build_path + '/' + container_name + '-build.log'
        args = self.buildah_cmd + ['bud', '--tls-verify=False', '--logfile',
                                   logfile, '-t', destination,
                                   container_build_path]
        print("Building %s image with: %s" % (container_name, ' '.join(args)))
        process.execute(*args, run_as_root=False, use_standard_locale=True)
Exemplo n.º 6
0
    def push(self, destination):
        """Push an image to a container registry.

        :params destination: URL to used to push the container. It contains
            the registry address, namespace, base, img_type, container name
            and tag.
        """
        # TODO(emilien): Stop ignoring TLS. The deployer should either secure
        # the registry or add it to insecure_registries.
        # TODO(emilien) We need to figure out how we can push to something
        # else than a Docker registry.
        args = self.buildah_cmd + ['push', '--tls-verify=False', destination,
                                   'docker://' + destination]
        print("Pushing %s image with: %s" % (destination, ' '.join(args)))
        process.execute(*args, run_as_root=False, use_standard_locale=True)
Exemplo n.º 7
0
 def _test_execute_with_log_stdout(self, log_mock, log_stdout=None):
     with mock.patch.object(
             processutils, 'execute', autospec=True) as execute_mock:
         execute_mock.return_value = ('stdout', 'stderr')
         if log_stdout is not None:
             process.execute('foo', log_stdout=log_stdout)
         else:
             process.execute('foo')
         execute_mock.assert_called_once_with('foo')
         name, args, kwargs = log_mock.debug.mock_calls[1]
         if log_stdout is False:
             self.assertEqual(2, log_mock.debug.call_count)
             self.assertNotIn('stdout', args[0])
         else:
             self.assertEqual(3, log_mock.debug.call_count)
             self.assertIn('stdout', args[0])
Exemplo n.º 8
0
 def _test_execute_with_log_stdout(self, log_mock, log_stdout=None):
     with mock.patch.object(
             processutils, 'execute', autospec=True) as execute_mock:
         execute_mock.return_value = ('stdout', 'stderr')
         if log_stdout is not None:
             process.execute('foo', log_stdout=log_stdout)
         else:
             process.execute('foo')
         execute_mock.assert_called_once_with('foo')
         name, args, kwargs = log_mock.debug.mock_calls[1]
         if log_stdout is False:
             self.assertEqual(2, log_mock.debug.call_count)
             self.assertNotIn('stdout', args[0])
         else:
             self.assertEqual(3, log_mock.debug.call_count)
             self.assertIn('stdout', args[0])
Exemplo n.º 9
0
    def push(self, destination):
        """Push an image to a container registry.

        :params destination: URL to used to push the container. It contains
            the registry address, namespace, base, img_type, container name
            and tag.
        """
        # TODO(emilien): Stop ignoring TLS. The deployer should either secure
        # the registry or add it to insecure_registries.
        # TODO(emilien) We need to figure out how we can push to something
        # else than a Docker registry.
        args = self.buildah_cmd + [
            'push', '--tls-verify=False', destination,
            'docker://' + destination
        ]
        print("Pushing %s image with: %s" % (destination, ' '.join(args)))
        process.execute(*args, run_as_root=False, use_standard_locale=True)
Exemplo n.º 10
0
    def build(self, container_name, container_build_path):
        """Build an image from a given directory.

        :params container_name: Name of the container.
        :params container_build_path: Directory where the Dockerfile or
            Containerfile and other files are located to build the image.
        """

        # 'buildah bud' is the command we want because Kolla uses Dockefile to
        # build images.
        # TODO(emilien): Stop ignoring TLS. The deployer should either secure
        # the registry or add it to insecure_registries.
        logfile = container_build_path + '/' + container_name + '-build.log'

        # TODO(ramishra) Hack to make the logfile readable by current user,
        # as we're running buildah as root. This would be removed once we
        # move to rootless buildah.
        pathlib.Path(logfile).touch()

        bud_args = ['bud']
        for v in self.volumes:
            bud_args.extend(['--volume', v])
        if self.debug:
            # TODO(bogdando): add --log-rusage for newer buildah
            bud_args.extend(['--loglevel=3'])
        # TODO(aschultz): drop --format docker when oci format is properly
        # supported by the undercloud registry
        bud_args.extend([
            '--format', 'docker', '--tls-verify=False', '--logfile', logfile,
            '-t',
            self._get_destination(container_name), container_build_path
        ])
        args = self.buildah_cmd + bud_args
        self.log.info("Building %s image with: %s" %
                      (container_name, ' '.join(args)))
        process.execute(*args,
                        check_exit_code=True,
                        run_as_root=False,
                        use_standard_locale=True)
Exemplo n.º 11
0
 def test_execute_not_use_standard_locale(self, execute_mock):
     process.execute('foo', use_standard_locale=False,
                     env_variables={'foo': 'bar'})
     execute_mock.assert_called_once_with('foo',
                                          env_variables={'foo': 'bar'})
Exemplo n.º 12
0
 def test_execute_not_use_standard_locale(self, execute_mock):
     process.execute('foo', use_standard_locale=False,
                     env_variables={'foo': 'bar'})
     execute_mock.assert_called_once_with('foo',
                                          env_variables={'foo': 'bar'})