@@ -32,7 +32,7 @@ export class AmplifyHosting extends Construct {
3232
3333 const repository = new Repository ( this , 'Repo' , { repositoryName, description : `${ this . node . path } /Repo` } ) ;
3434
35- const repoImportJob = repository . importFromUrl ( 'main' , sourceRepo , sourceBranch ) ;
35+ const repoImportJob = repository . importFromUrl ( sourceRepo , sourceBranch ) ;
3636
3737 const amplifySSRLoggingRole = new iam . Role ( this , 'AmplifySSRLoggingRole' , {
3838 description : 'The service role that will be used by AWS Amplify for SSR app logging.' ,
@@ -62,6 +62,10 @@ export class AmplifyHosting extends Construct {
6262 } ,
6363 postBuild : {
6464 commands : [
65+ 'shopt -s dotglob' ,
66+ `if [ -d .next/standalone/node_modules ]; then mv -n .next/standalone/node_modules/* .next/standalone/${ appRoot } /node_modules/.; fi` ,
67+ 'rm -rf .next/standalone/node_modules' ,
68+ `mv -f .next/standalone/${ appRoot } /* .next/standalone/.` ,
6569 'cp .env .env.production .next/standalone/' ,
6670 ] ,
6771 } ,
@@ -88,6 +92,9 @@ export class AmplifyHosting extends Construct {
8892 } ) ;
8993 ( this . app . node . defaultChild as cdk . CfnResource ) . addPropertyOverride ( 'Platform' , 'WEB_COMPUTE' ) ;
9094
95+ const outputFileTracingRoot = appRoot . split ( '/' ) . map ( x => x = '..' ) . join ( '/' ) + '/' ;
96+ this . app . addEnvironment ( 'NEXT_PRIVATE_OUTPUT_TRACE_ROOT' , outputFileTracingRoot ) ;
97+
9198 this . app . addEnvironment ( 'AMPLIFY_MONOREPO_APP_ROOT' , appRoot ) ;
9299 this . app . addEnvironment ( 'AMPLIFY_DIFF_DEPLOY' , 'false' ) ;
93100 this . app . addEnvironment ( '_LIVE_UPDATES' , JSON . stringify ( liveUpdates ) ) ;
@@ -136,13 +143,14 @@ export class AmplifyHosting extends Construct {
136143}
137144
138145export class Repository extends codecommit . Repository {
146+ readonly importFunction : lambda . Function ;
139147 readonly importProvider : cr . Provider ;
140148
141149 constructor ( scope : Construct , id : string , props : codecommit . RepositoryProps ) {
142150 super ( scope , id , props ) ;
143151
144- const importFunction = new lambda . Function ( this , 'ImportFunction' , {
145- description : 'Copy Git Repository ' ,
152+ this . importFunction = new lambda . Function ( this , 'ImportFunction' , {
153+ description : 'Clone to CodeCommit from remote repo (You can execute this function manually.) ' ,
146154 runtime : lambda . Runtime . PYTHON_3_9 ,
147155 code : lambda . Code . fromAsset ( './src/functions/copy-git-repo' , {
148156 bundling : {
@@ -167,21 +175,26 @@ export class Repository extends codecommit.Repository {
167175 memorySize : 2048 ,
168176 ephemeralStorageSize : cdk . Size . gibibytes ( 2 ) ,
169177 timeout : cdk . Duration . minutes ( 3 ) ,
178+ environment : {
179+ TARGET_REPO : this . repositoryCloneUrlGrc ,
180+ } ,
170181 } ) ;
171- this . grantPullPush ( importFunction ) ;
182+ this . grantPullPush ( this . importFunction ) ;
172183
173- this . importProvider = new cr . Provider ( this , 'ImportProvider' , { onEventHandler : importFunction } ) ;
184+ this . importProvider = new cr . Provider ( this , 'ImportProvider' , { onEventHandler : this . importFunction } ) ;
174185 }
175186
176- importFromUrl ( targetBranch : string , sourceRepoUrlHttp : string , sourceBranch : string ) {
187+ importFromUrl ( sourceRepoUrlHttp : string , sourceBranch : string , targetBranch : string = 'main' ) {
188+ this . importFunction . addEnvironment ( 'SOURCE_REPO' , sourceRepoUrlHttp ) ;
189+ this . importFunction . addEnvironment ( 'SOURCE_BRANCH' , sourceBranch ) ;
190+ this . importFunction . addEnvironment ( 'TARGET_BRANCH' , targetBranch ) ;
191+
177192 return new cdk . CustomResource ( this , targetBranch , {
178193 resourceType : 'Custom::RepoImportJob' ,
179194 serviceToken : this . importProvider . serviceToken ,
180195 properties : {
181196 SourceRepo : sourceRepoUrlHttp ,
182197 SourceBranch : sourceBranch ,
183- TargetRepo : this . repositoryCloneUrlGrc ,
184- TargetBranch : targetBranch ,
185198 } ,
186199 } ) ;
187200 }
0 commit comments