aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 10.6 kB
JavaScript
;var __runInitializers=exports&&exports.__runInitializers||function(thisArg,initializers,value){for(var useValue=arguments.length>2,i=0;i<initializers.length;i++)value=useValue?initializers[i].call(thisArg,value):initializers[i].call(thisArg);return useValue?value:void 0},__esDecorate=exports&&exports.__esDecorate||function(ctor,descriptorIn,decorators,contextIn,initializers,extraInitializers){function accept(f){if(f!==void 0&&typeof f!="function")throw new TypeError("Function expected");return f}for(var kind=contextIn.kind,key=kind==="getter"?"get":kind==="setter"?"set":"value",target=!descriptorIn&&ctor?contextIn.static?ctor:ctor.prototype:null,descriptor=descriptorIn||(target?Object.getOwnPropertyDescriptor(target,contextIn.name):{}),_,done=!1,i=decorators.length-1;i>=0;i--){var context={};for(var p in contextIn)context[p]=p==="access"?{}:contextIn[p];for(var p in contextIn.access)context.access[p]=contextIn.access[p];context.addInitializer=function(f){if(done)throw new TypeError("Cannot add initializers after decoration has completed");extraInitializers.push(accept(f||null))};var result=(0,decorators[i])(kind==="accessor"?{get:descriptor.get,set:descriptor.set}:descriptor[key],context);if(kind==="accessor"){if(result===void 0)continue;if(result===null||typeof result!="object")throw new TypeError("Object expected");(_=accept(result.get))&&(descriptor.get=_),(_=accept(result.set))&&(descriptor.set=_),(_=accept(result.init))&&initializers.unshift(_)}else(_=accept(result))&&(kind==="field"?initializers.unshift(_):descriptor[key]=_)}target&&Object.defineProperty(target,contextIn.name,descriptor),done=!0};Object.defineProperty(exports,"__esModule",{value:!0}),exports.PERF_BUNDLING_SRC_SYM=exports.DockerVolumeConsistency=exports.DockerImage=exports.BundlingDockerImage=exports.BundlingFileAccess=exports.BundlingOutput=exports.DockerBuildSecret=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var child_process_1=()=>{var tmp=require("child_process");return child_process_1=()=>tmp,tmp},path_1=()=>{var tmp=require("path");return path_1=()=>tmp,tmp},errors_1=()=>{var tmp=require("./errors");return errors_1=()=>tmp,tmp},fs_1=()=>{var tmp=require("./fs");return fs_1=()=>tmp,tmp},asset_staging_1=()=>{var tmp=require("./private/asset-staging");return asset_staging_1=()=>tmp,tmp},jsii_deprecated_1=()=>{var tmp=require("./private/jsii-deprecated");return jsii_deprecated_1=()=>tmp,tmp},literal_string_1=()=>{var tmp=require("./private/literal-string");return literal_string_1=()=>tmp,tmp},perf_1=()=>{var tmp=require("./private/perf");return perf_1=()=>tmp,tmp};class DockerBuildSecret{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.DockerBuildSecret",version:"2.260.0"};static fromSrc(src){return`src=${src}`}}exports.DockerBuildSecret=DockerBuildSecret;var BundlingOutput;(function(BundlingOutput2){BundlingOutput2.ARCHIVED="archived",BundlingOutput2.NOT_ARCHIVED="not-archived",BundlingOutput2.AUTO_DISCOVER="auto-discover",BundlingOutput2.SINGLE_FILE="single-file"})(BundlingOutput||(exports.BundlingOutput=BundlingOutput={}));var BundlingFileAccess;(function(BundlingFileAccess2){BundlingFileAccess2.VOLUME_COPY="VOLUME_COPY",BundlingFileAccess2.BIND_MOUNT="BIND_MOUNT"})(BundlingFileAccess||(exports.BundlingFileAccess=BundlingFileAccess={}));let BundlingDockerImage=(()=>{let _instanceExtraInitializers=[],_run_decorators,_cp_decorators;return class{static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;_run_decorators=[(0,perf_1().profileFn)("BundlingDockerImage.run",{telemetry:!0})],_cp_decorators=[(0,perf_1().profileFn)("BundlingDockerImage.cp",{telemetry:!0})],__esDecorate(this,null,_run_decorators,{kind:"method",name:"run",static:!1,private:!1,access:{has:obj=>"run"in obj,get:obj=>obj.run},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,_cp_decorators,{kind:"method",name:"cp",static:!1,private:!1,access:{has:obj=>"cp"in obj,get:obj=>obj.cp},metadata:_metadata},null,_instanceExtraInitializers),_metadata&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}image=__runInitializers(this,_instanceExtraInitializers);_imageHash;static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.BundlingDockerImage",version:"2.260.0"};static fromRegistry(image){return new DockerImage(image)}static fromAsset(path,options={}){return DockerImage.fromBuild(path,options)}constructor(image,_imageHash){this.image=image,this._imageHash=_imageHash}toJSON(){return this._imageHash??this.image}run(options={}){const volumes=options.volumes||[],environment=options.environment||{},entrypoint=options.entrypoint?.[0]||null,command=[...options.entrypoint?.[1]?[...options.entrypoint.slice(1)]:[],...options.command?[...options.command]:[]],dockerArgs=["run","--rm",...options.securityOpt?["--security-opt",options.securityOpt]:[],...options.network?["--network",options.network]:[],...options.platform?["--platform",options.platform]:[],...options.user?["-u",options.user]:[],...options.volumesFrom?flatten(options.volumesFrom.map(v=>["--volumes-from",v])):[],...flatten(volumes.map(v=>["-v",`${v.hostPath}:${v.containerPath}:${isSeLinux()?"z,":""}${v.consistency??DockerVolumeConsistency.DELEGATED}`])),...flatten(Object.entries(environment).map(([k,v])=>["--env",`${k}=${v}`])),...options.workingDirectory?["-w",options.workingDirectory]:[],...entrypoint?["--entrypoint",entrypoint]:[],this.image,...command];(0,asset_staging_1().dockerExec)(dockerArgs)}cp(imagePath,outputPath){const{stdout}=(0,asset_staging_1().dockerExec)(["create",this.image],{}),match=stdout.toString().match(/([0-9a-f]{16,})/);if(!match)throw new(errors_1()).ExecutionError((0,literal_string_1().lit)`FailedToFailedExtractContainer`,"Failed to extract container ID from Docker create output");const containerId=match[1],containerPath=`${containerId}:${imagePath}`,destPath=outputPath??fs_1().FileSystem.mkdtemp("cdk-docker-cp-");try{return(0,asset_staging_1().dockerExec)(["cp",containerPath,destPath]),destPath}catch(err){throw new(errors_1()).ExecutionError((0,literal_string_1().lit)`FailedToFailedCopyFiles`,`Failed to copy files from ${containerPath} to ${destPath}: ${err}`)}finally{(0,asset_staging_1().dockerExec)(["rm","-v",containerId])}}}})();exports.BundlingDockerImage=BundlingDockerImage;let DockerImage=(()=>{let _classSuper=BundlingDockerImage,_staticExtraInitializers=[],_static_fromBuild_decorators;return class DockerImage2 extends _classSuper{static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;_static_fromBuild_decorators=[(0,perf_1().profileFn)("DockerImage.fromBuild",{telemetry:!0})],__esDecorate(this,null,_static_fromBuild_decorators,{kind:"method",name:"fromBuild",static:!0,private:!1,access:{has:obj=>"fromBuild"in obj,get:obj=>obj.fromBuild},metadata:_metadata},null,_staticExtraInitializers),_metadata&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static[JSII_RTTI_SYMBOL_1]=(__runInitializers(this,_staticExtraInitializers),{fqn:"aws-cdk-lib.DockerImage",version:"2.260.0"});static fromBuild(path,options={}){try{jsiiDeprecationWarnings().aws_cdk_lib_DockerBuildOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromBuild),error}const buildArgs=options.buildArgs||{};if(options.file&&(0,path_1().isAbsolute)(options.file))throw new(errors_1()).UnscopedValidationError((0,literal_string_1().lit)`MustBeFileRelativeDocker`,`"file" must be relative to the docker build directory. Got ${options.file}`);const hash=fs_1().FileSystem.fingerprint(path,{extraHash:JSON.stringify(options)}),tag=`cdk-${hash}`;if(Object.keys(options.buildContexts??{}).length>0||!this.imageAlreadyExists(tag)){const dockerArgs=["build","-t",tag,...options.file?["-f",(0,path_1().join)(path,options.file)]:[],...options.platform?["--platform",options.platform]:[],...options.network?["--network",options.network]:[],...options.targetStage?["--target",options.targetStage]:[],...options.cacheFrom?[...options.cacheFrom.map(cacheFrom=>["--cache-from",this.cacheOptionToFlag(cacheFrom)]).flat()]:[],...options.cacheTo?["--cache-to",this.cacheOptionToFlag(options.cacheTo)]:[],...options.cacheDisabled?["--no-cache"]:[],...flatten(Object.entries(buildArgs).map(([k,v])=>["--build-arg",`${k}=${v}`])),...flatten(Object.entries(options.buildContexts||{}).map(([k,v])=>["--build-context",`${k}=${v}`])),path];(0,asset_staging_1().dockerExec)(dockerArgs)}return new DockerImage2(tag,hash)}static fromRegistry(image){return new DockerImage2(image)}static imageAlreadyExists(tag){const prog=process.env.CDK_DOCKER??"docker";return(0,child_process_1().spawnSync)(prog,["image","inspect",tag],{stdio:"ignore"}).status===0}static cacheOptionToFlag(option){let flag=`type=${option.type}`;return option.params&&(flag+=","+Object.entries(option.params).map(([k,v])=>`${k}=${v}`).join(",")),flag}image;constructor(image,_imageHash){const deprecated=(0,jsii_deprecated_1().quiet)();super(image,_imageHash),(0,jsii_deprecated_1().reset)(deprecated),this.image=image}toJSON(){const deprecated=(0,jsii_deprecated_1().quiet)(),json=super.toJSON();return(0,jsii_deprecated_1().reset)(deprecated),json}run(options={}){try{jsiiDeprecationWarnings().aws_cdk_lib_DockerRunOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.run),error}const deprecated=(0,jsii_deprecated_1().quiet)(),result=super.run(options);return(0,jsii_deprecated_1().reset)(deprecated),result}cp(imagePath,outputPath){const deprecated=(0,jsii_deprecated_1().quiet)(),result=super.cp(imagePath,outputPath);return(0,jsii_deprecated_1().reset)(deprecated),result}}})();exports.DockerImage=DockerImage;var DockerVolumeConsistency;(function(DockerVolumeConsistency2){DockerVolumeConsistency2.CONSISTENT="consistent",DockerVolumeConsistency2.DELEGATED="delegated",DockerVolumeConsistency2.CACHED="cached"})(DockerVolumeConsistency||(exports.DockerVolumeConsistency=DockerVolumeConsistency={}));function flatten(x){return Array.prototype.concat([],...x)}function isSeLinux(){if(process.platform!="linux")return!1;const proc=(0,child_process_1().spawnSync)("selinuxenabled",[],{stdio:["pipe",process.stderr,"inherit"]});return proc.error?!1:proc.status==0}exports.PERF_BUNDLING_SRC_SYM=Symbol.for("@aws-cdk/core.bundlingSource");