diff --git a/cdk/amplify-production-stack.ts b/cdk/amplify-production-stack.ts new file mode 100644 index 000000000..07eca073f --- /dev/null +++ b/cdk/amplify-production-stack.ts @@ -0,0 +1,91 @@ +import * as amplify from '@aws-cdk/aws-amplify-alpha'; +import * as cdk from 'aws-cdk-lib'; +import * as iam from 'aws-cdk-lib/aws-iam'; + +export class AmplifyProductionStack extends cdk.Stack { + + constructor(scope: cdk.App, id: string, props: cdk.StackProps) { + super(scope, id, props); + +/* + REWRITE Rewrite (200). + PERMANENT_REDIRECT Permanent redirect (301). + TEMPORARY_REDIRECT Temporary redirect (302). + NOT_FOUND Not found (404). + NOT_FOUND_REWRITE Not found rewrite (404). +*/ + + const main_paths = [ + + { source: 'https://jira.alliancegenome.org', target: 'https://agr-jira.atlassian.net', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: 'https://alliancegenome.org', target: 'https://www.alliancegenome.org', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/bluegenes', target: 'https://www.alliancegenome.org/bluegenes/alliancemine', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/swagger-ui', target: 'https://www.alliancegenome.org/swagger-ui/', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + + { source: '/api/<*>', target: 'https://prod-alb.alliancegenome.org/api/<*>', status: amplify.RedirectStatus.REWRITE }, + + { source: '/jbrowse/worms/protein', target: 'https://www.alliancegenome.org/jbrowse/worms/protein/', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/jbrowse/worms/protein/', target: 'https://main.djgvd7iswt7yy.amplifyapp.com/', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/protein/<*>', target: 'https://main.djgvd7iswt7yy.amplifyapp.com/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/jbrowse-simple', target: 'https://www.alliancegenome.org/jbrowse/worms/jbrowse-simple/', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/jbrowse/worms/jbrowse-simple/', target: 'https://main.d341oo3yism9gt.amplifyapp.com/jbrowse-simple/', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/jbrowse-simple/<*>', target: 'https://main.d341oo3yism9gt.amplifyapp.com/jbrowse-simple/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/jbrowse', target: 'https://www.alliancegenome.org/jbrowse/worms/jbrowse/', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/jbrowse/worms/jbrowse/', target: 'https://main.d341oo3yism9gt.amplifyapp.com/jbrowse/', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/jbrowse/<*>', target: 'https://main.d341oo3yism9gt.amplifyapp.com/jbrowse/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/jbrowse2', target: 'https://www.alliancegenome.org/jbrowse/worms/jbrowse2/', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/jbrowse/worms/jbrowse2/', target: 'https://main.d2jjb0xowet5mr.amplifyapp.com/', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/jbrowse2/<*>', target: 'https://main.d2jjb0xowet5mr.amplifyapp.com/<*>', status: amplify.RedirectStatus.REWRITE }, + + { source: '/jbrowse/<*>', target: 'https://prod-alb.alliancegenome.org/jbrowse/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/apollo/<*>', target: 'https://prod-alb.alliancegenome.org/apollo/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/agr_simplemine.cgi', target: 'https://caltech-curation.textpressolab.com/pub/cgi-bin/forms/agr_simplemine.cgi', status: amplify.RedirectStatus.REWRITE }, + { source: '/alliancemine/cdn/<*>', target: 'https://prod-alb.alliancegenome.org/alliancemine/cdn/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/alliancemine/', target: 'https://prod-alb.alliancegenome.org/alliancemine/', status: amplify.RedirectStatus.REWRITE }, + { source: '/alliancemine/<*>', target: 'https://prod-alb.alliancegenome.org/alliancemine/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/bluegenes/', target: 'https://prod-alb.alliancegenome.org/bluegenes/alliancemine', status: amplify.RedirectStatus.REWRITE }, + { source: '/bluegenes/<*>', target: 'https://prod-alb.alliancegenome.org/bluegenes/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/swagger-ui/', target: 'https://prod-alb.alliancegenome.org/swagger-ui/', status: amplify.RedirectStatus.REWRITE }, + { source: '/swagger-ui/<*>', target: 'https://prod-alb.alliancegenome.org/swagger-ui/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/openapi', target: 'https://prod-alb.alliancegenome.org/openapi', status: amplify.RedirectStatus.REWRITE }, + + { source: '/textpresso/sgd', target: 'https://www.alliancegenome.org/textpresso/sgd/tpc', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/textpresso/sgd/', target: 'https://www.alliancegenome.org/textpresso/sgd/tpc', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/textpresso/sgd/<*>', target: 'https://sgd-textpresso.alliancegenome.org/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/textpresso/wb', target: 'https://www.alliancegenome.org/textpresso/wb/tpc', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/textpresso/wb/', target: 'https://www.alliancegenome.org/textpresso/wb/tpc', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/textpresso/wb/<*>', target: 'https://wb-textpresso.alliancegenome.org/<*>', status: amplify.RedirectStatus.REWRITE }, + + { source: '/<*>', target: '/index.html', status: amplify.RedirectStatus.NOT_FOUND_REWRITE }, + { source: '', target: '/index.html', status: amplify.RedirectStatus.REWRITE } + + ]; + + const amplifyApp = new amplify.App(this, 'agr-ui-production', { + sourceCodeProvider: new amplify.GitHubSourceCodeProvider({ + owner: 'alliance-genome', + repository: 'agr_ui', + oauthToken: cdk.SecretValue.secretsManager('GithubOauthDevopsToken'), + }), + role: iam.Role.fromRoleArn(this, "AmplifyALBRole", 'arn:aws:iam::100225593120:role/StageAmplifyRole'), + }); + + amplifyApp.addEnvironment("BUILD_ENV", "production"); + + const main = amplifyApp.addBranch('main', { autoBuild: true, branchName: 'main', stage: 'PRODUCTION' }); + + const domain = amplifyApp.addDomain('alliancegenome.org'); + domain.mapRoot(main); + domain.mapSubDomain(main, 'www'); + domain.mapSubDomain(main, 'jira'); + + for(let path of main_paths) { + amplifyApp.addCustomRule({ + source: path.source, + target: path.target, + status: path.status + }); + } + + } +} diff --git a/cdk/amplify-rules-stack.ts b/cdk/amplify-rules-stack.ts deleted file mode 100644 index 82253f86d..000000000 --- a/cdk/amplify-rules-stack.ts +++ /dev/null @@ -1,49 +0,0 @@ -import * as amplify from '@aws-cdk/aws-amplify-alpha'; -import * as cdk from 'aws-cdk-lib'; - -export class AmplifyRulesStack extends cdk.Stack { - - constructor(scope: cdk.App, id: string, props: cdk.StackProps) { - super(scope, id, props); - -/* - REWRITE Rewrite (200). - PERMANENT_REDIRECT Permanent redirect (301). - TEMPORARY_REDIRECT Temporary redirect (302). - NOT_FOUND Not found (404). - NOT_FOUND_REWRITE Not found rewrite (404). -*/ - - const test_paths = [ - { source: '/<*>', target: '/index.html', status: amplify.RedirectStatus.REWRITE }, - { source: '/api/<*>', target: 'https://test-alb.alliancegenome.org/api/<*>', status: amplify.RedirectStatus.REWRITE }, - { source: '/jbrowse/<*>', target: 'https://test-alb.alliancegenome.org/jbrowse/<*>', status: amplify.RedirectStatus.REWRITE }, - { source: '/apollo/<*>', target: 'https://test-alb.alliancegenome.org/apollo/<*>', status: amplify.RedirectStatus.REWRITE }, - { source: '/agr_simplemine.cgi', target: 'https://caltech-curation.textpressolab.com/pub/cgi-bin/forms/agr_simplemine.cgi', status: amplify.RedirectStatus.REWRITE }, - { source: '/alliancemine/cdn/<*>', target: 'https://test-alb.alliancegenome.org/alliancemine/cdn/<*>', status: amplify.RedirectStatus.REWRITE }, - { source: '/alliancemine/', target: 'https://test-alb.alliancegenome.org/alliancemine/', status: amplify.RedirectStatus.REWRITE }, - { source: '/alliancemine/<*>', target: 'https://test-alb.alliancegenome.org/alliancemine/<*>', status: amplify.RedirectStatus.REWRITE }, - { source: '/bluegenes', target: 'https://test-alb.alliancegenome.org/bluegenes/alliancemine', status: amplify.RedirectStatus.REWRITE }, - { source: '/bluegenes/', target: 'https://test-alb.alliancegenome.org/bluegenes/alliancemine', status: amplify.RedirectStatus.REWRITE }, - { source: '/bluegenes/', target: 'https://test-alb.alliancegenome.org/bluegenes/<*>', status: amplify.RedirectStatus.REWRITE }, - { source: '/swagger-ui', target: 'https://test-alb.alliancegenome.org/swagger-ui', status: amplify.RedirectStatus.REWRITE }, - { source: '/swagger-ui/', target: 'https://test-alb.alliancegenome.org/swagger-ui/', status: amplify.RedirectStatus.REWRITE }, - { source: '/swagger-ui/<*>', target: 'https://test-alb.alliancegenome.org/swagger-ui/<*>', status: amplify.RedirectStatus.REWRITE }, - { source: '/openapi', target: 'https://test-alb.alliancegenome.org/openapi', status: amplify.RedirectStatus.REWRITE }, - { source: '/openapi2', target: 'https://test-alb.alliancegenome.org/openapi2', status: amplify.RedirectStatus.REWRITE }, - { source: '', target: '/index.html', status: amplify.RedirectStatus.NOT_FOUND_REWRITE } - ]; - - let amplifyApp = amplify.App.fromAppId(this, 'agr_ui_test', 'agr_ui_test'); - - - for(let path of test_paths) { - amplifyApp.addCustomRule({ - source: path.source, - target: path.target, - status: path.status - }); - } - - } -} diff --git a/cdk/amplify-stage-stack.ts b/cdk/amplify-stage-stack.ts index ed30672ca..a0cfbc512 100644 --- a/cdk/amplify-stage-stack.ts +++ b/cdk/amplify-stage-stack.ts @@ -1,6 +1,6 @@ import * as amplify from '@aws-cdk/aws-amplify-alpha'; import * as cdk from 'aws-cdk-lib'; -import * as codebuild from 'aws-cdk-lib/aws-codebuild'; +import * as iam from 'aws-cdk-lib/aws-iam'; export class AmplifyStageStack extends cdk.Stack { @@ -45,7 +45,7 @@ export class AmplifyStageStack extends cdk.Stack { { source: '/textpresso/wb/', target: 'https://stage.alliancegenome.org/textpresso/wb/tpc', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, { source: '/textpresso/wb/<*>', target: 'https://wb-textpresso.alliancegenome.org/<*>', status: amplify.RedirectStatus.REWRITE }, { source: '/<*>', target: '/index.html', status: amplify.RedirectStatus.NOT_FOUND_REWRITE }, - { source: '', target: '/index.html', status: amplify.RedirectStatus.REWRITE } + { source: '', target: '/index.html', status: amplify.RedirectStatus.REWRITE } ]; const amplifyApp = new amplify.App(this, 'agr-ui-stage', { @@ -55,18 +55,17 @@ export class AmplifyStageStack extends cdk.Stack { oauthToken: cdk.SecretValue.secretsManager('GithubOauthDevopsToken'), }), autoBranchCreation: { - patterns: ['SCRUM-*', 'KANBAN-*'], + patterns: ['SCRUM-*'], }, autoBranchDeletion: true, + role: iam.Role.fromRoleArn(this, "AmplifyALBRole", 'arn:aws:iam::100225593120:role/StageAmplifyRole'), }); - //const main = amplifyApp.addBranch('main', { autoBuild: true, branchName: 'main', stage: 'PRODUCTION' }); - //const test = amplifyApp.addBranch('test', { autoBuild: true, branchName: 'test', stage: 'BETA' }); const stage = amplifyApp.addBranch('stage', { autoBuild: true, branchName: 'stage', stage: 'PRODUCTION' }); const domain = amplifyApp.addDomain('alliancegenome.org', { enableAutoSubdomain: true, // in case subdomains should be auto registered for branches - autoSubdomainCreationPatterns: ['scrum-*', 'kanban-*'], // regex for branches that should auto register subdomains + autoSubdomainCreationPatterns: ['scrum-*'], // regex for branches that should auto register subdomains }); //domain.mapRoot(stage); diff --git a/cdk/amplify-test-stack.ts b/cdk/amplify-test-stack.ts new file mode 100644 index 000000000..7b8419777 --- /dev/null +++ b/cdk/amplify-test-stack.ts @@ -0,0 +1,83 @@ +import * as amplify from '@aws-cdk/aws-amplify-alpha'; +import * as cdk from 'aws-cdk-lib'; +import * as iam from 'aws-cdk-lib/aws-iam'; + +export class AmplifyTestStack extends cdk.Stack { + + constructor(scope: cdk.App, id: string, props: cdk.StackProps) { + super(scope, id, props); + +/* + REWRITE Rewrite (200). + PERMANENT_REDIRECT Permanent redirect (301). + TEMPORARY_REDIRECT Temporary redirect (302). + NOT_FOUND Not found (404). + NOT_FOUND_REWRITE Not found rewrite (404). +*/ + + const test_paths = [ + { source: '/<*>', target: '/index.html', status: amplify.RedirectStatus.NOT_FOUND_REWRITE }, + { source: '/api/<*>', target: 'https://test-alb.alliancegenome.org/api/<*>', status: amplify.RedirectStatus.REWRITE }, + + { source: '/jbrowse/worms/protein', target: 'https://test.alliancegenome.org/jbrowse/worms/protein/', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/jbrowse/worms/protein/', target: 'https://main.djgvd7iswt7yy.amplifyapp.com/', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/protein/<*>', target: 'https://main.djgvd7iswt7yy.amplifyapp.com/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/jbrowse-simple', target: 'https://test.alliancegenome.org/jbrowse/worms/jbrowse-simple/', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/jbrowse/worms/jbrowse-simple/', target: 'https://main.d341oo3yism9gt.amplifyapp.com/jbrowse-simple/', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/jbrowse-simple/<*>', target: 'https://main.d341oo3yism9gt.amplifyapp.com/jbrowse-simple/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/jbrowse', target: 'https://test.alliancegenome.org/jbrowse/worms/jbrowse/', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/jbrowse/worms/jbrowse/', target: 'https://main.d341oo3yism9gt.amplifyapp.com/jbrowse/', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/jbrowse/<*>', target: 'https://main.d341oo3yism9gt.amplifyapp.com/jbrowse/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/jbrowse2', target: 'https://test.alliancegenome.org/jbrowse/worms/jbrowse2/', status: amplify.RedirectStatus.PERMANENT_REDIRECT }, + { source: '/jbrowse/worms/jbrowse2/', target: 'https://main.d2jjb0xowet5mr.amplifyapp.com/', status: amplify.RedirectStatus.REWRITE }, + { source: '/jbrowse/worms/jbrowse2/<*>', target: 'https://main.d2jjb0xowet5mr.amplifyapp.com/<*>', status: amplify.RedirectStatus.REWRITE }, + + { source: '/jbrowse/<*>', target: 'https://test-alb.alliancegenome.org/jbrowse/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/apollo/<*>', target: 'https://test-alb.alliancegenome.org/apollo/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/agr_simplemine.cgi', target: 'https://caltech-curation.textpressolab.com/pub/cgi-bin/forms/agr_simplemine.cgi', status: amplify.RedirectStatus.REWRITE }, + { source: '/alliancemine/cdn/<*>', target: 'https://test-alb.alliancegenome.org/alliancemine/cdn/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/alliancemine/', target: 'https://test-alb.alliancegenome.org/alliancemine/', status: amplify.RedirectStatus.REWRITE }, + { source: '/alliancemine/<*>', target: 'https://test-alb.alliancegenome.org/alliancemine/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/bluegenes', target: 'https://test-alb.alliancegenome.org/bluegenes/alliancemine', status: amplify.RedirectStatus.REWRITE }, + { source: '/bluegenes/', target: 'https://test-alb.alliancegenome.org/bluegenes/alliancemine', status: amplify.RedirectStatus.REWRITE }, + { source: '/bluegenes/<*>', target: 'https://test-alb.alliancegenome.org/bluegenes/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/swagger-ui', target: 'https://test-alb.alliancegenome.org/swagger-ui', status: amplify.RedirectStatus.REWRITE }, + { source: '/swagger-ui/', target: 'https://test-alb.alliancegenome.org/swagger-ui/', status: amplify.RedirectStatus.REWRITE }, + { source: '/swagger-ui/<*>', target: 'https://test-alb.alliancegenome.org/swagger-ui/<*>', status: amplify.RedirectStatus.REWRITE }, + { source: '/openapi', target: 'https://test-alb.alliancegenome.org/openapi', status: amplify.RedirectStatus.REWRITE }, + { source: '', target: '/index.html', status: amplify.RedirectStatus.REWRITE } + ]; + + const amplifyApp = new amplify.App(this, 'agr-ui-test', { + sourceCodeProvider: new amplify.GitHubSourceCodeProvider({ + owner: 'alliance-genome', + repository: 'agr_ui', + oauthToken: cdk.SecretValue.secretsManager('GithubOauthDevopsToken'), + }), + autoBranchCreation: { + patterns: ['KANBAN-*'], + }, + autoBranchDeletion: true, + role: iam.Role.fromRoleArn(this, "AmplifyALBRole", 'arn:aws:iam::100225593120:role/StageAmplifyRole'), + }); + + const test = amplifyApp.addBranch('test', { autoBuild: true, branchName: 'test', stage: 'PRODUCTION' }); + + const domain = amplifyApp.addDomain('alliancegenome.org', { + enableAutoSubdomain: true, // in case subdomains should be auto registered for branches + autoSubdomainCreationPatterns: ['kanban-*'], // regex for branches that should auto register subdomains + }); + + //domain.mapRoot(test); + domain.mapSubDomain(test, 'test'); + + for(let path of test_paths) { + amplifyApp.addCustomRule({ + source: path.source, + target: path.target, + status: path.status + }); + } + + } +} diff --git a/cdk/cdk-app.ts b/cdk/cdk-app.ts index 15f2a461e..fe6e56336 100644 --- a/cdk/cdk-app.ts +++ b/cdk/cdk-app.ts @@ -2,6 +2,8 @@ import * as cdk from 'aws-cdk-lib'; import { AmplifyALBStack } from './amplify-alb-stack'; import { AmplifyStageStack } from './amplify-stage-stack'; +import { AmplifyTestStack } from './amplify-test-stack'; +import { AmplifyProductionStack } from './amplify-production-stack'; const app = new cdk.App(); @@ -35,20 +37,12 @@ new AmplifyALBStack(app, 'prod-alb-stack', { }, }); -/* -new AmplifyRulesStack(app, 'stage-rules-stack', { - stackName: 'stage-rules-stack' -}); - -new AmplifyRulesStack(app, 'test-rules-stack', { - stackName: 'stage-rules-stack' -}); - -new AmplifyRulesStack(app, 'prod-rules-stack', { - stackName: 'stage-rules-stack' -}); -*/ - new AmplifyStageStack(app, 'agr-ui-stage', { stackName: 'agr-ui-stage' }); +new AmplifyTestStack(app, 'agr-ui-test', { + stackName: 'agr-ui-test' +}); +new AmplifyProductionStack(app, 'agr-ui-production', { + stackName: 'agr-ui-production' +});