@@ -50,7 +50,17 @@ export interface EmbeddedLinuxPipelineProps extends cdk.StackProps {
5050 readonly layerRepoName ?: string ;
5151 /** Additional policy statements to add to the build project. */
5252 readonly buildPolicyAdditions ?: iam . PolicyStatement [ ] ;
53- }
53+ /** Access logging bucket to use */
54+ readonly accessLoggingBucket ?: s3 . Bucket ;
55+ /** Access logging prefix to use */
56+ readonly serverAccessLogsPrefix ?: string ;
57+ /** Artifact bucket to use */
58+ readonly artifactBucket ?: s3 . Bucket ;
59+ /** Output bucket to use */
60+ readonly outputBucket ?: s3 . Bucket | VMImportBucket ;
61+ /** Prefix for S3 object within bucket */
62+ readonly subDirectoryName ?: string ;
63+ }
5464
5565/**
5666 * The stack for creating a build pipeline.
@@ -80,11 +90,16 @@ export class EmbeddedLinuxPipelineStack extends cdk.Stack {
8090 let outputBucket : s3 . IBucket | VMImportBucket ;
8191 let environmentVariables = { } ;
8292 let scriptAsset ! : Asset ;
93+ let accessLoggingBucket : s3 . IBucket ;
8394
84- const accessLoggingBucket = new s3 . Bucket ( this , 'ArtifactAccessLogging' , {
85- versioned : true ,
86- enforceSSL : true ,
87- } ) ;
95+ if ( props . accessLoggingBucket ) {
96+ accessLoggingBucket = props . accessLoggingBucket ;
97+ } else {
98+ accessLoggingBucket = new s3 . Bucket ( this , 'ArtifactAccessLogging' , {
99+ versioned : true ,
100+ enforceSSL : true ,
101+ } ) ;
102+ }
88103
89104 if ( props . projectKind && props . projectKind == ProjectKind . PokyAmi ) {
90105 scriptAsset = new Asset ( this , 'CreateAMIScript' , {
@@ -99,14 +114,18 @@ export class EmbeddedLinuxPipelineStack extends cdk.Stack {
99114 enableKeyRotation : true ,
100115 }
101116 ) ;
102-
103- outputBucket = new VMImportBucket ( this , 'PipelineOutput' , {
104- versioned : true ,
105- enforceSSL : true ,
106- encryptionKey : outputBucketEncryptionKey ,
107- encryptionKeyArn : outputBucketEncryptionKey . keyArn ,
108- serverAccessLogsBucket : accessLoggingBucket ,
109- } ) ;
117+ if ( props . outputBucket ) {
118+ outputBucket = props . outputBucket ;
119+ } else {
120+ outputBucket = new VMImportBucket ( this , 'PipelineOutput' , {
121+ versioned : true ,
122+ enforceSSL : true ,
123+ encryptionKey : outputBucketEncryptionKey ,
124+ encryptionKeyArn : outputBucketEncryptionKey . keyArn ,
125+ serverAccessLogsBucket : accessLoggingBucket ,
126+ serverAccessLogsPrefix : props . serverAccessLogsPrefix ,
127+ } ) ;
128+ }
110129 environmentVariables = {
111130 IMPORT_BUCKET : {
112131 type : BuildEnvironmentVariableType . PLAINTEXT ,
@@ -122,28 +141,38 @@ export class EmbeddedLinuxPipelineStack extends cdk.Stack {
122141 } ,
123142 } ;
124143 } else {
125- outputBucket = new s3 . Bucket ( this , 'PipelineOutput' , {
144+ if ( props . outputBucket ) {
145+ outputBucket = props . outputBucket ;
146+ } else {
147+ outputBucket = new s3 . Bucket ( this , 'PipelineOutput' , {
148+ versioned : true ,
149+ enforceSSL : true ,
150+ serverAccessLogsBucket : accessLoggingBucket ,
151+ } ) ;
152+ }
153+ }
154+
155+ let artifactBucket : s3 . IBucket ;
156+
157+ if ( props . artifactBucket ) {
158+ artifactBucket = props . artifactBucket ;
159+ } else {
160+ const encryptionKey = new kms . Key ( this , 'PipelineArtifactKey' , {
161+ removalPolicy : RemovalPolicy . DESTROY ,
162+ enableKeyRotation : true ,
163+ } ) ;
164+ artifactBucket = new s3 . Bucket ( this , 'PipelineArtifacts' , {
126165 versioned : true ,
127166 enforceSSL : true ,
128167 serverAccessLogsBucket : accessLoggingBucket ,
168+ encryptionKey,
169+ encryption : s3 . BucketEncryption . KMS ,
170+ blockPublicAccess : new s3 . BlockPublicAccess (
171+ s3 . BlockPublicAccess . BLOCK_ALL
172+ ) ,
129173 } ) ;
130174 }
131175
132- const encryptionKey = new kms . Key ( this , 'PipelineArtifactKey' , {
133- removalPolicy : RemovalPolicy . DESTROY ,
134- enableKeyRotation : true ,
135- } ) ;
136- const artifactBucket = new s3 . Bucket ( this , 'PipelineArtifacts' , {
137- versioned : true ,
138- enforceSSL : true ,
139- serverAccessLogsBucket : accessLoggingBucket ,
140- encryptionKey,
141- encryption : s3 . BucketEncryption . KMS ,
142- blockPublicAccess : new s3 . BlockPublicAccess (
143- s3 . BlockPublicAccess . BLOCK_ALL
144- ) ,
145- } ) ;
146-
147176 /** Create our CodePipeline Actions. */
148177 const sourceRepo = new SourceRepo ( this , 'SourceRepo' , {
149178 ...props ,
@@ -236,11 +265,22 @@ export class EmbeddedLinuxPipelineStack extends cdk.Stack {
236265 project,
237266 } ) ;
238267
239- const artifactAction = new codepipeline_actions . S3DeployAction ( {
240- actionName : 'Artifact' ,
241- input : buildOutput ,
242- bucket : outputBucket ,
243- } ) ;
268+ let artifactAction : codepipeline_actions . S3DeployAction ;
269+
270+ if ( props . subDirectoryName ) {
271+ artifactAction = new codepipeline_actions . S3DeployAction ( {
272+ actionName : 'Artifact' ,
273+ input : buildOutput ,
274+ bucket : outputBucket ,
275+ objectKey : props . subDirectoryName
276+ } ) ;
277+ } else {
278+ artifactAction = new codepipeline_actions . S3DeployAction ( {
279+ actionName : 'Artifact' ,
280+ input : buildOutput ,
281+ bucket : outputBucket ,
282+ } ) ;
283+ }
244284
245285 /** Here we create the logic to check for presence of ECR image on the CodePipeline automatic triggering upon resource creation,
246286 * and stop the execution if the image does not exist. */
0 commit comments