Skip to content

Commit

Permalink
refactor: prune when multiple steps are present
Browse files Browse the repository at this point in the history
  • Loading branch information
junglebarry committed Sep 1, 2021
1 parent 726d324 commit 47f7700
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions lib/cdn-site-hosting/cdn-site-hosting-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ export class CdnSiteHostingConstruct extends cdk.Construct {

// Deploy site contents to S3 bucket
if (props.sourcesWithDeploymentOptions) {
const isSingleDeploymentStep =
props.sourcesWithDeploymentOptions.length === 1;

// multiple sources with granular cache and invalidation control
props.sourcesWithDeploymentOptions.forEach(
(
Expand All @@ -95,29 +98,25 @@ export class CdnSiteHostingConstruct extends cdk.Construct {
distributionPathsToInvalidate &&
distributionPathsToInvalidate.length > 0;

const suffix = name ? name : `${index}`;
const nameOrIndex = name ? name : `${index}`;

new s3deploy.BucketDeployment(
this,
`DeployWithInvalidationControl-${suffix}`,
{
cacheControl,
sources: sources,
prune: false,
destinationBucket: this.s3Bucket,
distribution: isInvalidationRequired
? this.cloudfrontWebDistribution
: undefined,
distributionPaths: isInvalidationRequired
? distributionPathsToInvalidate
: undefined,
}
);
new s3deploy.BucketDeployment(this, `CustomDeploy${nameOrIndex}`, {
cacheControl,
sources: sources,
prune: isSingleDeploymentStep,
destinationBucket: this.s3Bucket,
distribution: isInvalidationRequired
? this.cloudfrontWebDistribution
: undefined,
distributionPaths: isInvalidationRequired
? distributionPathsToInvalidate
: undefined,
});
}
);
} else if (props.sources) {
// multiple sources, with default cache-control and wholesale invalidation
new s3deploy.BucketDeployment(this, "DeployWithFullInvalidation", {
new s3deploy.BucketDeployment(this, "DeployAndInvalidate", {
sources: props.sources,
destinationBucket: this.s3Bucket,
distribution: this.cloudfrontWebDistribution,
Expand Down

0 comments on commit 47f7700

Please sign in to comment.