def make_docker_compose(app_path,database,tools): ''' Tao docker compose voi cac service di kem :param app_path: :param database: :param tools: :return: duong dan docker compose ''' dir_path = os.path.dirname(os.path.abspath(__file__)) compose_path = dir_path+'/'+app_path+'/docker-compose.yml' app_port = str(Docker_Utils.get_available_port(type='app'))+':80' temp = '' if database != "": Service_Template.CO_APP_LINK_X = Service_Template.CO_APP_LINK Service_Template.CO_APP_LINK_X += Service_Template.CO_APP_LINK_MYSQL database_port = Docker_Utils.get_available_port(type='database') template = Service_Template.DATABASE_SERVICE[str(database).upper()].replace('X_NAME', 'database')\ .replace('X_PORT',str(database_port)+':3306') temp = '\n'+template data = Service_Template.CO_APP_TEMPL.replace('X_PORT',app_port) + temp if tools != "": data + Service_Template.TOOL_SERVICE[str(tools).upper()] if Utils.write_new_file(compose_path,data): return compose_path return ""
def run_app_v2(json_data): ''' :param json_data: :return: ''' # Make dockerfile docker_file_path = make_docker_file(json_data['app_name'],json_data['git_source_code'],json_data['programming_base']) # Build image response = [line for line in Docker_Utils.build_docker_file(get_current_dir()+'/'+json_data['app_name'], json_data['app_name']+'_'+json_data['version'])] # run_script = 'docker build -f \''+docker_file_path+'\' -t \''+(json_data['app_name']+'_'+json_data['version'])+'\'' # if os.system(run_script) != 0: # return app_image = json_data['app_name']+'_'+json_data['version'] if docker_file_path!="": # Deploy by marathon marathon_deploy_app(make_json_define_app('web_app', {'image': app_image, 'app_name': json_data['app_name']})) if 'tools' in json_data: marathon_deploy_app(make_json_define_app('tools', {'image': json_data['tools'], 'app_name': json_data['app_name']})) if 'database' in json_data: marathon_deploy_app(make_json_define_app('database', {'image': json_data['database'], 'app_name': json_data['app_name']})) return [True, docker_file_path]