Skip to content

feat: Add option to accept as source an s3 url #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions lib/spa-deploy/spa-deploy-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,29 @@ export class SPADeploy extends cdk.Construct {
return bucket;
}

/**
* Helper method that returns an s3deploy.ISource,
* it accepts either config.websiteFolder as a path to a local .zip file or a directory
* or as an s3 url pointing to .zip file
* @param config
* @returns s3deploy.ISource
*/
private getSource(config:SPADeployConfig): s3deploy.ISource{

const websiteBucket = this.getS3Bucket(config, false);
let source: s3deploy.ISource | undefined = undefined

const isS3Url = new RegExp('s3://.*.zip$');
if (isS3Url.test(config.websiteFolder)){
let key = config.websiteFolder.split(websiteBucket.bucketName + "/")[1]
source = s3deploy.Source.bucket(websiteBucket, key)
}else{
source = s3deploy.Source.asset(config.websiteFolder)
}

return source
}

/**
* Helper method to provide configuration for cloudfront
*/
Expand Down Expand Up @@ -192,9 +215,9 @@ export class SPADeploy extends cdk.Construct {
*/
public createBasicSite(config:SPADeployConfig): SPADeployment {
const websiteBucket = this.getS3Bucket(config, false);

new s3deploy.BucketDeployment(this, 'BucketDeployment', {
sources: [s3deploy.Source.asset(config.websiteFolder)],
sources: [this.getSource(config)],
role: config.role,
destinationBucket: websiteBucket,
});
Expand Down Expand Up @@ -226,7 +249,7 @@ export class SPADeploy extends cdk.Construct {
const distribution = new CloudFrontWebDistribution(this, 'cloudfrontDistribution', this.getCFConfig(websiteBucket, config, accessIdentity));

new s3deploy.BucketDeployment(this, 'BucketDeployment', {
sources: [s3deploy.Source.asset(config.websiteFolder)],
sources: [this.getSource(config)],
destinationBucket: websiteBucket,
// Invalidate the cache for / and index.html when we deploy so that cloudfront serves latest site
distribution,
Expand Down Expand Up @@ -260,7 +283,7 @@ export class SPADeploy extends cdk.Construct {
const distribution = new CloudFrontWebDistribution(this, 'cloudfrontDistribution', this.getCFConfig(websiteBucket, config, accessIdentity, cert));

new s3deploy.BucketDeployment(this, 'BucketDeployment', {
sources: [s3deploy.Source.asset(config.websiteFolder)],
sources: [this.getSource(config)],
destinationBucket: websiteBucket,
// Invalidate the cache for / and index.html when we deploy so that cloudfront serves latest site
distribution,
Expand Down