Skip to content

Commit

Permalink
check expired and tagged at first.
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiwara committed Jul 16, 2024
1 parent 4457400 commit e99f50d
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions ecrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,21 @@ IMAGE:
displayName := string(repo) + ":" + tag
sums.Add(d)

// Check if the image is expired
pushedAt := *d.ImagePushedAt
if !rc.IsExpired(pushedAt) {
log.Printf("[info] image %s is not expired, keep it", displayName)
continue IMAGE
}

if tagged {
keepCount++
if keepCount <= rc.KeepCount {
log.Printf("[info] image %s is in keep_count %d <= %d, keep it", displayName, keepCount, rc.KeepCount)
continue IMAGE
}
}

// Check if the image is in use (digest)
imageURISha256 := ImageURI(fmt.Sprintf("%s.dkr.ecr.%s.amazonaws.com/%s@%s", *d.RegistryId, app.region, *d.RepositoryName, *d.ImageDigest))
log.Printf("[debug] checking %s", imageURISha256)
Expand All @@ -291,19 +306,6 @@ IMAGE:
}
}

pushedAt := *d.ImagePushedAt
if !rc.IsExpired(pushedAt) {
log.Printf("[info] image %s is not expired, keep it", displayName)
continue IMAGE
}
if tagged {
keepCount++
if keepCount <= rc.KeepCount {
log.Printf("[info] image %s is in keep_count %d <= %d, keep it", displayName, keepCount, rc.KeepCount)
continue IMAGE
}
}

// Don't match any conditions, so expired
log.Printf("[notice] image %s is expired %s %s", displayName, *d.ImageDigest, pushedAt.Format(time.RFC3339))
expiredIds = append(expiredIds, ecrTypes.ImageIdentifier{ImageDigest: d.ImageDigest})
Expand Down

0 comments on commit e99f50d

Please sign in to comment.