From 49cb1e91e0cf01e27843f4c8e22731b7d28c049e Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 9 Jul 2014 20:37:57 +0100 Subject: Switch carton bundling to S3. --- .travis.yml | 7 +++++-- .travis/after_script | 34 +++++++++------------------------- .travis/install | 28 ++++++++++++++++------------ 3 files changed, 30 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index a0421bc95..bad676933 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,11 +11,14 @@ perl: - "5.14" env: - - secure: "lm7DasPP+iHVI3ZIjTX7tQMfiEsGBJGM2HrPO8AByZWJohL2gd024ngevXXkBT0Qln5z+RhGJOd+QWjvKmuhfCBPveL8IX4v0KHUTfxrjBoBSB09cb4UNdExWu7HPO63RsbhpQdaIoIYIpr1eBb9txBCbGD9aYepuqIKIj/QHwM=" + global: + - "S3_BUCKET=fixmystreet-bundle-cache" + - secure: "llgWNfR/8pH0HjYpg+xhVxuqTaLC0GGUugfuINiUap7JxzjCZ2rlryxCXA4BCM8GUHa9wlYKhrKCSx+DM3EHRE0cLei7LNxAK1JSXLj3NihFQhqnq64tjDwGCSA4l7mlqErA7DK4Dpmh+hBp5f680akITAInM92CbwQZxLDYaCU=" + - secure: "qW+WCgAF68itADxcbcq+nCnKx3vf3GX73HMfjfbkFFUsYmIR+ZaJ9yQMnGJwxIpCHTWLAeqyx4KO8N8T3GmNdKYzIMZemOzp4ED29YC31QOQeq1CwNp2hD5sq/o47d2BzXWwMYNvNXfxz1K6r2c6EMPUtu8X3B8ExZq1RzSFdXs=" before_install: - sudo apt-get update -qq - - sudo apt-get install -qq jhead libgmp-dev + - sudo apt-get install -qq jhead libgmp-dev python-boto # A couple of other modules that normally come from packages, but no system stuff here - cpanm -q Locale::gettext Math::BigInt::GMP - sudo locale-gen cy_GB.UTF-8 en_GB.UTF-8 nb_NO.UTF-8 de_CH.UTF-8 sv_SE.UTF-8 diff --git a/.travis/after_script b/.travis/after_script index 469796be9..37fd37eb8 100755 --- a/.travis/after_script +++ b/.travis/after_script @@ -1,20 +1,20 @@ #!/usr/bin/env python import hashlib -import json import os import subprocess import sys import tarfile -sharename = '48rLGpU1' +import boto +from boto.s3.key import Key root = os.path.join(os.path.dirname(__file__), '..') with open(os.path.join(root, 'cpanfile.snapshot')) as cpanfile: hash = hashlib.md5(cpanfile.read()).hexdigest() wanted_filename = 'fixmystreet-local-%s.tgz' % hash -if os.path.exists(wanted_filename): +if os.path.exists(wanted_filename) and os.path.getsize(wanted_filename): print "File was downloaded, no need to upload" sys.exit() @@ -23,27 +23,11 @@ tfile = tarfile.open(wanted_filename, 'w:gz') tfile.add('local') tfile.close() -print "Logging in..." -refreshtoken = os.getenv('TOKEN') -if not refreshtoken: - print " No token available, bailing" - sys.exit() -output = subprocess.check_output([ - 'curl', '-s', '-X', 'POST', '--data', '{"refreshtoken":"%s"}' % refreshtoken, - 'https://open.ge.tt/1/users/login' -]) -output = json.loads(output) -accesstoken = output['accesstoken'] - -print "Creating file..." -output = subprocess.check_output([ - 'curl', '-s', '-X', 'POST', '--data', '{"filename":"%s"}' % wanted_filename, - 'https://open.ge.tt/1/files/%s/create?accesstoken=%s' % (sharename, accesstoken) -]) -output = json.loads(output) -puturl = output['upload']['puturl'] +print "Uploading archive to S3..." +conn = boto.connect_s3() +bucket = conn.get_bucket('fixmystreet-bundle-cache') +key = Key(bucket) +key.key = wanted_filename +key.set_contents_from_filename(wanted_filename) -print "Uploading archive to ge.tt..." -with open('output', 'w') as out: - subprocess.call([ 'curl', '-#', '--upload-file', wanted_filename, puturl ], stdout=out) print "Completed" diff --git a/.travis/install b/.travis/install index 126d641a1..8514e801d 100755 --- a/.travis/install +++ b/.travis/install @@ -1,28 +1,32 @@ #!/usr/bin/env python import hashlib -import json import os import sys import tarfile -import urllib -sharename = '48rLGpU1' +import boto +from boto.s3.key import Key +from boto.exception import S3ResponseError root = os.path.join(os.path.dirname(__file__), '..') with open(os.path.join(root, 'cpanfile.snapshot')) as cpanfile: hash = hashlib.md5(cpanfile.read()).hexdigest() wanted_filename = 'fixmystreet-local-%s.tgz' % hash -share = json.loads( urllib.urlopen( 'https://open.ge.tt/1/shares/%s' % sharename ).read() ) -for file in share['files']: - if file['filename'] == wanted_filename and file['readystate'] == 'uploaded': - print "Found cached copy of local, using..." - urllib.urlretrieve('https://open.ge.tt/1/files/%s/%s/blob' % (sharename, file['fileid']), wanted_filename) - if tarfile.is_tarfile(wanted_filename): - tfile = tarfile.open(wanted_filename) - tfile.extractall() - sys.exit(0) +conn = boto.connect_s3() +bucket = conn.get_bucket('fixmystreet-bundle-cache') + +k = Key(bucket) +k.key = wanted_filename +try: + k.get_contents_to_filename(wanted_filename) + if tarfile.is_tarfile(wanted_filename): + tfile = tarfile.open(wanted_filename) + tfile.extractall() + sys.exit(0) +except S3ResponseError: + os.remove(wanted_filename) print "No cached copy found, running carton install..." os.system('cpanm -q Carton') -- cgit v1.2.3