Skip to content

Commit

Permalink
ecr
Browse files Browse the repository at this point in the history
  • Loading branch information
omerh committed Nov 13, 2019
1 parent 83b13b2 commit f7abea8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ ECR Opertaion for setting lifecycle policy to untagged repositories
awsctl set ecrregistrypolicy -r eu-west-2 --retention 7
```

ECR Repository configuration to scanOnPush repository for vulnerabilities

```bash
awsctl set ecrscanonpush --region eu-west-1 --scan true --yes
awsctl set ecrscanonpush --region all --scan true --yes
```

For any missing action please open an issue for a feature request.

### Contributing
Expand Down
2 changes: 1 addition & 1 deletion cmd/awsctl/cmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var setCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(setCmd)
setCmd.AddCommand(cmdCloudwatch)
setCmd.AddCommand(setEcrRegistryPolicy)
setCmd.AddCommand(setEcrRegistryPolicyCmd)
setCmd.AddCommand(setEcrScanOnPushcmd)
setCmd.PersistentFlags().BoolP("yes", "y", false, "Specify --yes to execute")
setCmd.PersistentFlags().Int("retention", 14, "Retention in days")
Expand Down
2 changes: 1 addition & 1 deletion cmd/awsctl/cmd/set_ecr_registry_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/cobra"
)

var setEcrRegistryPolicy = &cobra.Command{
var setEcrRegistryPolicyCmd = &cobra.Command{
Use: "ecrregistrypolicy",
Short: "Set ECR Registry policy to untagged images",
Run: func(cmd *cobra.Command, args []string) {
Expand Down
18 changes: 18 additions & 0 deletions pkg/helper/ecr.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,21 @@ func SetEcrRepoImageScanOnPush(repositoryName string, region string, scanOnPush
log.Printf("scanOnPush for repository %v was set to %v", repositoryName, scanOnPush)
}
}

// EcrDeleteOldImageBuildsAndKeep delete old images and keep only n last images
func EcrDeleteOldImageBuildsAndKeep(repositoryName string, region string, imagesToKeep int) {
awsSession, _ := InitAwsSession(region)
svc := ecr.New(awsSession)
input := &ecr.ListImagesInput{
RepositoryName: aws.String(repositoryName),
}
images, err := svc.ListImages(input)
if err != nil {
log.Printf("Error: %v", err)
return
}
// for _, i := range images {
// fmt.Println(i)
// }
fmt.Println(images)
}

0 comments on commit f7abea8

Please sign in to comment.