blob: 39d8a2be37c607184843af3141df5773da530615 [file] [log] [blame]
schillinge2f5e85e2019-03-03 19:17:23 +01001import logging
2from io import BytesIO
3
4import docker
5
6from emuvim.api.util.path_utils import get_absolute_path
7
8
9def build_dockerfile_dir(folder, tag):
10 dcli = docker.from_env().api
11 folder = get_absolute_path(folder)
12 build_stream = dcli.build(folder, tag=tag)
13 logging.info('Docker build result:')
14 for line in build_stream:
15 logging.info(line)
16
17
18def suffix_tag_name(tag, suffix):
19 if ":" in tag:
20 return "%s_%s" % (tag, suffix)
21 return "%s:latest_%s" % (tag, suffix)
22
23
24def wrap_debian_like(image):
25 dcli = docker.from_env().api
26 dockerfile = '''
27 FROM %s
28 RUN apt update -y && apt install -y net-tools iputils-ping iproute
29 ''' % image
30 f = BytesIO(dockerfile.encode('utf-8'))
31 wrapper_name = suffix_tag_name(image, 'containernet_compatible')
32 logging.info('wrapping image: %s->%s' % (image, wrapper_name))
33 build_stream = dcli.build(fileobj=f, tag=wrapper_name)
34 build_result = [line for line in build_stream]
35 logging.debug('Docker build result:' + '\n'.join(build_result))
36 return wrapper_name
37
38
39# 172.17.0.1 is the ip of the docker0 interface on the host
40DOCKER_HOST_IP = '172.17.0.1'