Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for image digest and spare roundtrip to ... #231

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add support for image digest and spare roundtrip to ...
... registry if digest is set
- image digests are immutable, no need to explicitly check it or for new versions
- in case of docker registry downtime, job would be still able to be scheduled in case digest is set
achawki committed Jul 31, 2018
commit 0091750e3e6dac4eb22503520a01687ba833ba19
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@ Note: docker registry must be [v2](https://docs.docker.com/registry/spec/api/).

* `tag`: *Optional.* The tag to track. Defaults to `latest`.

* `Digest`: *Optional.* The image digest. If set `tag` will be ignored.

* `username`: *Optional.* The username to authenticate with when pushing.

* `password`: *Optional.* The password to use when authenticating.
56 changes: 30 additions & 26 deletions cmd/check/main.go
Original file line number Diff line number Diff line change
@@ -66,44 +66,48 @@ func main() {
tag = "latest"
}

transport, registryURL := makeTransport(logger, request, registryHost, repo)
var response CheckResponse

client := &http.Client{
Transport: retryRoundTripper(logger, transport),
}
if request.Source.Digest != "" {
response = append(response, Version{request.Source.Digest})
} else {
transport, registryURL := makeTransport(logger, request, registryHost, repo)

ub, err := v2.NewURLBuilderFromString(registryURL, false)
fatalIf("failed to construct registry URL builder", err)
client := &http.Client{
Transport: retryRoundTripper(logger, transport),
}

namedRef, err := reference.WithName(repo)
fatalIf("failed to construct named reference", err)
ub, err := v2.NewURLBuilderFromString(registryURL, false)
fatalIf("failed to construct registry URL builder", err)

var response CheckResponse
namedRef, err := reference.WithName(repo)
fatalIf("failed to construct named reference", err)

taggedRef, err := reference.WithTag(namedRef, tag)
fatalIf("failed to construct tagged reference", err)
taggedRef, err := reference.WithTag(namedRef, tag)
fatalIf("failed to construct tagged reference", err)

latestManifestURL, err := ub.BuildManifestURL(taggedRef)
fatalIf("failed to build latest manifest URL", err)
latestManifestURL, err := ub.BuildManifestURL(taggedRef)
fatalIf("failed to build latest manifest URL", err)

latestDigest, foundLatest := fetchDigest(client, latestManifestURL)
latestDigest, foundLatest := fetchDigest(client, latestManifestURL)

if request.Version.Digest != "" {
digestRef, err := reference.WithDigest(namedRef, digest.Digest(request.Version.Digest))
fatalIf("failed to build cursor manifest URL", err)
if request.Version.Digest != "" {
digestRef, err := reference.WithDigest(namedRef, digest.Digest(request.Version.Digest))
fatalIf("failed to build cursor manifest URL", err)

cursorManifestURL, err := ub.BuildManifestURL(digestRef)
fatalIf("failed to build manifest URL", err)
cursorManifestURL, err := ub.BuildManifestURL(digestRef)
fatalIf("failed to build manifest URL", err)

cursorDigest, foundCursor := fetchDigest(client, cursorManifestURL)
cursorDigest, foundCursor := fetchDigest(client, cursorManifestURL)

if foundCursor && cursorDigest != latestDigest {
response = append(response, Version{cursorDigest})
if foundCursor && cursorDigest != latestDigest {
response = append(response, Version{cursorDigest})
}
}
}

if foundLatest {
response = append(response, Version{latestDigest})
if foundLatest {
response = append(response, Version{latestDigest})
}
}

json.NewEncoder(os.Stdout).Encode(response)
@@ -192,7 +196,7 @@ func makeTransport(logger lager.Logger, request CheckRequest, registryHost strin

pingClient := &http.Client{
Transport: retryRoundTripper(logger, authTransport),
Timeout: 1 * time.Minute,
Timeout: 1 * time.Minute,
}

challengeManager := auth.NewSimpleChallengeManager()
1 change: 1 addition & 0 deletions cmd/check/models.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import "encoding/json"
type Source struct {
Repository string `json:"repository"`
Tag json.Number `json:"tag"`
Digest string `json:"digest"`
Username string `json:"username"`
Password string `json:"password"`
InsecureRegistries []string `json:"insecure_registries"`