'Add a "last-mile" layer of environment config to a Docker image for deis-registry.'

def build(self, source, config, repo, tag):

    check_blacklist(repo)
    env = u'    '.join((u'{}="{}"'.format(k, v.encode(u'unicode-escape').replace(u'"', u'\\"')) for (k, v) in config.viewitems()))
    dockerfile = u'FROM    {}\nENV    {}'.format(source, env)
    f = io.BytesIO(dockerfile.encode(u'utf-8'))
    target_repo = u'{}/{}:{}'.format(self.registry, repo, tag)
    logger.info(u'Building    Docker    image    {}'.format(target_repo))
    with SimpleFlock(self.FLOCKFILE, timeout=1200):
        stream = self.client.build(fileobj=f, tag=target_repo, stream=True, rm=True)
        log_output(stream)
