// GenerateConfigFromLabels generates the S2I Config struct from the Docker // image labels. func GenerateConfigFromLabels(image string, config *api.Config) error { d, err := docker.New(config.DockerConfig, config.PullAuthentication) if err != nil { return err } var source *dockerclient.Image if config.ForcePull { source, err = d.PullImage(image) } else { source, err = d.CheckAndPullImage(image) } if err != nil { return err } if builderVersion, ok := source.Config.Labels["io.openshift.builder-version"]; ok { config.BuilderImageVersion = builderVersion config.BuilderBaseImageVersion = source.Config.Labels["io.openshift.builder-base-version"] } config.ScriptsURL = source.Config.Labels[api.DefaultNamespace+"scripts-url"] if len(config.ScriptsURL) == 0 { // FIXME: Backward compatibility config.ScriptsURL = source.Config.Labels["io.s2i.scripts-url"] } config.Description = source.Config.Labels[api.KubernetesNamespace+"description"] config.DisplayName = source.Config.Labels[api.KubernetesNamespace+"display-name"] if builder, ok := source.Config.Labels[api.DefaultNamespace+"build.image"]; ok { config.BuilderImage = builder } else { return fmt.Errorf("Required label %q not found in image", api.DefaultNamespace+"build.image") } if repo, ok := source.Config.Labels[api.DefaultNamespace+"build.source-location"]; ok { config.Source = repo } else { return fmt.Errorf("Required label %q not found in image", api.DefaultNamespace+"source-location") } config.ContextDir = source.Config.Labels[api.DefaultNamespace+"build.source-context-dir"] config.Ref = source.Config.Labels[api.DefaultNamespace+"build.commit.ref"] return nil }
// GenerateConfigFromLabels generates the S2I Config struct from the Docker // image labels. func GenerateConfigFromLabels(config *api.Config, metadata *docker.PullResult) error { if config == nil { return errors.New("config must be provided to GenerateConfigFromLabels") } if metadata == nil { return errors.New("image metadata must be provided to GenerateConfigFromLabels") } labels := metadata.Image.Config.Labels if builderVersion, ok := labels["io.openshift.builder-version"]; ok { config.BuilderImageVersion = builderVersion config.BuilderBaseImageVersion = labels["io.openshift.builder-base-version"] } config.ScriptsURL = labels[api.DefaultNamespace+"scripts-url"] if len(config.ScriptsURL) == 0 { // FIXME: Backward compatibility config.ScriptsURL = labels["io.s2i.scripts-url"] } config.Description = labels[api.KubernetesNamespace+"description"] config.DisplayName = labels[api.KubernetesNamespace+"display-name"] if builder, ok := labels[api.DefaultNamespace+"build.image"]; ok { config.BuilderImage = builder } else { return fmt.Errorf("Required label %q not found in image", api.DefaultNamespace+"build.image") } if repo, ok := labels[api.DefaultNamespace+"build.source-location"]; ok { config.Source = repo } else { return fmt.Errorf("Required label %q not found in image", api.DefaultNamespace+"source-location") } config.ContextDir = labels[api.DefaultNamespace+"build.source-context-dir"] config.Ref = labels[api.DefaultNamespace+"build.commit.ref"] return nil }
// GenerateConfigFromLabels generates the S2I Config struct from the Docker // image labels. func GenerateConfigFromLabels(config *api.Config) error { result, err := docker.GetBuilderImage(config) if err != nil { return err } labels := result.Image.Config.Labels if builderVersion, ok := labels["io.openshift.builder-version"]; ok { config.BuilderImageVersion = builderVersion config.BuilderBaseImageVersion = labels["io.openshift.builder-base-version"] } config.ScriptsURL = labels[api.DefaultNamespace+"scripts-url"] if len(config.ScriptsURL) == 0 { // FIXME: Backward compatibility config.ScriptsURL = labels["io.s2i.scripts-url"] } config.Description = labels[api.KubernetesNamespace+"description"] config.DisplayName = labels[api.KubernetesNamespace+"display-name"] if builder, ok := labels[api.DefaultNamespace+"build.image"]; ok { config.BuilderImage = builder } else { return fmt.Errorf("Required label %q not found in image", api.DefaultNamespace+"build.image") } if repo, ok := labels[api.DefaultNamespace+"build.source-location"]; ok { config.Source = repo } else { return fmt.Errorf("Required label %q not found in image", api.DefaultNamespace+"source-location") } config.ContextDir = labels[api.DefaultNamespace+"build.source-context-dir"] config.Ref = labels[api.DefaultNamespace+"build.commit.ref"] return nil }