2017-11-30 07:20:24 +00:00
|
|
|
"""
|
|
|
|
Generates a variety of Dockerfiles based on an input matrix
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import docker
|
|
|
|
from .base import BuildPack
|
|
|
|
|
|
|
|
|
|
|
|
class DockerBuildPack(BuildPack):
|
|
|
|
name = "Dockerfile"
|
|
|
|
dockerfile = "Dockerfile"
|
|
|
|
|
|
|
|
def detect(self):
|
|
|
|
return os.path.exists(self.binder_path('Dockerfile'))
|
|
|
|
|
|
|
|
def render(self):
|
|
|
|
Dockerfile = self.binder_path('Dockerfile')
|
|
|
|
with open(Dockerfile) as f:
|
|
|
|
return f.read()
|
|
|
|
|
2017-12-01 01:14:42 +00:00
|
|
|
def build(self, image_spec, memory_limit):
|
|
|
|
limits = {
|
|
|
|
# Always disable memory swap for building, since mostly
|
|
|
|
# nothing good can come of that.
|
|
|
|
'memoryswap': -1
|
|
|
|
}
|
|
|
|
if memory_limit:
|
|
|
|
limits['memory'] = memory_limit
|
2017-11-30 07:20:24 +00:00
|
|
|
client = docker.APIClient(version='auto', **docker.utils.kwargs_from_env())
|
|
|
|
for line in client.build(
|
|
|
|
path=os.getcwd(),
|
|
|
|
dockerfile=self.binder_path(self.dockerfile),
|
|
|
|
tag=image_spec,
|
|
|
|
buildargs={},
|
|
|
|
decode=True,
|
|
|
|
forcerm=True,
|
2017-12-01 01:14:42 +00:00
|
|
|
rm=True,
|
|
|
|
container_limits=limits
|
2017-11-30 07:20:24 +00:00
|
|
|
):
|
|
|
|
yield line
|