'Build the docs in an environment.
If `docker` is True, or Docker is enabled by the settings.DOCKER_ENABLE
setting, then build in a Docker environment. Otherwise build locally.'

def run_build(self, docker=False, record=True):

    env_vars = self.get_env_vars()
    if (docker or settings.DOCKER_ENABLE):
        env_cls = DockerEnvironment
    else:
        env_cls = LocalEnvironment
    self.build_env = env_cls(project=self.project, version=self.version, build=self.build, record=record, environment=env_vars)
    with self.build_env:
        if (self.project.documentation_type == 'auto'):
            self.update_documentation_type()
        python_env_cls = Virtualenv
        if self.config.use_conda:
            self._log('Using    conda')
            python_env_cls = Conda
        self.python_env = python_env_cls(version=self.version, build_env=self.build_env, config=self.config)
        try:
            self.setup_environment()
            outcomes = self.build_docs()
            build_id = self.build.get('id')
        except SoftTimeLimitExceeded:
            raise BuildEnvironmentError(_('Build    exited    due    to    time    out'))
        if build_id:
            finish_build.delay(version_pk=self.version.pk, build_pk=build_id, hostname=socket.gethostname(), html=outcomes['html'], search=outcomes['search'], localmedia=outcomes['localmedia'], pdf=outcomes['pdf'], epub=outcomes['epub'])
    if self.build_env.failed:
        self.send_notifications()
    build_complete.send(sender=Build, build=self.build_env.build)
    self.build_env.update_build(state=BUILD_STATE_FINISHED)
