Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
- added some checking so that we don't get more than one multipart me…
Browse files Browse the repository at this point in the history
…rge running at the same time. Improved some of the naming.
  • Loading branch information
PhotoNomad0 committed Oct 19, 2017
1 parent 8528938 commit 0b2078e
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions libraries/door43_tools/project_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,18 @@ def deploy_revision_to_door43(self, build_log_key):
s3_repo_key = 'u/{0}/{1}'.format(user, repo_name)
download_key = s3_commit_key

partial = False
multi_merge = False
partial_deploy = False
multipart_merge = False
if 'multiple' in build_log:
multi_merge = build_log['multiple']
multipart_merge = build_log['multiple']
App.logger.debug("found multi-part merge")

prefix = download_key + '/'
undeployed = self.get_undeployed_parts(prefix)
if len(undeployed) > 0:
App.logger.debug("Parts not yet deployed: {0}".format(undeployed))
return False

key_deployed_ = download_key + '/deployed'
if App.cdn_s3_handler().key_exists(key_deployed_):
App.logger.debug("Already merged parts")
Expand All @@ -74,7 +81,7 @@ def deploy_revision_to_door43(self, build_log_key):
elif 'part' in build_log:
part = build_log['part']
download_key += '/' + part
partial = True
partial_deploy = True
App.logger.debug("found partial: " + part)

if not App.cdn_s3_handler().key_exists(download_key + '/finished'):
Expand All @@ -91,21 +98,27 @@ def deploy_revision_to_door43(self, build_log_key):
App.logger.debug("Downloading {0} to {1}...".format(template_key, template_file))
App.door43_s3_handler().download_file(template_key, template_file)

if not multi_merge:
source_dir, success = self.deploy_single_conversion(build_log, download_key, output_dir, repo_name,
if not multipart_merge:
source_dir, success = self.template_converted_files(build_log, download_key, output_dir, repo_name,
resource_type, s3_commit_key, source_dir, start,
template_file)
if not success:
return
else:
# merge multi-part project
source_dir, success = self.deploy_multipart_master(s3_commit_key, resource_type, download_key, output_dir,
source_dir, start, template_file)
source_dir, success = self.multipart_master_merge(s3_commit_key, resource_type, download_key, output_dir,
source_dir, start, template_file)
if not success:
return False

#######################
#
# Now do the deploy
#
#######################

# Copy first HTML file to index.html if index.html doesn't exist
if not partial or multi_merge:
if not partial_deploy or multipart_merge:
html_files = sorted(glob(os.path.join(output_dir, '*.html')))
index_file = os.path.join(output_dir, 'index.html')
if len(html_files) > 0 and not os.path.isfile(index_file):
Expand All @@ -117,7 +130,7 @@ def deploy_revision_to_door43(self, build_log_key):
if not os.path.exists(output_file) and not os.path.isdir(filename):
copyfile(filename, output_file)

if partial: # move files to common area
if partial_deploy: # move files to common area
basename = os.path.basename(filename)
if basename not in ['finished', 'build_log.json', 'index.html', 'merged.json', 'lint_log.json']:
App.logger.debug("Moving {0} to common area".format(basename))
Expand All @@ -138,7 +151,7 @@ def deploy_revision_to_door43(self, build_log_key):
App.logger.debug("Uploading {0} to {1}".format(path, key))
App.door43_s3_handler().upload_file(path, key, cache_time=0)

if not partial:
if not partial_deploy:
# Now we place json files and make an index.html file for the whole repo
try:
App.door43_s3_handler().copy(from_key='{0}/project.json'.format(s3_repo_key), from_bucket=App.cdn_bucket)
Expand All @@ -150,28 +163,23 @@ def deploy_revision_to_door43(self, build_log_key):
except:
pass

else: # if processing part
else: # if processing part of multi-part merge
self.write_data_to_file(output_dir, download_key, 'deployed', ' ') # flag that deploy has finished
if App.cdn_s3_handler().key_exists(s3_commit_key + '/final_build_log.json'):
App.logger.debug("final build detected")
App.logger.debug("conversions all finished, trigger final merge")
App.cdn_s3_handler().copy(from_key=s3_commit_key + '/final_build_log.json',
to_key=s3_commit_key + '/build_log.json')

self.write_data_to_file(output_dir, download_key, 'deployed', ' ') # flag that deploy has finished

elapsed_seconds = int(time.time() - start)
App.logger.debug("deploy type partial={0}, multi_merge={1}".format(partial, multi_merge))
App.logger.debug("deploy type partial={0}, multi_merge={1}".format(partial_deploy, multipart_merge))
App.logger.debug("deploy completed in {0} seconds".format(elapsed_seconds))
self.close()
return True

def deploy_multipart_master(self, s3_commit_key, resource_type, download_key, output_dir, source_dir, start,
template_file):
def multipart_master_merge(self, s3_commit_key, resource_type, download_key, output_dir, source_dir, start,
template_file):
prefix = download_key + '/'
undeployed = self.get_undeployed_parts(prefix)
if len(undeployed) > 0:
App.logger.debug("Parts not deployed: {0}".format(undeployed))

App.door43_s3_handler().download_dir(prefix, source_dir) # get previous templated files
source_dir = os.path.join(source_dir, download_key)
files = sorted(glob(os.path.join(source_dir, '*.*')))
Expand Down Expand Up @@ -214,7 +222,7 @@ def get_undeployed_parts(self, prefix):
unfinished.append(part_num)
return unfinished

def deploy_single_conversion(self, build_log, download_key, output_dir, repo_name, resource_type, s3_commit_key,
def template_converted_files(self, build_log, download_key, output_dir, repo_name, resource_type, s3_commit_key,
source_dir, start, template_file):
App.cdn_s3_handler().download_dir(download_key + '/', source_dir)
source_dir = os.path.join(source_dir, download_key)
Expand Down

0 comments on commit 0b2078e

Please sign in to comment.