infrastructure with aws cdk
This commit is contained in:
90
infrastructure/cdk/lib/ecr-stack.ts
Normal file
90
infrastructure/cdk/lib/ecr-stack.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
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}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user