mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-19 16:40:12 +01:00
fix some tests, split up and refactor
some wonky regression introduced by docker dependencies when running on darwin. see https://github.com/ory/dockertest/issues/212 for more info. will have a look at this next
This commit is contained in:
parent
83aa420996
commit
6b9fd8d7ef
12 changed files with 389 additions and 225 deletions
38
pkg/registry/helpers/helpers.go
Normal file
38
pkg/registry/helpers/helpers.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
url2 "net/url"
|
||||
)
|
||||
|
||||
// ConvertToHostname strips a url from everything but the hostname part
|
||||
func ConvertToHostname(url string) (string, string, error) {
|
||||
urlWithSchema := fmt.Sprintf("x://%s", url)
|
||||
u, err := url2.Parse(urlWithSchema)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
fmt.Println(url, err)
|
||||
hostName := u.Hostname()
|
||||
port := u.Port()
|
||||
|
||||
|
||||
return hostName, port, err
|
||||
}
|
||||
|
||||
// NormalizeRegistry makes sure variations of DockerHubs registry
|
||||
func NormalizeRegistry(registry string) (string, error) {
|
||||
hostName, port, err := ConvertToHostname(registry)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if hostName == "registry-1.docker.io" || hostName == "docker.io" {
|
||||
hostName = "index.docker.io"
|
||||
}
|
||||
|
||||
if port != "" {
|
||||
return fmt.Sprintf("%s:%s", hostName, port), nil
|
||||
}
|
||||
return hostName, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue