91 lines
2.7 KiB
TypeScript
91 lines
2.7 KiB
TypeScript
import * as cdk from "aws-cdk-lib";
|
|
import * as ecr from "aws-cdk-lib/aws-ecr";
|
|
import { Construct } from "constructs";
|
|
|
|
interface EcrStackProps extends cdk.StackProps {
|
|
/**
|
|
* Environment name (dev, staging, prod)
|
|
*/
|
|
environment: string;
|
|
|
|
/**
|
|
* Number of images to retain (default: 10)
|
|
*/
|
|
maxImageCount?: number;
|
|
}
|
|
|
|
export class EcrStack extends cdk.Stack {
|
|
/**
|
|
* Backend Docker image repository
|
|
*/
|
|
public readonly backendRepository: ecr.Repository;
|
|
|
|
/**
|
|
* Frontend Docker image repository
|
|
*/
|
|
public readonly frontendRepository: ecr.Repository;
|
|
|
|
constructor(scope: Construct, id: string, props: EcrStackProps) {
|
|
super(scope, id, props);
|
|
|
|
const { environment, maxImageCount = 10 } = props;
|
|
|
|
// Backend repository
|
|
this.backendRepository = new ecr.Repository(this, "BackendRepository", {
|
|
repositoryName: `rentall-backend-${environment}`,
|
|
removalPolicy: cdk.RemovalPolicy.RETAIN,
|
|
imageScanOnPush: true,
|
|
imageTagMutability: ecr.TagMutability.MUTABLE,
|
|
lifecycleRules: [
|
|
{
|
|
rulePriority: 1,
|
|
description: `Keep only the last ${maxImageCount} images`,
|
|
maxImageCount: maxImageCount,
|
|
tagStatus: ecr.TagStatus.ANY,
|
|
},
|
|
],
|
|
});
|
|
|
|
// Frontend repository
|
|
this.frontendRepository = new ecr.Repository(this, "FrontendRepository", {
|
|
repositoryName: `rentall-frontend-${environment}`,
|
|
removalPolicy: cdk.RemovalPolicy.RETAIN,
|
|
imageScanOnPush: true,
|
|
imageTagMutability: ecr.TagMutability.MUTABLE,
|
|
lifecycleRules: [
|
|
{
|
|
rulePriority: 1,
|
|
description: `Keep only the last ${maxImageCount} images`,
|
|
maxImageCount: maxImageCount,
|
|
tagStatus: ecr.TagStatus.ANY,
|
|
},
|
|
],
|
|
});
|
|
|
|
// Outputs
|
|
new cdk.CfnOutput(this, "BackendRepositoryUri", {
|
|
value: this.backendRepository.repositoryUri,
|
|
description: "Backend ECR repository URI",
|
|
exportName: `BackendRepositoryUri-${environment}`,
|
|
});
|
|
|
|
new cdk.CfnOutput(this, "BackendRepositoryName", {
|
|
value: this.backendRepository.repositoryName,
|
|
description: "Backend ECR repository name",
|
|
exportName: `BackendRepositoryName-${environment}`,
|
|
});
|
|
|
|
new cdk.CfnOutput(this, "FrontendRepositoryUri", {
|
|
value: this.frontendRepository.repositoryUri,
|
|
description: "Frontend ECR repository URI",
|
|
exportName: `FrontendRepositoryUri-${environment}`,
|
|
});
|
|
|
|
new cdk.CfnOutput(this, "FrontendRepositoryName", {
|
|
value: this.frontendRepository.repositoryName,
|
|
description: "Frontend ECR repository name",
|
|
exportName: `FrontendRepositoryName-${environment}`,
|
|
});
|
|
}
|
|
}
|