Skip to content

Commit

Permalink
feat: #479 Introduce CI mode: parallel (default) and simple
Browse files Browse the repository at this point in the history
  • Loading branch information
mkleszcz committed Feb 16, 2024
1 parent db0a868 commit 359d396
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 7 deletions.
17 changes: 17 additions & 0 deletions packages/infra/infra-core/src/lib/env-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ declare const process: {
SB_TOOLS_HOSTED_ZONE_NAME: string;
SB_TOOLS_HOSTED_ZONE_ID: string;
SB_TOOLS_DOMAIN_VERSION_MATRIX: string;
SB_CI_MODE: string;
};
};

Expand Down Expand Up @@ -64,6 +65,15 @@ interface WebAppConfig {
envVariables: EnvironmentVariables;
}

export enum CI_MODE {
PARALLEL = 'parallel',
SIMPLE = 'simple',
}

interface CIConfig {
mode: CI_MODE;
}

export interface EnvironmentSettings {
appBasicAuth: string | null | undefined;
deployBranches: Array<string>;
Expand All @@ -77,11 +87,13 @@ export interface EnvironmentSettings {
version: string;
webAppEnvVariables: EnvironmentVariables;
certificates: CertificatesConfig;
CIConfig: CIConfig;
}

interface ConfigFileContent {
toolsConfig: ToolsConfig;
webAppConfig: WebAppConfig;
CIConfig: CIConfig;
}

export interface EnvConfigFileContent {
Expand Down Expand Up @@ -109,6 +121,10 @@ async function readConfig(): Promise<ConfigFileContent> {
versionMatrix: process.env.SB_TOOLS_DOMAIN_VERSION_MATRIX,
},
},
CIConfig: {
mode: process.env.SB_CI_MODE === CI_MODE.SIMPLE
? CI_MODE.SIMPLE : CI_MODE.PARALLEL,
}
};
}

Expand Down Expand Up @@ -176,5 +192,6 @@ export async function loadEnvSettings(): Promise<EnvironmentSettings> {
...(envConfig?.webAppConfig?.envVariables || {}),
},
certificates: envConfig.certificates,
CIConfig: config.CIConfig,
};
}
11 changes: 11 additions & 0 deletions packages/infra/infra-core/src/lib/patterns/serviceCiConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Construct } from 'constructs';
import * as codebuild from 'aws-cdk-lib/aws-codebuild';
import { EnvConstructProps } from '../constructs';
import { CI_MODE } from '../env-config';
import { IStage } from 'aws-cdk-lib/aws-codepipeline';

export interface IServiceCiConfig {
defaultEnvVariables: {
Expand All @@ -22,9 +24,11 @@ export enum PnpmWorkspaceFilters {
export class ServiceCiConfig extends Construct implements IServiceCiConfig {
defaultEnvVariables: { [p: string]: codebuild.BuildEnvironmentVariable };
defaultCachePaths: string[];
props: EnvConstructProps;

constructor(scope: Construct, id: string, props: EnvConstructProps) {
super(scope, id);
this.props = props;

this.defaultEnvVariables = {
CI: {
Expand Down Expand Up @@ -69,4 +73,11 @@ export class ServiceCiConfig extends Construct implements IServiceCiConfig {
'export AWS_SESSION_TOKEN=$(echo "${TEMP_ROLE}" | jq -r \'.Credentials.SessionToken\')',
];
}

protected getRunOrder(stage: IStage, defaultRunOrder?: number) {
if (this.props.envSettings.CIConfig.mode === CI_MODE.PARALLEL) {
return defaultRunOrder;
}
return stage.actions.length + 1;
}
}
5 changes: 3 additions & 2 deletions packages/infra/infra-shared/src/stacks/ci/ciBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class BackendCiConfig extends ServiceCiConfig {
'api',
{
project: apiDeployProject,
runOrder: 2,
runOrder: this.getRunOrder(props.deployStage, 2)
},
props,
),
Expand All @@ -54,7 +54,7 @@ export class BackendCiConfig extends ServiceCiConfig {
'migrations',
{
project: migrationsDeployProject,
runOrder: 2,
runOrder: this.getRunOrder(props.deployStage, 2)
},
props,
),
Expand All @@ -72,6 +72,7 @@ export class BackendCiConfig extends ServiceCiConfig {
actionName: `${props.envSettings.projectEnvName}-build-${name}`,
project: actionProps.project,
input: props.inputArtifact,
runOrder: this.getRunOrder(props.buildStage)
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/infra/infra-shared/src/stacks/ci/ciComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ComponentsCiConfig extends ServiceCiConfig {
project: actionProps.project,
actionName: `${props.envSettings.projectEnvName}-deploy-components`,
input: props.inputArtifact,
runOrder: 1,
runOrder: this.getRunOrder(props.deployStage, 1),
});
}

Expand Down
3 changes: 2 additions & 1 deletion packages/infra/infra-shared/src/stacks/ci/ciDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class DocsCiConfig extends ServiceCiConfig {
{
project: deployProject,
input: buildArtifact,
runOrder: 2,
runOrder: this.getRunOrder(props.deployStage, 2),
},
props,
),
Expand All @@ -61,6 +61,7 @@ export class DocsCiConfig extends ServiceCiConfig {
>{
...actionProps,
actionName: `${props.envSettings.projectEnvName}-build-docs`,
runOrder: this.getRunOrder(props.buildStage)
});
}

Expand Down
3 changes: 2 additions & 1 deletion packages/infra/infra-shared/src/stacks/ci/ciServerless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ServerlessCiConfig extends ServiceCiConfig {
{
project: deployProject,
input: buildArtifact,
runOrder: 2,
runOrder: this.getRunOrder(props.deployStage, 2),
},
props,
),
Expand All @@ -61,6 +61,7 @@ export class ServerlessCiConfig extends ServiceCiConfig {
>{
...actionProps,
actionName: `${props.envSettings.projectEnvName}-build-workers`,
runOrder: this.getRunOrder(props.deployStage),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class UploadVersionCiConfig extends ServiceCiConfig {
{
project: deployProject,
input: props.inputArtifact,
runOrder: 3,
runOrder: this.getRunOrder(props.stage, 3),
},
props
)
Expand Down
3 changes: 2 additions & 1 deletion packages/infra/infra-shared/src/stacks/ci/ciWebApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class WebappCiConfig extends ServiceCiConfig {
{
project: deployProject,
input: buildArtifact,
runOrder: 2,
runOrder: this.getRunOrder(props.deployStage, 2),
},
props,
),
Expand All @@ -61,6 +61,7 @@ export class WebappCiConfig extends ServiceCiConfig {
>{
...actionProps,
actionName: `${props.envSettings.projectEnvName}-build-webapp`,
runOrder: this.getRunOrder(props.buildStage)
});
}

Expand Down

0 comments on commit 359d396

Please sign in to comment.