-
Notifications
You must be signed in to change notification settings - Fork 208
Ensure to watch image from image providers #1117
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2302d22
Add image watcher
nakabonne 7b67121
Use sync.Map for git repos
nakabonne 8f024d2
Add image watcher config to piped
nakabonne 0d28d40
Rename LoadImageWatcher
nakabonne 1c4d30e
Add test cases for piped
nakabonne 2cc2c9f
Fix image name string
nakabonne 44f960b
Fix nits
nakabonne 02c9d9b
Fix
nakabonne dc28c17
Use normal map instead of sync.Map
nakabonne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["provider.go"], | ||
| importpath = "github.com/pipe-cd/pipe/pkg/app/piped/imageprovider", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//pkg/app/piped/imageprovider/gcr:go_default_library", | ||
| "//pkg/config:go_default_library", | ||
| "//pkg/model:go_default_library", | ||
| "@com_github_docker_distribution//registry/client/auth/challenge:go_default_library", | ||
| "@org_uber_go_zap//:go_default_library", | ||
| ], | ||
| ) |
This file contains hidden or 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 hidden or 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 hidden or 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,73 @@ | ||
| // Copyright 2020 The PipeCD Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package imageprovider | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
| "net/url" | ||
|
|
||
| "github.com/docker/distribution/registry/client/auth/challenge" | ||
| "go.uber.org/zap" | ||
|
|
||
| "github.com/pipe-cd/pipe/pkg/app/piped/imageprovider/gcr" | ||
| "github.com/pipe-cd/pipe/pkg/config" | ||
| "github.com/pipe-cd/pipe/pkg/model" | ||
| ) | ||
|
|
||
| // Provider acts as a container registry client. | ||
| type Provider interface { | ||
| // Name gives back the provider name that is unique in the Piped. | ||
| Name() string | ||
| // Type indicates which container registry client to act as. | ||
| Type() model.ImageProviderType | ||
| // ParseImage converts the given string into structured image. | ||
| ParseImage(image string) (*model.ImageName, error) | ||
| // GetLatestImages gives back an image with the latest tag. | ||
| GetLatestImage(ctx context.Context, image *model.ImageName) (*model.ImageRef, error) | ||
| } | ||
|
|
||
| // NewProvider yields an appropriate provider according to the given config. | ||
| func NewProvider(cfg *config.PipedImageProvider, logger *zap.Logger) (Provider, error) { | ||
| switch cfg.Type { | ||
| case model.ImageProviderTypeGCR: | ||
| return gcr.NewProvider(cfg.Name, cfg.GCRConfig, doChallenge, logger) | ||
| case model.ImageProviderTypeDockerHub: | ||
| return nil, fmt.Errorf("not implemented yet") | ||
| case model.ImageProviderTypeECR: | ||
| return nil, fmt.Errorf("not implemented yet") | ||
| default: | ||
| return nil, fmt.Errorf("unknown image provider type: %s", cfg.Type) | ||
| } | ||
| } | ||
|
|
||
| func doChallenge(manager challenge.Manager, tx http.RoundTripper, domain string) (*url.URL, error) { | ||
nakabonne marked this conversation as resolved.
Show resolved
Hide resolved
nakabonne marked this conversation as resolved.
Show resolved
Hide resolved
nakabonne marked this conversation as resolved.
Show resolved
Hide resolved
nakabonne marked this conversation as resolved.
Show resolved
Hide resolved
nakabonne marked this conversation as resolved.
Show resolved
Hide resolved
nakabonne marked this conversation as resolved.
Show resolved
Hide resolved
nakabonne marked this conversation as resolved.
Show resolved
Hide resolved
nakabonne marked this conversation as resolved.
Show resolved
Hide resolved
nakabonne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| registryURL := url.URL{ | ||
| Scheme: "https", | ||
| Host: domain, | ||
| Path: "/v2/", | ||
| } | ||
| cs, err := manager.GetChallenges(registryURL) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if len(cs) == 0 { | ||
| // TODO: Handle the no challenge case | ||
| // referring to https://github.com/fluxcd/flux/blob/72743f209207453a4326757ba89fb03cb514b34d/pkg/registry/client_factory.go#L64-L91 | ||
| } | ||
|
|
||
| return ®istryURL, nil | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As they described:
https://docs.docker.com/registry/spec/api/#listing-image-tags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the lack of description, the implementation of GCR is still WIP, and we decided to prioritize ECR over GCR. So will just leave TODO comments.