Skip to content

Commit

Permalink
chore: Pipeline Refactor (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamputraintan authored Apr 30, 2024
1 parent 43bb169 commit 1ee5092
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 213 deletions.
48 changes: 23 additions & 25 deletions config/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { region, accountIdAlias } from './constants';
import { region, AppStage, accountIdAlias } from './constants';
import { StatefulStackCollectionProps } from '../lib/workload/stateful/statefulStackCollectionClass';
import { StatelessStackCollectionProps } from '../lib/workload/stateless/statelessStackCollectionClass';
import { getSharedStackProps } from './stacks/shared';
Expand All @@ -24,75 +24,73 @@ interface EnvironmentConfig {
/**
* The function will return the appropriate configuration for the given account
*
* @param accountName the name of account stage
* @returns the configuration for the given accountName
* @param stage the name of account stage
* @returns the configuration for the given app stage
*/
export const getEnvironmentConfig = (
accountName: 'beta' | 'gamma' | 'prod'
): EnvironmentConfig | null => {
switch (accountName) {
case 'beta':
export const getEnvironmentConfig = (stage: AppStage): EnvironmentConfig | null => {
switch (stage) {
case AppStage.BETA:
return {
name: 'beta',
region,
accountId: accountIdAlias[accountName], // umccr_development
accountId: accountIdAlias[stage], // umccr_development
stackProps: {
statefulConfig: {
sharedStackProps: getSharedStackProps(accountName),
sharedStackProps: getSharedStackProps(stage),
tokenServiceStackProps: getTokenServiceStackProps(),
icaEventPipeStackProps: getIcaEventPipeStackProps(),
},
statelessConfig: {
postgresManagerStackProps: getPostgresManagerStackProps(),
metadataManagerStackProps: getMetadataManagerStackProps(),
sequenceRunManagerStackProps: getSequenceRunManagerStackProps(),
fileManagerStackProps: getFileManagerStackProps(accountName),
bsRunsUploadManagerStackProps: getBsRunsUploadManagerStackProps(accountName),
icav2CopyBatchUtilityStackProps: getICAv2CopyBatchUtilityStackProps(accountName),
fileManagerStackProps: getFileManagerStackProps(stage),
bsRunsUploadManagerStackProps: getBsRunsUploadManagerStackProps(stage),
icav2CopyBatchUtilityStackProps: getICAv2CopyBatchUtilityStackProps(stage),
},
},
};

case 'gamma':
case AppStage.GAMMA:
return {
name: 'gamma',
region,
accountId: accountIdAlias[accountName], // umccr_staging
accountId: accountIdAlias[stage], // umccr_staging
stackProps: {
statefulConfig: {
sharedStackProps: getSharedStackProps(accountName),
sharedStackProps: getSharedStackProps(stage),
tokenServiceStackProps: getTokenServiceStackProps(),
icaEventPipeStackProps: getIcaEventPipeStackProps(),
},
statelessConfig: {
postgresManagerStackProps: getPostgresManagerStackProps(),
metadataManagerStackProps: getMetadataManagerStackProps(),
sequenceRunManagerStackProps: getSequenceRunManagerStackProps(),
fileManagerStackProps: getFileManagerStackProps(accountName),
bsRunsUploadManagerStackProps: getBsRunsUploadManagerStackProps(accountName),
icav2CopyBatchUtilityStackProps: getICAv2CopyBatchUtilityStackProps(accountName),
fileManagerStackProps: getFileManagerStackProps(stage),
bsRunsUploadManagerStackProps: getBsRunsUploadManagerStackProps(stage),
icav2CopyBatchUtilityStackProps: getICAv2CopyBatchUtilityStackProps(stage),
},
},
};

case 'prod':
case AppStage.PROD:
return {
name: 'prod',
region,
accountId: accountIdAlias[accountName], // umccr_production
accountId: accountIdAlias[stage], // umccr_production
stackProps: {
statefulConfig: {
sharedStackProps: getSharedStackProps(accountName),
sharedStackProps: getSharedStackProps(stage),
tokenServiceStackProps: getTokenServiceStackProps(),
icaEventPipeStackProps: getIcaEventPipeStackProps(),
},
statelessConfig: {
postgresManagerStackProps: getPostgresManagerStackProps(),
metadataManagerStackProps: getMetadataManagerStackProps(),
sequenceRunManagerStackProps: getSequenceRunManagerStackProps(),
fileManagerStackProps: getFileManagerStackProps(accountName),
bsRunsUploadManagerStackProps: getBsRunsUploadManagerStackProps(accountName),
icav2CopyBatchUtilityStackProps: getICAv2CopyBatchUtilityStackProps(accountName),
fileManagerStackProps: getFileManagerStackProps(stage),
bsRunsUploadManagerStackProps: getBsRunsUploadManagerStackProps(stage),
icav2CopyBatchUtilityStackProps: getICAv2CopyBatchUtilityStackProps(stage),
},
},
};
Expand Down
43 changes: 24 additions & 19 deletions config/constants.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { VpcLookupOptions } from 'aws-cdk-lib/aws-ec2';

export type AccountName = 'beta' | 'gamma' | 'prod';
export enum AppStage {
BETA = 'beta',
GAMMA = 'gamma',
PROD = 'prod',
}

export const region = 'ap-southeast-2';

/**
* accountIdAlias: mapping from AccountName to AWS Account ID.
* accountIdAliasType to ensure that the accountId is always explicitly defined for each account.
*/
type accountIdAliasType = {
[K in AccountName]: string;
};

export const accountIdAlias: accountIdAliasType = {
beta: '843407916570', // umccr_development
gamma: '455634345446', // umccr_staging
prod: '472057503814', // umccr_production
export const accountIdAlias: Record<AppStage, string> = {
[AppStage.BETA]: '843407916570', // umccr_development
[AppStage.GAMMA]: '455634345446', // umccr_staging
[AppStage.PROD]: '472057503814', // umccr_production
};

// external ICA constants
Expand All @@ -38,13 +37,17 @@ export const cognitoPortalAppClientIdParameterName =
export const cognitoStatusPageAppClientIdParameterName =
'/data_portal/status_page/cog_app_client_id_stage';

export const devBucket = 'umccr-temp-dev';
export const stgBucket = 'umccr-temp-stg';
export const prodBucket = 'org.umccr.data.oncoanalyser';
export const oncoanalyserBucket: Record<AppStage, string> = {
[AppStage.BETA]: 'umccr-temp-dev',
[AppStage.GAMMA]: 'umccr-temp-stg',
[AppStage.PROD]: 'org.umccr.data.oncoanalyser',
};

export const devGdsBsRunsUploadLogPath = 'gds://development/primary_data/temp/bs_runs_upload_tes/';
export const stgGdsBsRunsUploadLogPath = 'gds://staging/primary_data/temp/bs_runs_upload_tes/';
export const prodGdsBsRunsUploadLogPath = 'gds://production/primary_data/temp/bs_runs_upload_tes/';
export const gdsBsRunsUploadLogPath: Record<AppStage, string> = {
[AppStage.BETA]: 'gds://development/primary_data/temp/bs_runs_upload_tes/',
[AppStage.GAMMA]: 'gds://staging/primary_data/temp/bs_runs_upload_tes/',
[AppStage.PROD]: 'gds://production/primary_data/temp/bs_runs_upload_tes/',
};

/**
* Validate the secret name so that it doesn't end with 6 characters and a hyphen.
Expand Down Expand Up @@ -93,9 +96,11 @@ export const basespaceAccessTokenSecretName = '/manual/BaseSpaceAccessTokenSecre
/*
ICAv2 Resources - required by various stacks
*/
export const icav2AccessTokenSecretNameDev = 'ICAv2JWTKey-umccr-prod-service-trial'; // pragma: allowlist secret
export const icav2AccessTokenSecretNameStg = 'ICAv2JWTKey-umccr-prod-service-staging'; // pragma: allowlist secret
export const icav2AccessTokenSecretNameProd = 'ICAv2JWTKey-umccr-prod-service-prod'; // pragma: allowlist secret
export const icav2AccessTokenSecretName: Record<AppStage, string> = {
[AppStage.BETA]: 'ICAv2JWTKey-umccr-prod-service-trial', // pragma: allowlist secret
[AppStage.GAMMA]: 'ICAv2JWTKey-umccr-prod-service-staging', // pragma: allowlist secret
[AppStage.PROD]: 'ICAv2JWTKey-umccr-prod-service-prod', // pragma: allowlist secret
};

/*
Resources generated by the ICAv2 Copy Batch utility stack
Expand Down
29 changes: 5 additions & 24 deletions config/stacks/bsRunsUploadManager.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
import {
devGdsBsRunsUploadLogPath,
stgGdsBsRunsUploadLogPath,
prodGdsBsRunsUploadLogPath,
AccountName,
AppStage,
icaAccessTokenSecretName,
jwtSecretName,
basespaceAccessTokenSecretName,
eventBusName,
gdsBsRunsUploadLogPath,
} from '../constants';
import { BsRunsUploadManagerConfig } from '../../lib/workload/stateless/stacks/bs-runs-upload-manager/deploy/stack';

export const getBsRunsUploadManagerStackProps = (n: AccountName): BsRunsUploadManagerConfig => {
const baseConfig = {
export const getBsRunsUploadManagerStackProps = (stage: AppStage): BsRunsUploadManagerConfig => {
return {
ica_token_secret_id: icaAccessTokenSecretName,
portal_token_secret_id: jwtSecretName,
basespace_token_secret_id: basespaceAccessTokenSecretName,
eventbus_name: eventBusName,
gds_system_files_path: gdsBsRunsUploadLogPath[stage],
};

switch (n) {
case 'beta':
return {
...baseConfig,
gds_system_files_path: devGdsBsRunsUploadLogPath,
};
case 'gamma':
return {
...baseConfig,
gds_system_files_path: stgGdsBsRunsUploadLogPath,
};
case 'prod':
return {
...baseConfig,
gds_system_files_path: prodGdsBsRunsUploadLogPath,
};
}
};
29 changes: 5 additions & 24 deletions config/stacks/fileManager.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { FilemanagerConfig } from '../../lib/workload/stateless/stacks/filemanager/deploy/stack';
import {
AccountName,
AppStage,
computeSecurityGroupName,
databasePort,
dbClusterEndpointHostParameterName,
devBucket,
eventSourceQueueName,
prodBucket,
stgBucket,
vpcProps,
cognitoPortalAppClientIdParameterName,
cognitoStatusPageAppClientIdParameterName,
cognitoUserPoolIdParameterName,
oncoanalyserBucket,
} from '../constants';

export const getFileManagerStackProps = (n: AccountName): FilemanagerConfig => {
const baseConfig = {
export const getFileManagerStackProps = (stage: AppStage): FilemanagerConfig => {
return {
securityGroupName: computeSecurityGroupName,
vpcProps,
eventSourceQueueName: eventSourceQueueName,
Expand All @@ -25,23 +23,6 @@ export const getFileManagerStackProps = (n: AccountName): FilemanagerConfig => {
cognitoPortalAppClientIdParameterName: cognitoPortalAppClientIdParameterName,
cognitoStatusPageAppClientIdParameterName: cognitoStatusPageAppClientIdParameterName,
cognitoUserPoolIdParameterName: cognitoUserPoolIdParameterName,
eventSourceBuckets: [oncoanalyserBucket[stage]],
};

switch (n) {
case 'beta':
return {
...baseConfig,
eventSourceBuckets: [devBucket],
};
case 'gamma':
return {
...baseConfig,
eventSourceBuckets: [stgBucket],
};
case 'prod':
return {
...baseConfig,
eventSourceBuckets: [prodBucket],
};
}
};
33 changes: 6 additions & 27 deletions config/stacks/icav2CopyBatchUtility.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import {
icav2AccessTokenSecretNameDev,
icav2AccessTokenSecretNameStg,
icav2AccessTokenSecretNameProd,
AccountName,
icav2CopyBatchSSMRoot,
} from '../constants';
import { AppStage, icav2CopyBatchSSMRoot, icav2AccessTokenSecretName } from '../constants';

import { ICAv2CopyBatchUtilityConfig } from '../../lib/workload/stateless/stacks/icav2-copy-batch-utility/deploy/stack';
import path from 'path';

export const getICAv2CopyBatchUtilityStackProps = (n: AccountName): ICAv2CopyBatchUtilityConfig => {
const baseConfig = {
export const getICAv2CopyBatchUtilityStackProps = (
stage: AppStage
): ICAv2CopyBatchUtilityConfig => {
return {
icav2_copy_batch_state_machine_name: 'icav2_copy_batch_utility_sfn',
icav2_copy_batch_state_machine_arn_ssm_parameter_path: path.join(
icav2CopyBatchSSMRoot,
Expand All @@ -29,23 +25,6 @@ export const getICAv2CopyBatchUtilityStackProps = (n: AccountName): ICAv2CopyBat
icav2CopyBatchSSMRoot,
'single_sfn_name'
),
icav2_token_secret_id: icav2AccessTokenSecretName[stage],
};

switch (n) {
case 'beta':
return {
...baseConfig,
icav2_token_secret_id: icav2AccessTokenSecretNameDev,
};
case 'gamma':
return {
...baseConfig,
icav2_token_secret_id: icav2AccessTokenSecretNameStg,
};
case 'prod':
return {
...baseConfig,
icav2_token_secret_id: icav2AccessTokenSecretNameProd,
};
}
};
Loading

0 comments on commit 1ee5092

Please sign in to comment.