job/osbuild: move utility the container package
Extract a helper method that parses the reference and applies defaults, i.e. registry and path, and move it to the contaier package.
This commit is contained in:
parent
3231aabbc0
commit
64a3aac895
2 changed files with 21 additions and 14 deletions
|
|
@ -208,25 +208,13 @@ func uploadToS3(a *awscloud.AWS, outputDirectory, exportPath, bucket, key, filen
|
|||
}
|
||||
|
||||
func (impl *OSBuildJobImpl) getContainerClient(destination string, targetOptions *target.ContainerTargetOptions) (*container.Client, error) {
|
||||
useImpl := false
|
||||
i := strings.IndexRune(destination, '/')
|
||||
if i == -1 || (!strings.ContainsAny(destination[:i], ".:") && destination[:i] != "localhost") {
|
||||
if impl.ContainersConfig.Domain != "" {
|
||||
base := impl.ContainersConfig.Domain
|
||||
if impl.ContainersConfig.Account != "" {
|
||||
base = fmt.Sprintf("%s/%s", base, impl.ContainersConfig.Account)
|
||||
}
|
||||
destination = fmt.Sprintf("%s/%s", base, destination)
|
||||
useImpl = true
|
||||
}
|
||||
}
|
||||
|
||||
destination, appliedDefaults := container.ApplyDefaultDomainPath(destination, impl.ContainersConfig.Domain, impl.ContainersConfig.Account)
|
||||
client, err := container.NewClient(destination)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if useImpl {
|
||||
if appliedDefaults {
|
||||
if impl.ContainersConfig.CertPath != "" {
|
||||
client.SetDockerCertPath(impl.ContainersConfig.CertPath)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,25 @@ func GetDefaultAuthFile() string {
|
|||
return filepath.FromSlash("/var/empty/containers-auth.json")
|
||||
}
|
||||
|
||||
// ApplyDefaultPath checks if the target includes a domain and if it doesn't adds the default ones
|
||||
// to the returned string. If also returns a bool indicating whether the defaults were applied
|
||||
func ApplyDefaultDomainPath(target, defaultDomain, defaultPath string) (string, bool) {
|
||||
appliedDefaults := false
|
||||
i := strings.IndexRune(target, '/')
|
||||
if i == -1 || (!strings.ContainsAny(target[:i], ".:") && target[:i] != "localhost") {
|
||||
if defaultDomain != "" {
|
||||
base := defaultDomain
|
||||
if defaultPath != "" {
|
||||
base = fmt.Sprintf("%s/%s", base, defaultPath)
|
||||
}
|
||||
target = fmt.Sprintf("%s/%s", base, target)
|
||||
appliedDefaults = true
|
||||
}
|
||||
}
|
||||
|
||||
return target, appliedDefaults
|
||||
}
|
||||
|
||||
// A Client to interact with the given Target object at a
|
||||
// container registry, like e.g. uploading an image to.
|
||||
// All mentioned defaults are only set when using the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue