From c5ff08e57d41c122fc80da95616f9b3af0bf68c3 Mon Sep 17 00:00:00 2001 From: yackob03 Date: Fri, 25 Oct 2013 18:14:35 -0400 Subject: [PATCH] Update the buildserver to use the new post format. --- buildserver/Dockerfile | 5 ++-- buildserver/buildserver.py | 37 ++++++++++++++++++++++-------- buildserver/requirements-nover.txt | 3 --- buildserver/requirements.txt | 5 ++++ buildserver/test.html | 9 -------- 5 files changed, 34 insertions(+), 25 deletions(-) delete mode 100644 buildserver/requirements-nover.txt create mode 100644 buildserver/requirements.txt delete mode 100644 buildserver/test.html diff --git a/buildserver/Dockerfile b/buildserver/Dockerfile index c58e9f0ad..eb69c1eb2 100644 --- a/buildserver/Dockerfile +++ b/buildserver/Dockerfile @@ -13,13 +13,12 @@ ADD https://get.docker.io/builds/Linux/x86_64/docker-latest /usr/local/bin/docke # Install the files ADD ./startserver /usr/local/bin/startserver ADD ./buildserver.py ./buildserver.py -ADD ./test.html ./test.html -ADD ./requirements-nover.txt ./requirements-nover.txt +ADD ./requirements.txt ./requirements.txt RUN chmod +x /usr/local/bin/docker /usr/local/bin/startserver RUN virtualenv --distribute venv -RUN venv/bin/pip install -r requirements-nover.txt +RUN venv/bin/pip install -r requirements.txt VOLUME /var/lib/docker diff --git a/buildserver/buildserver.py b/buildserver/buildserver.py index 1f5c7f0d8..5e65a2392 100644 --- a/buildserver/buildserver.py +++ b/buildserver/buildserver.py @@ -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) diff --git a/buildserver/requirements-nover.txt b/buildserver/requirements-nover.txt deleted file mode 100644 index 0aba1d6c9..000000000 --- a/buildserver/requirements-nover.txt +++ /dev/null @@ -1,3 +0,0 @@ -flask -requests --e git+git://github.com/DevTable/docker-py.git#egg=docker-py diff --git a/buildserver/requirements.txt b/buildserver/requirements.txt new file mode 100644 index 000000000..3093eeb14 --- /dev/null +++ b/buildserver/requirements.txt @@ -0,0 +1,5 @@ +mock==1.0.1 +requests==1.2.3 +six==1.3.0 +flask==0.10.1 +-e git+git://github.com/DevTable/docker-py.git#egg=docker-py \ No newline at end of file diff --git a/buildserver/test.html b/buildserver/test.html deleted file mode 100644 index 9a08eb994..000000000 --- a/buildserver/test.html +++ /dev/null @@ -1,9 +0,0 @@ - - -
- - - -
- - \ No newline at end of file