Add tarball support to the builder and pull github code as a tarball.

This commit is contained in:
jakedt 2014-03-31 15:40:24 -04:00
parent 00ac3fb639
commit e7c20e1052
2 changed files with 28 additions and 13 deletions

View file

@ -6,6 +6,7 @@ import requests
import re
import json
import shutil
import tarfile
from docker import Client, APIError
from tempfile import TemporaryFile, mkdtemp
@ -290,6 +291,8 @@ class DockerfileBuildWorker(Worker):
'application/x-zip-compressed': DockerfileBuildWorker.__prepare_zip,
'text/plain': DockerfileBuildWorker.__prepare_dockerfile,
'application/octet-stream': DockerfileBuildWorker.__prepare_dockerfile,
'application/x-tar': DockerfileBuildWorker.__prepare_tarball,
'application/gzip': DockerfileBuildWorker.__prepare_tarball,
}
@staticmethod
@ -298,7 +301,7 @@ class DockerfileBuildWorker(Worker):
# Save the zip file to temp somewhere
with TemporaryFile() as zip_file:
zip_file.write(request_file.content)
zip_file.write(request_file.raw)
to_extract = ZipFile(zip_file)
to_extract.extractall(build_dir)
@ -313,6 +316,16 @@ class DockerfileBuildWorker(Worker):
return build_dir
@staticmethod
def __prepare_tarball(request_file):
build_dir = mkdtemp(prefix='docker-build-')
# Save the zip file to temp somewhere
with tarfile.open(mode='r|*', fileobj=request_file.raw) as tar_stream:
tar_stream.extractall(build_dir)
return build_dir
def process_queue_item(self, job_details):
repository_build = model.get_repository_build(job_details['namespace'],
job_details['repository'],
@ -336,7 +349,7 @@ class DockerfileBuildWorker(Worker):
repo))
log_appender(start_msg)
docker_resource = requests.get(resource_url)
docker_resource = requests.get(resource_url, stream=True)
c_type = docker_resource.headers['content-type']
filetype_msg = ('Request to build type: %s with repo: %s and tags: %s' %