Update the buildserver to use the new post format.
This commit is contained in:
parent
684ce83058
commit
c5ff08e57d
5 changed files with 34 additions and 25 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
flask
|
||||
requests
|
||||
-e git+git://github.com/DevTable/docker-py.git#egg=docker-py
|
5
buildserver/requirements.txt
Normal file
5
buildserver/requirements.txt
Normal file
|
@ -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
|
|
@ -1,9 +0,0 @@
|
|||
<html>
|
||||
<body>
|
||||
<form enctype='multipart/form-data' method="post" action="/build/">
|
||||
<input type="file" name="dockerfile">
|
||||
<input type="text" name="tag">
|
||||
<button type="submit">Send</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Reference in a new issue