WIP: Get everything working except logging and job completion
This commit is contained in:
parent
eacf3f01d2
commit
f93c0a46e8
6 changed files with 120 additions and 52 deletions
|
@ -1,10 +1,11 @@
|
|||
import tarfile
|
||||
import requests
|
||||
import os
|
||||
|
||||
from tempfile import TemporaryFile, mkdtemp
|
||||
from zipfile import ZipFile
|
||||
from util.dockerfileparse import parse_dockerfile, ParsedDockerfile
|
||||
|
||||
|
||||
class BuildPackageException(Exception):
|
||||
""" Exception raised when retrieving or parsing a build package. """
|
||||
pass
|
||||
|
@ -15,16 +16,16 @@ class BuildPackage(object):
|
|||
|
||||
def __init__(self, requests_file):
|
||||
self._mime_processors = {
|
||||
'application/zip': BuildPack.__prepare_zip,
|
||||
'application/x-zip-compressed': BuildPack.__prepare_zip,
|
||||
'text/plain': BuildPack.__prepare_dockerfile,
|
||||
'application/octet-stream': BuildPack.__prepare_dockerfile,
|
||||
'application/x-tar': BuildPack.__prepare_tarball,
|
||||
'application/gzip': BuildPack.__prepare_tarball,
|
||||
'application/x-gzip': BuildPack.__prepare_tarball,
|
||||
'application/zip': BuildPackage.__prepare_zip,
|
||||
'application/x-zip-compressed': BuildPackage.__prepare_zip,
|
||||
'text/plain': BuildPackage.__prepare_dockerfile,
|
||||
'application/octet-stream': BuildPackage.__prepare_dockerfile,
|
||||
'application/x-tar': BuildPackage.__prepare_tarball,
|
||||
'application/gzip': BuildPackage.__prepare_tarball,
|
||||
'application/x-gzip': BuildPackage.__prepare_tarball,
|
||||
}
|
||||
|
||||
c_type = buildpack_resource.headers['content-type']
|
||||
c_type = requests_file.headers['content-type']
|
||||
c_type = c_type.split(';')[0] if ';' in c_type else c_type
|
||||
|
||||
if c_type not in self._mime_processors:
|
||||
|
@ -36,7 +37,7 @@ class BuildPackage(object):
|
|||
except Exception as ex:
|
||||
raise BuildPackageException(ex.message)
|
||||
|
||||
def parse_dockerfile(self, build_subdirectory):
|
||||
def parse_dockerfile(self, subdirectory):
|
||||
dockerfile_path = os.path.join(self._package_directory, subdirectory, 'Dockerfile')
|
||||
if not os.path.exists(dockerfile_path):
|
||||
if subdirectory:
|
||||
|
@ -49,10 +50,10 @@ class BuildPackage(object):
|
|||
with open(dockerfile_path, 'r') as dockerfileobj:
|
||||
return parse_dockerfile(dockerfileobj.read())
|
||||
|
||||
@classmethod
|
||||
@staticmethod
|
||||
def from_url(url):
|
||||
buildpack_resource = requests.get(buildpack_url, stream=True)
|
||||
return BuildPackage(buildpack_resource, c_type)
|
||||
buildpack_resource = requests.get(url, stream=True)
|
||||
return BuildPackage(buildpack_resource)
|
||||
|
||||
@staticmethod
|
||||
def __prepare_zip(request_file):
|
||||
|
|
Reference in a new issue