public addDockerImageAsset()

in src/index.ts [255:300]


  public addDockerImageAsset(asset: DockerImageAssetSource): DockerImageAssetLocation {
    assertNotNull(this.stack, ERR_MSG_CALL_BIND_FIRST);
    assertNotNull(this.repositoryName, 'The repositoryName is null');
    validateDockerImageAssetSource(asset);

    const imageTag = this.imageAssetTagPrefix + asset.sourceHash;
    const destinations: { [id: string]: cxschema.DockerImageDestination } = {};

    if (this.imageAssetRegionSet?.length) {
      for (const region of this.imageAssetRegionSet.map(r => r.trim())) {
        if (!region) { continue; }
        destinations[region] = {
          repositoryName: this.repositoryName,
          imageTag,
          region,
          assumeRoleArn: this.fileAssetPublishingRoleArn,
        };
      }
    } else {
      destinations[this.manifestEnvName] = {
        repositoryName: this.repositoryName,
        imageTag,
        region: resolvedOr(this.stack.region, undefined),
        assumeRoleArn: this.imageAssetPublishingRoleArn,
      };
    }

    // Add to manifest
    this.dockerImages[asset.sourceHash] = {
      source: {
        directory: asset.directoryName,
        dockerBuildArgs: asset.dockerBuildArgs,
        dockerBuildTarget: asset.dockerBuildTarget,
        dockerFile: asset.dockerFile,
      },
      destinations,
    };

    let { account, urlSuffix } = stackLocationOrInstrinsics(this.stack);
    account = this.imageAssetAccountId ?? account;

    return {
      repositoryName: cfnify(this.repositoryName),
      imageUri: cfnify(`${account}.dkr.ecr.${REGION_PLACEHOLDER}.${urlSuffix}/${this.repositoryName}:${imageTag}`),
    };
  }