Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/aws-ecr-lifecycle/sst-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* This file is auto-generated by SST. Do not edit. */
/* tslint:disable */
/* eslint-disable */
import "sst";
export {};

declare module "sst" {
export interface Resource {}
}
36 changes: 36 additions & 0 deletions examples/aws-ecr-lifecycle/sst.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/// <reference path="./.sst/platform/config.d.ts" />

/**
* ## ECR lifecycle policy
*
* Apply a lifecycle policy to the SST bootstrap ECR repository.
*/
export default $config({
app(input) {
return {
name: "aws-ecr-lifecycle",
home: "aws",
removal: input?.stage === "production" ? "retain" : "remove",
};
},
async run() {
new aws.ecr.LifecyclePolicy("SstAssetLifecycle", {
repository: sst.aws.getECRRepository().apply((repo) => repo.name),
policy: JSON.stringify({
rules: [
{
rulePriority: 1,
description: "Expire untagged images pushed over 30 days ago",
selection: {
tagStatus: "untagged",
countType: "sinceImagePushed",
countUnit: "days",
countNumber: 30,
},
action: { type: "expire" },
},
],
}),
});
},
});
42 changes: 42 additions & 0 deletions platform/src/components/aws/ecr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { output } from "@pulumi/pulumi";
import { getRegionOutput } from "@pulumi/aws";
import { bootstrap } from "./helpers/bootstrap";
import { VisibleError } from "../error";

export interface EcrRepositoryInfo {
/**
* The ECR repository name.
*/
name: string;
/**
* The ECR repository URL.
*/
url: string;
/**
* The ECR registry ID.
*/
registryId: string;
}

/**
* Get the bootstrap ECR repository used by SST for storing assets.
*/
export function getECRRepository() {
const region = getRegionOutput().name;
const bootstrapData = region.apply((value) => bootstrap.forRegion(value));

return output(bootstrapData).apply((data) => {
const name = data.assetEcrUrl.split("/").pop();
if (!name) {
throw new VisibleError(
`Failed to resolve the SST asset ECR repository name from "${data.assetEcrUrl}".`,
);
}

return {
name,
url: data.assetEcrUrl,
registryId: data.assetEcrRegistryId,
} satisfies EcrRepositoryInfo;
});
}
1 change: 1 addition & 0 deletions platform/src/components/aws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from "./cognito-user-pool.js";
export * from "./cron.js";
export * from "./dns.js";
export * from "./dynamo.js";
export * from "./ecr.js";
export * from "./efs.js";
export * from "./email.js";
export * from "./function.js";
Expand Down