in packages/blueprints/mirror-to-codecommit/src/blueprint.ts [57:130]
constructor(options_: Options) {
super(options_);
/**
* This is a typecheck to ensure that the defaults passed in are of the correct type.
* There are some cases where the typecheck will fail, but the defaults will still be valid, such when using enums.
* you can override this ex. myEnum: defaults.myEnum as Options['myEnum'],
*/
const typeCheck: Options = {
outdir: this.outdir,
...defaults,
};
const options = Object.assign(typeCheck, options_);
if (!this.context.project.src.listRepositoryNames().length) {
this.throwSynthesisError(
new BlueprintSynthesisError({
message: 'This project has no existing repositories to mirror. Did you mean to create this in another project?',
type: BlueprintSynthesisErrorTypes.ValidationError,
}),
);
}
if (options.repositories?.length) {
this.setInstantiation({
description: `Manages CodeCommit Mirrors for: [${options.repositories.join(',')}]`,
});
}
const branch = 'main';
const environment = options.account.environment && new Environment(this, options.account.environment);
for (const repositoryName of options.repositories || []) {
const repository = new SourceRepository(this, {
title: repositoryName as string,
});
const mirrorWorkflow = new WorkflowBuilder(this, {
Name: `${repository.title}-mirror-to-codecommit`,
Compute: {
Type: ComputeType.LAMBDA,
Fleet: ComputeFleet.LINUX_X86_64_XLARGE,
},
Triggers: [
{
Type: TriggerType.PUSH,
Branches: [branch],
},
],
RunMode: RunModeDefiniton.QUEUED,
});
mirrorWorkflow.addBuildAction({
actionName: 'SyncBranch',
steps: [
// # Creates the CodeCommit repository if it doesn't exist:
`aws codecommit get-repository --repository-name ${repository.title} || aws codecommit create-repository --repository-name ${repository.title}`,
// # Configure git to use AWS credential helper, which relies on the CI/CD
// # Environment's AWS Connection and Role:
"git config credential.helper '!aws codecommit credential-helper $@'",
'git config credential.UseHttpPath true',
// # Push the branch to CodeCommit:
// # (Do not force push, as PicaPica doesn't support this)
`git push https://git-codecommit.${options.account.region}.amazonaws.com/v1/repos/${repository.title} refs/remotes/origin/${branch}:refs/heads/${branch}`,
],
input: {
Sources: ['WorkflowSource'],
},
container: {
Registry: 'CODECATALYST',
Image: 'CodeCatalystLinuxLambda_x86_64:2024_03',
},
environment: convertToWorkflowEnvironment(environment),
});
new Workflow(this, repository, mirrorWorkflow.getDefinition());
}
}