// New returns the instance of STI builder strategy for the given config. // If the layeredBuilder parameter is specified, then the builder provided will // be used for the case that the base Docker image does not have 'tar' or 'bash' // installed. func New(req *api.Config, overrides build.Overrides) (*STI, error) { docker, err := dockerpkg.New(req.DockerConfig, req.PullAuthentication) if err != nil { return nil, err } var incrementalDocker dockerpkg.Docker if req.Incremental { incrementalDocker, err = dockerpkg.New(req.DockerConfig, req.IncrementalAuthentication) if err != nil { return nil, err } } inst := scripts.NewInstaller(req.BuilderImage, req.ScriptsURL, docker, req.PullAuthentication) b := &STI{ installer: inst, config: req, docker: docker, incrementalDocker: incrementalDocker, git: git.New(), fs: util.NewFileSystem(), tar: tar.New(), callbackInvoker: util.NewCallbackInvoker(), requiredScripts: []string{api.Assemble, api.Run}, optionalScripts: []string{api.SaveArtifacts}, externalScripts: map[string]bool{}, installedScripts: map[string]bool{}, scriptsURL: map[string]string{}, } // The sources are downloaded using the GIT downloader. // TODO: Add more SCM in future. // TODO: explicit decision made to customize processing for usage specifically vs. // leveraging overrides; also, we ultimately want to simplify s2i usage a good bit, // which would lead to replacing this quick short circuit (so this change is tactical) b.source = overrides.Downloader if b.source == nil && !req.Usage { downloader, sourceURL, err := scm.DownloaderForSource(req.Source, req.ForceCopy) if err != nil { return nil, err } b.source = downloader req.Source = sourceURL } b.garbage = &build.DefaultCleaner{b.fs, b.docker} b.layered, err = layered.New(req, b, overrides) // Set interfaces b.preparer = b // later on, if we support say .gitignore func in addition to .dockerignore func, setting // ignorer will be based on config setting b.ignorer = &ignore.DockerIgnorer{} b.artifacts = b b.scripts = b b.postExecutor = b return b, err }
// New returns the instance of STI builder strategy for the given config. // If the layeredBuilder parameter is specified, then the builder provided will // be used for the case that the base Docker image does not have 'tar' or 'bash' // installed. func New(req *api.Config, overrides build.Overrides) (*STI, error) { docker, err := dockerpkg.New(req.DockerConfig, req.PullAuthentication) if err != nil { return nil, err } var incrementalDocker dockerpkg.Docker if req.Incremental { incrementalDocker, err = dockerpkg.New(req.DockerConfig, req.IncrementalAuthentication) if err != nil { return nil, err } } inst := scripts.NewInstaller(req.BuilderImage, req.ScriptsURL, docker, req.PullAuthentication) b := &STI{ installer: inst, config: req, docker: docker, incrementalDocker: incrementalDocker, git: git.New(), fs: util.NewFileSystem(), tar: tar.New(), callbackInvoker: util.NewCallbackInvoker(), requiredScripts: []string{api.Assemble, api.Run}, optionalScripts: []string{api.SaveArtifacts}, externalScripts: map[string]bool{}, installedScripts: map[string]bool{}, scriptsURL: map[string]string{}, } // The sources are downloaded using the GIT downloader. // TODO: Add more SCM in future. b.source = overrides.Downloader if b.source == nil { downloader, sourceURL, err := scm.DownloaderForSource(req.Source) if err != nil { return nil, err } b.source = downloader req.Source = sourceURL } b.garbage = &build.DefaultCleaner{b.fs, b.docker} b.layered, err = layered.New(req, b, overrides) // Set interfaces b.preparer = b // later on, if we support say .gitignore func in addition to .dockerignore func, setting // ignorer will be based on config setting b.ignorer = &ignore.DockerIgnorer{} b.artifacts = b b.scripts = b b.postExecutor = b return b, err }
// GetBuilderImage processes the config and performs operations necessary to make // the Docker image specified as BuilderImage available locally. // It returns information about the base image, containing metadata necessary // for choosing the right STI build strategy. func GetBuilderImage(config *api.Config) (*docker.PullResult, error) { d, err := docker.New(config.DockerConfig, config.PullAuthentication) result := docker.PullResult{} if err != nil { return nil, err } var image *dockerclient.Image if config.ForcePull { image, err = d.PullImage(config.BuilderImage) if err != nil { glog.Warningf("An error occurred when pulling %s: %v. Attempting to use local image.", config.BuilderImage, err) image, err = d.CheckImage(config.BuilderImage) } } else { image, err = d.CheckAndPullImage(config.BuilderImage) } if err != nil { return nil, err } result.Image = image result.OnBuild = d.IsImageOnBuild(config.BuilderImage) if err = checkAllowedUser(d, config, result.OnBuild); err != nil { return nil, err } return &result, nil }
// New returns the instance of STI builder strategy for the given config. // If the layeredBuilder parameter is specified, then the builder provided will // be used for the case that the base Docker image does not have 'tar' or 'bash' // installed. func New(req *api.Config) (*STI, error) { docker, err := docker.New(req.DockerConfig, req.PullAuthentication) if err != nil { return nil, err } inst := scripts.NewInstaller(req.BuilderImage, req.ScriptsURL, docker, req.PullAuthentication) b := &STI{ installer: inst, config: req, docker: docker, git: git.New(), fs: util.NewFileSystem(), tar: tar.New(), callbackInvoker: util.NewCallbackInvoker(), requiredScripts: []string{api.Assemble, api.Run}, optionalScripts: []string{api.SaveArtifacts}, externalScripts: map[string]bool{}, installedScripts: map[string]bool{}, scriptsURL: map[string]string{}, } // The sources are downloaded using the GIT downloader. // TODO: Add more SCM in future. b.source = &git.Clone{b.git, b.fs} b.garbage = &build.DefaultCleaner{b.fs, b.docker} b.layered, err = layered.New(req, b) // Set interfaces b.preparer = b b.artifacts = b b.scripts = b b.postExecutor = b return b, err }
// New returns a new instance of OnBuild builder func New(config *api.Config, overrides build.Overrides) (*OnBuild, error) { dockerHandler, err := docker.New(config.DockerConfig, config.PullAuthentication) if err != nil { return nil, err } b := &OnBuild{ docker: dockerHandler, git: git.New(), fs: util.NewFileSystem(), tar: tar.New(), } // Use STI Prepare() and download the 'run' script optionally. s, err := sti.New(config, overrides) s.SetScripts([]string{}, []string{api.Assemble, api.Run}) downloader := overrides.Downloader if downloader == nil { d, sourceURL, err := scm.DownloaderForSource(config.Source) if err != nil { return nil, err } downloader = d config.Source = sourceURL } b.source = onBuildSourceHandler{ Downloader: downloader, Preparer: s, Ignorer: &ignore.DockerIgnorer{}, } b.garbage = &build.DefaultCleaner{b.fs, b.docker} return b, nil }
// New creates a DockerRunner for executing the methods associated with running // the produced image in a docker container for verification purposes. func New(config *api.Config) (*DockerRunner, error) { client, err := docker.New(config.DockerConfig, config.PullAuthentication) if err != nil { glog.Errorf("Failed to connect to Docker daemon: %v", err) return nil, err } return &DockerRunner{client}, nil }
// Create the DockerRunning struct for executing the methods assoicated with running // the produced image in a docker container for verification purposes. func New(config *api.Config) (*DockerRunner, error) { cc, ccerr := docker.New(config.DockerConfig, config.PullAuthentication) if ccerr != nil { glog.Errorf("Create of Docker Container client failed with %v \n", ccerr) return nil, ccerr } dr := &DockerRunner{ ContainerClient: cc, } return dr, nil }
func New(config *api.Config, scripts build.ScriptsHandler, overrides build.Overrides) (*Layered, error) { d, err := docker.New(config.DockerConfig, config.PullAuthentication) if err != nil { return nil, err } return &Layered{ docker: d, config: config, fs: util.NewFileSystem(), tar: tar.New(), scripts: scripts, }, nil }
// New creates a Layered builder. func New(config *api.Config, fs util.FileSystem, scripts build.ScriptsHandler, overrides build.Overrides) (*Layered, error) { d, err := docker.New(config.DockerConfig, config.PullAuthentication) if err != nil { return nil, err } tarHandler := tar.New(fs) tarHandler.SetExclusionPattern(regexp.MustCompile(config.ExcludeRegExp)) return &Layered{ docker: d, config: config, fs: fs, tar: tarHandler, scripts: scripts, }, nil }
// 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 }
// GetBuilderImage processes the config and performs operations necessary to make // the Docker image specified as BuilderImage available locally. // It returns information about the base image, containing metadata necessary // for choosing the right STI build strategy. func GetBuilderImage(config *api.Config) (*docker.PullResult, error) { d, err := docker.New(config.DockerConfig, config.PullAuthentication) result := docker.PullResult{} if err != nil { return nil, err } var image *dockerclient.Image if config.ForcePull { image, err = d.PullImage(config.BuilderImage) } else { image, err = d.CheckAndPull(config.BuilderImage) } if err != nil { return nil, err } result.Image = image result.OnBuild = d.IsImageOnBuild(config.BuilderImage) return &result, nil }
// New returns a new instance of OnBuild builder func New(config *api.Config) (*OnBuild, error) { dockerHandler, err := docker.New(config.DockerConfig, config.PullAuthentication) if err != nil { return nil, err } b := &OnBuild{ docker: dockerHandler, git: git.New(), fs: util.NewFileSystem(), tar: tar.New(), } // Use STI Prepare() and download the 'run' script optionally. s, err := sti.New(config) s.SetScripts([]string{}, []string{api.Assemble, api.Run}) b.source = onBuildSourceHandler{ &git.Clone{b.git, b.fs}, s, } b.garbage = &build.DefaultCleaner{b.fs, b.docker} return b, nil }
// New returns the instance of STI builder strategy for the given config. // If the layeredBuilder parameter is specified, then the builder provided will // be used for the case that the base Docker image does not have 'tar' or 'bash' // installed. func New(config *api.Config, overrides build.Overrides) (*STI, error) { docker, err := dockerpkg.New(config.DockerConfig, config.PullAuthentication) if err != nil { return nil, err } var incrementalDocker dockerpkg.Docker if config.Incremental { incrementalDocker, err = dockerpkg.New(config.DockerConfig, config.IncrementalAuthentication) if err != nil { return nil, err } } inst := scripts.NewInstaller(config.BuilderImage, config.ScriptsURL, config.ScriptDownloadProxyConfig, docker, config.PullAuthentication) tarHandler := tar.New() tarHandler.SetExclusionPattern(regexp.MustCompile(config.ExcludeRegExp)) builder := &STI{ installer: inst, config: config, docker: docker, incrementalDocker: incrementalDocker, git: git.New(), fs: util.NewFileSystem(), tar: tarHandler, callbackInvoker: util.NewCallbackInvoker(), requiredScripts: []string{api.Assemble, api.Run}, optionalScripts: []string{api.SaveArtifacts}, optionalRuntimeScripts: []string{api.AssembleRuntime}, externalScripts: map[string]bool{}, installedScripts: map[string]bool{}, scriptsURL: map[string]string{}, } if len(config.RuntimeImage) > 0 { builder.runtimeInstaller = scripts.NewInstaller(config.RuntimeImage, config.ScriptsURL, config.ScriptDownloadProxyConfig, docker, config.PullAuthentication) builder.runtimeDocker, err = dockerpkg.New(config.DockerConfig, config.RuntimeAuthentication) if err != nil { return builder, err } } // The sources are downloaded using the Git downloader. // TODO: Add more SCM in future. // TODO: explicit decision made to customize processing for usage specifically vs. // leveraging overrides; also, we ultimately want to simplify s2i usage a good bit, // which would lead to replacing this quick short circuit (so this change is tactical) builder.source = overrides.Downloader if builder.source == nil && !config.Usage { downloader, sourceURL, err := scm.DownloaderForSource(config.Source, config.ForceCopy) if err != nil { return nil, err } builder.source = downloader config.Source = sourceURL } builder.garbage = build.NewDefaultCleaner(builder.fs, builder.docker) builder.layered, err = layered.New(config, builder, overrides) // Set interfaces builder.preparer = builder // later on, if we support say .gitignore func in addition to .dockerignore func, setting // ignorer will be based on config setting builder.ignorer = &ignore.DockerIgnorer{} builder.artifacts = builder builder.scripts = builder builder.postExecutor = builder builder.initPostExecutorSteps() return builder, err }