-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #73 support registry data prune
- Loading branch information
1 parent
dae916a
commit 897fc80
Showing
11 changed files
with
278 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package registry | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
type CatalogRes struct { | ||
Repositories []string `json:"repositories"` | ||
} | ||
|
||
func (r *Registry) Catalog(ctx context.Context) (*CatalogRes, error) { | ||
url := fmt.Sprintf("%s/v2/_catalog", r.baseUrl) | ||
|
||
resp, err := r.client.Get(url) | ||
if err != nil { | ||
return nil, fmt.Errorf("get catalog: %w", err) | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
var result CatalogRes | ||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { | ||
return nil, fmt.Errorf("decode catalog: %w", err) | ||
} | ||
|
||
return &result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package registry | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type ManifestHeadRes struct { | ||
Digest string `json:"digest"` | ||
} | ||
|
||
func (r *Registry) ManifestHead(ctx context.Context, repo, tag string) (*ManifestHeadRes, error) { | ||
url := fmt.Sprintf("%s/v2/%s/manifests/%s", r.baseUrl, repo, tag) | ||
|
||
req, err := http.NewRequestWithContext(ctx, "HEAD", url, nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("create manifest head request: %w", err) | ||
} | ||
|
||
req.Header.Set("Accept", "application/vnd.docker.distribution.manifest.v2+json") | ||
|
||
resp, err := r.client.Do(req) | ||
if err != nil { | ||
return nil, fmt.Errorf("do manifest head request: %w", err) | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
return &ManifestHeadRes{ | ||
Digest: resp.Header.Get("Docker-Content-Digest"), | ||
}, nil | ||
} | ||
|
||
func (r *Registry) ManifestDelete(ctx context.Context, repo, digest string) error { | ||
url := fmt.Sprintf("%s/v2/%s/manifests/%s", r.baseUrl, repo, digest) | ||
|
||
req, err := http.NewRequestWithContext(ctx, "DELETE", url, nil) | ||
if err != nil { | ||
return fmt.Errorf("create manifest delete request: %w", err) | ||
} | ||
|
||
resp, err := r.client.Do(req) | ||
if err != nil { | ||
return fmt.Errorf("do manifest delete request: %w", err) | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package registry | ||
|
||
import "net/http" | ||
|
||
type Registry struct { | ||
baseUrl string | ||
client *http.Client | ||
} | ||
|
||
func New(baseUrl string) *Registry { | ||
return &Registry{ | ||
baseUrl: baseUrl, | ||
client: &http.Client{}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package registry | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
type TagsListRes struct { | ||
Tags []string `json:"tags"` | ||
} | ||
|
||
func (r *Registry) TagsList(ctx context.Context, repo string) (*TagsListRes, error) { | ||
url := fmt.Sprintf("%s/v2/%s/tags/list", r.baseUrl, repo) | ||
|
||
resp, err := r.client.Get(url) | ||
if err != nil { | ||
return nil, fmt.Errorf("get tags list: %w", err) | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
var result TagsListRes | ||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { | ||
return nil, fmt.Errorf("decode tags list: %w", err) | ||
} | ||
|
||
return &result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters