Update the buildserver to use the new post format.

This commit is contained in:
yackob03 2013-10-25 18:14:35 -04:00
parent 684ce83058
commit c5ff08e57d
5 changed files with 34 additions and 25 deletions

View file

@ -4,12 +4,14 @@ import shutil
import os
import re
import requests
import json
from flask import Flask, request, send_file, jsonify, redirect, url_for, abort
from flask import Flask, request, jsonify, url_for, abort, make_response
from zipfile import ZipFile
from tempfile import TemporaryFile, mkdtemp
from uuid import uuid4
from multiprocessing.pool import ThreadPool
from base64 import b64encode
BUFFER_SIZE = 8 * 1024
@ -20,11 +22,6 @@ app = Flask(__name__)
logger = logging.getLogger(__name__)
@app.route('/')
def index():
return send_file('test.html')
def count_steps(dockerfile_path):
with open(dockerfile_path, 'r') as dockerfileobj:
steps = 0
@ -58,7 +55,7 @@ def prepare_dockerfile(request_file):
def build_image(build_dir, tag_name, num_steps, result_object):
try:
logger.debug('Does this show up?')
logger.debug('Starting build.')
docker_cl = docker.Client(version='1.5')
result_object['status'] = 'building'
build_status = docker_cl.build(path=build_dir, tag=tag_name)
@ -145,9 +142,29 @@ pool = ThreadPool(1)
def start_build():
resource_url = request.values['resource_url']
tag_name = request.values['tag']
acccess_token = request.values['token']
download_resource = requests.get(resource_url)
download_resource.get()
# Save the token
host = re.match(r'([a-z0-9.:]+)/.+/.+$', tag_name)
if host:
docker_endpoint = 'http://%s/v1/' % host.group(0)
dockercfg_path = os.path.join(os.environ.get('HOME', '.'), '.dockercfg')
token = b64encode('$token:%s' % acccess_token)
with open(dockercfg_path, 'w') as dockercfg:
payload = {
docker_endpoint: {
'auth': token,
'email': '',
}
}
dockercfg.write(json.dumps(payload))
else:
logger.warning('Invalid tag name: %s' % tag_name)
abort(400)
docker_resource = requests.get(resource_url)
c_type = docker_resource.headers['content-type']
logger.info('Request to build file of type: %s with tag: %s' %
(c_type, tag_name))
@ -156,7 +173,7 @@ def start_build():
logger.error('Invalid dockerfile content type: %s' % c_type)
abort(400)
build_dir = MIME_PROCESSORS[c_type](docker_input)
build_dir = MIME_PROCESSORS[c_type](docker_resource)
dockerfile_path = os.path.join(build_dir, "Dockerfile")
num_steps = count_steps(dockerfile_path)