Flesh out the create API and wire everything up together. Next up, testing.
This commit is contained in:
parent
2afb8c85b1
commit
9b9a29c310
10 changed files with 156 additions and 15 deletions
|
@ -3,6 +3,7 @@ import logging
|
|||
import shutil
|
||||
import os
|
||||
import re
|
||||
import requests
|
||||
|
||||
from flask import Flask, request, send_file, jsonify, redirect, url_for, abort
|
||||
from zipfile import ZipFile
|
||||
|
@ -39,7 +40,7 @@ def prepare_zip(request_file):
|
|||
|
||||
# Save the zip file to temp somewhere
|
||||
with TemporaryFile() as zip_file:
|
||||
request_file.save(zip_file)
|
||||
zip_file.write(request_file.content)
|
||||
to_extract = ZipFile(zip_file)
|
||||
to_extract.extractall(build_dir)
|
||||
|
||||
|
@ -49,7 +50,8 @@ def prepare_zip(request_file):
|
|||
def prepare_dockerfile(request_file):
|
||||
build_dir = mkdtemp(prefix='docker-build-')
|
||||
dockerfile_path = os.path.join(build_dir, "Dockerfile")
|
||||
request_file.save(dockerfile_path)
|
||||
with open(dockerfile_path, 'w') as dockerfile:
|
||||
dockerfile.write(request_file.content)
|
||||
|
||||
return build_dir
|
||||
|
||||
|
@ -141,10 +143,12 @@ pool = ThreadPool(1)
|
|||
|
||||
@app.route('/build/', methods=['POST'])
|
||||
def start_build():
|
||||
docker_input = request.files['dockerfile']
|
||||
c_type = docker_input.content_type
|
||||
resource_url = request.values['resource_url']
|
||||
tag_name = request.values['tag']
|
||||
|
||||
download_resource = requests.get(resource_url)
|
||||
download_resource.get()
|
||||
|
||||
logger.info('Request to build file of type: %s with tag: %s' %
|
||||
(c_type, tag_name))
|
||||
|
||||
|
@ -175,7 +179,9 @@ def start_build():
|
|||
pool.apply_async(build_image, [build_dir, tag_name, num_steps,
|
||||
result_object])
|
||||
|
||||
return redirect(url_for('get_status', job_id=job_id))
|
||||
resp = make_response('Created', 201)
|
||||
resp.headers['Location'] = url_for('get_status', job_id=job_id)
|
||||
return resp
|
||||
|
||||
|
||||
@app.route('/build/<job_id>')
|
||||
|
|
Reference in a new issue