Skip to content

Commit

Permalink
fix(replication): aws ecr delete image
Browse files Browse the repository at this point in the history
Signed-off-by: Ziming Zhang <[email protected]>
Change-Id: I5e38b813c2840e0270973c38680cb8f815e5ece9
Signed-off-by: Ziming Zhang <[email protected]>
  • Loading branch information
bitsf committed Jan 13, 2020
1 parent 3fe7517 commit ed3bf04
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/replication/adapter/awsecr/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,38 @@ func (a *adapter) createRepository(repository string) error {
}
return nil
}

// DeleteManifest ...
func (a *adapter) DeleteManifest(repository, reference string) error {
// AWS doesn't implement standard OCI delete manifest API, so use it's sdk.
if a.registry.Credential == nil ||
len(a.registry.Credential.AccessKey) == 0 || len(a.registry.Credential.AccessSecret) == 0 {
return errors.New("no credential ")
}
cred := credentials.NewStaticCredentials(
a.registry.Credential.AccessKey,
a.registry.Credential.AccessSecret,
"")
if a.region == "" {
return errors.New("no region parsed")
}
config := &aws.Config{
Credentials: cred,
Region: &a.region,
HTTPClient: &http.Client{
Transport: registry.GetHTTPTransport(a.registry.Insecure),
},
}
if a.forceEndpoint != nil {
config.Endpoint = a.forceEndpoint
}
sess := session.Must(session.NewSession(config))

svc := awsecrapi.New(sess)

_, err := svc.BatchDeleteImage(&awsecrapi.BatchDeleteImageInput{
RepositoryName: &repository,
ImageIds: []*awsecrapi.ImageIdentifier{{ImageTag: &reference}},
})
return err
}

0 comments on commit ed3bf04

Please sign in to comment.