Skip to content

Commit

Permalink
[ContainerRegistry] Update delete image sample (#16002)
Browse files Browse the repository at this point in the history
to delete tags before delete the image as this is the recommended best
practice for the service.
  • Loading branch information
jeremymeng authored Jun 25, 2021
1 parent 9440254 commit ca61eb9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions sdk/containerregistry/container-registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,14 @@ async function main() {
// Delete images older than the first three.
for await (const manifest of imageManifests) {
if (imageCount++ > imagesToKeep) {
const image = repository.getArtifact(manifest.digest);
console.log(`Deleting image with digest ${manifest.digest}`);
console.log(` This image has the following tags:`);
console.log(` Deleting the following tags from the image:`);
for (const tagName of manifest.tags) {
console.log(` ${manifest.repositoryName}:${tagName}`);
image.deleteTag(tagName);
}
await repository.getArtifact(manifest.digest).delete();
await image.delete();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ async function main() {
// Delete images older than the first three.
for await (const manifest of imageManifests) {
if (imageCount++ > imagesToKeep) {
const image = repository.getArtifact(manifest.digest);
console.log(`Deleting image with digest ${manifest.digest}`);
console.log(` This image has the following tags:`);
console.log(` Deleting the following tags from the image:`);
for (const tagName of manifest.tags) {
console.log(` ${manifest.repositoryName}:${tagName}`);
image.deleteTag(tagName);
}
await repository.getArtifact(manifest.digest).delete();
await image.delete();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ async function main() {
// Delete images older than the first three.
for await (const manifest of imageManifests) {
if (imageCount++ > imagesToKeep) {
const image = repository.getArtifact(manifest.digest);
console.log(`Deleting image with digest ${manifest.digest}`);
console.log(` This image has the following tags:`);
console.log(` Deleting the following tags from the image:`);
for (const tagName of manifest.tags) {
console.log(` ${manifest.repositoryName}:${tagName}`);
image.deleteTag(tagName);
}
await repository.getArtifact(manifest.digest).delete();
await image.delete();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ async function main() {
// Delete images older than the first three.
for await (const manifest of imageManifests) {
if (imageCount++ > imagesToKeep) {
const image = repository.getArtifact(manifest.digest);
console.log(`Deleting image with digest ${manifest.digest}`);
console.log(` This image has the following tags:`);
console.log(` Deleting the following tags from the image:`);
for (const tagName of manifest.tags) {
console.log(` ${manifest.repositoryName}:${tagName}`);
image.deleteTag(tagName);
}
await repository.getArtifact(manifest.digest).delete();
await image.delete();
}
}
}
Expand Down

0 comments on commit ca61eb9

Please sign in to comment.