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

@ -1,7 +1,7 @@
import logging
import io
import os.path
import zipfile
import tarfile
from github import Github, UnknownObjectException, GithubException
from tempfile import SpooledTemporaryFile
@ -16,7 +16,7 @@ client = app.config['HTTPCLIENT']
logger = logging.getLogger(__name__)
ZIPBALL = 'application/zip'
TARBALL_MIME = 'application/gzip'
CHUNK_SIZE = 512 * 1024
@ -222,19 +222,22 @@ class GithubBuildTrigger(BuildTrigger):
@staticmethod
def _prepare_build(config, repo, commit_sha, build_name, ref):
# Prepare the download and upload URLs
archive_link = repo.get_archive_link('zipball', commit_sha)
archive_link = repo.get_archive_link('tarball', commit_sha)
download_archive = client.get(archive_link, stream=True)
zipball_subdir = ''
with SpooledTemporaryFile(CHUNK_SIZE) as zipball:
tarball_subdir = ''
with SpooledTemporaryFile(CHUNK_SIZE) as tarball:
for chunk in download_archive.iter_content(CHUNK_SIZE):
zipball.write(chunk)
tarball.write(chunk)
# Seek to position 0 to make tarfile happy
tarball.seek(0)
# Pull out the name of the subdir that GitHub generated
with zipfile.ZipFile(zipball) as archive:
zipball_subdir = archive.namelist()[0]
with tarfile.open(fileobj=tarball) as archive:
tarball_subdir = archive.getnames()[0]
dockerfile_id = user_files.store_file(zipball, ZIPBALL)
dockerfile_id = user_files.store_file(tarball, TARBALL_MIME)
logger.debug('Successfully prepared job')
@ -247,7 +250,7 @@ class GithubBuildTrigger(BuildTrigger):
# compute the subdir
repo_subdir = config['subdir']
joined_subdir = os.path.join(zipball_subdir, repo_subdir)
joined_subdir = os.path.join(tarball_subdir, repo_subdir)
logger.debug('Final subdir: %s' % joined_subdir)
return dockerfile_id, list(tags), build_name, joined_subdir
@ -280,7 +283,6 @@ class GithubBuildTrigger(BuildTrigger):
def manual_start(self, auth_token, config):
source = config['build_source']
subdir = config['subdir']
gh_client = self._get_client(auth_token)
repo = gh_client.get_repo(source)