def create_image(): if 'file' not in request.files: abort(400) file = request.files['file'] if file.filename == '': abort(400) if file and allowed_file(file.filename): try: filename = secure_filename(file.filename) filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename) filetype = filename.split(".")[-1] file.save(filepath) image = Image(filepath, filename, filetype) image.insert() return jsonify({ 'success': True, 'image': image.format() }) except BaseException: abort(422)
def get_file(): logging.info('get file') user = ctx.request.user if not user: raise APIError('Authencation:fail','token','token is wrong','-1') i = ctx.request.input(filetype='.jpg') logging.info('the file is %s'% (i.file)) if not isinstance(i.file, MultipartFile): raise APIError('IO:error','file','read the file error','-1') logging.info('the token is %s' % i.token) file_name = next_id()+'.'+i.filetype file_path = os.path.join(image_path, file_name) logging.info('the out file is %s' % file_path) fw = open(file_path, 'wb') buf = i.file.file.readline() while buf != '': fw.write(buf) buf = i.file.file.readline() fw.close() image = Image(image_path=image_path_relative+file_name,user_id=user.id) image.insert() image.pop('image_path') image.errcode='0' return image
def push(): image_args = { 'image_name': request.form.get('image_name'), 'pull_address': request.form.get('pull_address'), 'image_tag': request.form.get('image_tag'), 'git_branch': request.form.get('git_branch'), 'git_message': request.form.get('git_message'), 'code_registry': request.form.get('code_registry'), 'host': request.form.get('host'), 'port': request.form.get('port'), 'command': re.sub(r'(-[vpe])', r'\\\n\1', request.form.get('command')), 'dockerfile': request.form.get('dockerfile') } try: Image.insert(image_args) if image_args.get('git_branch') == 'master': project = Project.where('image_name', image_args.get('image_name')).first() if project: project.new_tag = image_args.get('image_tag') project.save() else: deploy_image(image_args.get('image_tag')) except QueryException as e: return make_response(e.message, status_code=500) return make_response()