{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/source-to-image/pulls/comments/24947499","id":24947499,"diff_hunk":"@@ -0,0 +1,173 @@\n+package scripts\n+\n+import (\n+\t\"net/url\"\n+\t\"path/filepath\"\n+\n+\t\"github.com/golang/glog\"\n+\n+\t\"github.com/openshift/source-to-image/pkg/api\"\n+\t\"github.com/openshift/source-to-image/pkg/docker\"\n+\t\"github.com/openshift/source-to-image/pkg/errors\"\n+\t\"github.com/openshift/source-to-image/pkg/util\"\n+)\n+\n+// InstallResult structure describes the result of install operation\n+type InstallResult struct {\n+\n+\t// Downloaded describes if download operation happened, this will be true for\n+\t// external scripts, but false for scripts from inside the image\n+\tDownloaded bool\n+\n+\t// Installed describes if script was installed to upload directory\n+\tInstalled bool\n+\n+\t// Error last error encountered during install operation\n+\tError error\n+}\n+\n+// Installer interface is responsible for installing scripts needed to run the build\n+type Installer interface {\n+\tInstallRequired(scripts []api.Script, dstDir string) (map[api.Script]*InstallResult, error)\n+\tInstallOptional(scripts []api.Script, dstDir string) map[api.Script]*InstallResult\n+}\n+\n+// NewInstaller returns a new instance of the default Installer implementation\n+func NewInstaller(image string, scriptsURL string, docker docker.Docker) Installer {\n+\treturn &installer{\n+\t\timage:      image,\n+\t\tscriptsURL: scriptsURL,\n+\t\tdocker:     docker,\n+\t\tdownloader: NewDownloader(),\n+\t\tfs:         util.NewFileSystem(),\n+\t}\n+}\n+\n+type installer struct {\n+\timage      string\n+\tscriptsURL string\n+\tdocker     docker.Docker\n+\tdownloader Downloader\n+\tfs         util.FileSystem\n+}\n+\n+// InstallRequired downloads and installs required scripts into dstDir, the result is a\n+// map of scripts with detailed information about each of the scripts install process\n+// with error if installing some of them failed\n+func (i *installer) InstallRequired(scripts []api.Script, dstDir string) (results map[api.Script]*InstallResult, err error) {\n+\tresults = i.run(scripts, dstDir)\n+\tfailedScripts := []api.Script{}\n+\tfor script, result := range results {\n+\t\tif !result.Installed && result.Error != nil {\n+\t\t\tfailedScripts = append(failedScripts, script)\n+\t\t}\n+\t}\n+\tif len(failedScripts) > 0 {\n+\t\terr = errors.NewInstallRequiredError(failedScripts)\n+\t}\n+\n+\treturn\n+}\n+\n+// InstallOptional downloads and installs a set of scripts into dstDir, the result is a\n+// map of scripts with detailed information about each of the scripts install process\n+func (i *installer) InstallOptional(scripts []api.Script, dstDir string) map[api.Script]*InstallResult {\n+\treturn i.run(scripts, dstDir)\n+}\n+\n+func (i *installer) run(scripts []api.Script, dstDir string) map[api.Script]*InstallResult {\n+\tresults := make(map[api.Script]*InstallResult)\n+\tif len(scripts) == 0 {\n+\t\treturn results\n+\t}\n+\tfor _, script := range scripts {\n+\t\tresults[script] = &InstallResult{}\n+\t}\n+\n+\t//get scripts from parameter URL\n+\tif i.scriptsURL != \"\" {\n+\t\ti.download(i.scriptsURL, results, filepath.Join(dstDir, string(api.DownloadedScripts)))\n+\t}\n+\n+\t// get scripts from default URL\n+\tdefaultURL, err := i.docker.GetScriptsURL(i.image)\n+\tif err == nil && defaultURL != \"\" {\n+\t\ti.download(defaultURL, results, filepath.Join(dstDir, string(api.DefaultScripts)))\n+\t} else {\n+\t\tglog.Warningf(\"Image %s does not contain STI_SCRIPTS_URL defined!\", i.image)\n+\t}\n+\n+\ti.install(results, dstDir)\n+\treturn results\n+}\n+\n+func (i *installer) download(scriptsURL string, scripts map[api.Script]*InstallResult, dstDir string) {\n+\tfor script, result := range scripts {\n+\t\turl, err := url.Parse(scriptsURL + \"/\" + string(script))\n+\t\tif err != nil {\n+\t\t\tresult.Error = err\n+\t\t\tcontinue\n+\t\t}\n+\n+\t\ttarget := filepath.Join(dstDir, string(script))\n+\t\tdownload, err := i.downloader.Download(url, target)\n+\t\t// make sure to have appropriate file permissions for downloaded scripts\n+\t\tif download && err == nil {\n+\t\t\tif err = i.fs.Chmod(target, 0700); err != nil {\n+\t\t\t\tresult.Error = err\n+\t\t\t}\n+\t\t}\n+\t\t// save information about download & error only if there's no  previous information\n+\t\tif !result.Downloaded {\n+\t\t\tresult.Downloaded = download\n+\t\t}\n+\t\tif result.Error == nil {\n+\t\t\tresult.Error = err\n+\t\t}\n+\t}\n+}\n+\n+func (i *installer) install(results map[api.Script]*InstallResult, dstDir string) {\n+\tfor script, result := range results {\n+\t\t// ignore not downloaded scripts\n+\t\tif !result.Downloaded && result.Error == nil {\n+\t\t\tresult.Installed = true\n+\t\t\tcontinue\n+\t\t}\n+\n+\t\tscriptPath := i.getScriptPath(script, dstDir)\n+\t\tif scriptPath == \"\" {\n+\t\t\tresult.Error = errors.NewInstallError(script)\n+\t\t\tcontinue\n+\t\t}\n+\t\tif err := i.fs.Rename(scriptPath, filepath.Join(dstDir, \"upload/scripts\", string(script))); err != nil {","path":"pkg/scripts/install.go","position":null,"original_position":143,"commit_id":"600dfc85d08f8cd94694fd76a0c82c995cf80206","original_commit_id":"84748f1038f119cd472fc68865e530e990f813c1","user":{"login":"soltysh","id":576341,"avatar_url":"https://avatars.githubusercontent.com/u/576341?v=3","gravatar_id":"","url":"https://api.github.com/users/soltysh","html_url":"https://github.com/soltysh","followers_url":"https://api.github.com/users/soltysh/followers","following_url":"https://api.github.com/users/soltysh/following{/other_user}","gists_url":"https://api.github.com/users/soltysh/gists{/gist_id}","starred_url":"https://api.github.com/users/soltysh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soltysh/subscriptions","organizations_url":"https://api.github.com/users/soltysh/orgs","repos_url":"https://api.github.com/users/soltysh/repos","events_url":"https://api.github.com/users/soltysh/events{/privacy}","received_events_url":"https://api.github.com/users/soltysh/received_events","type":"User","site_admin":false},"body":"This is the actual install part, we're picking a script and we're moving it to `upload` directory. Without it you won't get any scripts uploaded to builder image.","created_at":"2015-02-18T22:28:34Z","updated_at":"2015-02-18T22:28:34Z","html_url":"https://github.com/openshift/source-to-image/pull/129#discussion_r24947499","pull_request_url":"https://api.github.com/repos/openshift/source-to-image/pulls/129","_links":{"self":{"href":"https://api.github.com/repos/openshift/source-to-image/pulls/comments/24947499"},"html":{"href":"https://github.com/openshift/source-to-image/pull/129#discussion_r24947499"},"pull_request":{"href":"https://api.github.com/repos/openshift/source-to-image/pulls/129"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/source-to-image/pulls/129","id":29458041,"html_url":"https://github.com/openshift/source-to-image/pull/129","diff_url":"https://github.com/openshift/source-to-image/pull/129.diff","patch_url":"https://github.com/openshift/source-to-image/pull/129.patch","issue_url":"https://api.github.com/repos/openshift/source-to-image/issues/129","number":129,"state":"open","locked":false,"title":"[WIP] Refactoring installer to return more information about the download proess","user":{"login":"soltysh","id":576341,"avatar_url":"https://avatars.githubusercontent.com/u/576341?v=3","gravatar_id":"","url":"https://api.github.com/users/soltysh","html_url":"https://github.com/soltysh","followers_url":"https://api.github.com/users/soltysh/followers","following_url":"https://api.github.com/users/soltysh/following{/other_user}","gists_url":"https://api.github.com/users/soltysh/gists{/gist_id}","starred_url":"https://api.github.com/users/soltysh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soltysh/subscriptions","organizations_url":"https://api.github.com/users/soltysh/orgs","repos_url":"https://api.github.com/users/soltysh/repos","events_url":"https://api.github.com/users/soltysh/events{/privacy}","received_events_url":"https://api.github.com/users/soltysh/received_events","type":"User","site_admin":false},"body":"@mfojtik this is first run (works but still needs work esp. in places marked `TODO`), let me know what you think about it.","created_at":"2015-02-17T16:53:55Z","updated_at":"2015-02-18T22:28:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"26fa6d00c3a1a0485ea9c9016c8df4e715ee4afa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openshift/source-to-image/pulls/129/commits","review_comments_url":"https://api.github.com/repos/openshift/source-to-image/pulls/129/comments","review_comment_url":"https://api.github.com/repos/openshift/source-to-image/pulls/comments/{number}","comments_url":"https://api.github.com/repos/openshift/source-to-image/issues/129/comments","statuses_url":"https://api.github.com/repos/openshift/source-to-image/statuses/600dfc85d08f8cd94694fd76a0c82c995cf80206","head":{"label":"soltysh:refactor_download","ref":"refactor_download","sha":"600dfc85d08f8cd94694fd76a0c82c995cf80206","user":{"login":"soltysh","id":576341,"avatar_url":"https://avatars.githubusercontent.com/u/576341?v=3","gravatar_id":"","url":"https://api.github.com/users/soltysh","html_url":"https://github.com/soltysh","followers_url":"https://api.github.com/users/soltysh/followers","following_url":"https://api.github.com/users/soltysh/following{/other_user}","gists_url":"https://api.github.com/users/soltysh/gists{/gist_id}","starred_url":"https://api.github.com/users/soltysh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soltysh/subscriptions","organizations_url":"https://api.github.com/users/soltysh/orgs","repos_url":"https://api.github.com/users/soltysh/repos","events_url":"https://api.github.com/users/soltysh/events{/privacy}","received_events_url":"https://api.github.com/users/soltysh/received_events","type":"User","site_admin":false},"repo":{"id":25208363,"name":"source-to-image","full_name":"soltysh/source-to-image","owner":{"login":"soltysh","id":576341,"avatar_url":"https://avatars.githubusercontent.com/u/576341?v=3","gravatar_id":"","url":"https://api.github.com/users/soltysh","html_url":"https://github.com/soltysh","followers_url":"https://api.github.com/users/soltysh/followers","following_url":"https://api.github.com/users/soltysh/following{/other_user}","gists_url":"https://api.github.com/users/soltysh/gists{/gist_id}","starred_url":"https://api.github.com/users/soltysh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soltysh/subscriptions","organizations_url":"https://api.github.com/users/soltysh/orgs","repos_url":"https://api.github.com/users/soltysh/repos","events_url":"https://api.github.com/users/soltysh/events{/privacy}","received_events_url":"https://api.github.com/users/soltysh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/soltysh/source-to-image","description":"A tool for building/building artifacts from source and injecting into docker images","fork":true,"url":"https://api.github.com/repos/soltysh/source-to-image","forks_url":"https://api.github.com/repos/soltysh/source-to-image/forks","keys_url":"https://api.github.com/repos/soltysh/source-to-image/keys{/key_id}","collaborators_url":"https://api.github.com/repos/soltysh/source-to-image/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/soltysh/source-to-image/teams","hooks_url":"https://api.github.com/repos/soltysh/source-to-image/hooks","issue_events_url":"https://api.github.com/repos/soltysh/source-to-image/issues/events{/number}","events_url":"https://api.github.com/repos/soltysh/source-to-image/events","assignees_url":"https://api.github.com/repos/soltysh/source-to-image/assignees{/user}","branches_url":"https://api.github.com/repos/soltysh/source-to-image/branches{/branch}","tags_url":"https://api.github.com/repos/soltysh/source-to-image/tags","blobs_url":"https://api.github.com/repos/soltysh/source-to-image/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/soltysh/source-to-image/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/soltysh/source-to-image/git/refs{/sha}","trees_url":"https://api.github.com/repos/soltysh/source-to-image/git/trees{/sha}","statuses_url":"https://api.github.com/repos/soltysh/source-to-image/statuses/{sha}","languages_url":"https://api.github.com/repos/soltysh/source-to-image/languages","stargazers_url":"https://api.github.com/repos/soltysh/source-to-image/stargazers","contributors_url":"https://api.github.com/repos/soltysh/source-to-image/contributors","subscribers_url":"https://api.github.com/repos/soltysh/source-to-image/subscribers","subscription_url":"https://api.github.com/repos/soltysh/source-to-image/subscription","commits_url":"https://api.github.com/repos/soltysh/source-to-image/commits{/sha}","git_commits_url":"https://api.github.com/repos/soltysh/source-to-image/git/commits{/sha}","comments_url":"https://api.github.com/repos/soltysh/source-to-image/comments{/number}","issue_comment_url":"https://api.github.com/repos/soltysh/source-to-image/issues/comments/{number}","contents_url":"https://api.github.com/repos/soltysh/source-to-image/contents/{+path}","compare_url":"https://api.github.com/repos/soltysh/source-to-image/compare/{base}...{head}","merges_url":"https://api.github.com/repos/soltysh/source-to-image/merges","archive_url":"https://api.github.com/repos/soltysh/source-to-image/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/soltysh/source-to-image/downloads","issues_url":"https://api.github.com/repos/soltysh/source-to-image/issues{/number}","pulls_url":"https://api.github.com/repos/soltysh/source-to-image/pulls{/number}","milestones_url":"https://api.github.com/repos/soltysh/source-to-image/milestones{/number}","notifications_url":"https://api.github.com/repos/soltysh/source-to-image/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/soltysh/source-to-image/labels{/name}","releases_url":"https://api.github.com/repos/soltysh/source-to-image/releases{/id}","created_at":"2014-10-14T13:32:11Z","updated_at":"2015-02-16T20:03:38Z","pushed_at":"2015-02-18T21:40:35Z","git_url":"git://github.com/soltysh/source-to-image.git","ssh_url":"git@github.com:soltysh/source-to-image.git","clone_url":"https://github.com/soltysh/source-to-image.git","svn_url":"https://github.com/soltysh/source-to-image","homepage":"","size":946,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"openshift:master","ref":"master","sha":"d2c8661cf024ad774210a218b03717b2673d53e1","user":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"repo":{"id":16323162,"name":"source-to-image","full_name":"openshift/source-to-image","owner":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openshift/source-to-image","description":"A tool for building/building artifacts from source and injecting into docker images","fork":false,"url":"https://api.github.com/repos/openshift/source-to-image","forks_url":"https://api.github.com/repos/openshift/source-to-image/forks","keys_url":"https://api.github.com/repos/openshift/source-to-image/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openshift/source-to-image/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openshift/source-to-image/teams","hooks_url":"https://api.github.com/repos/openshift/source-to-image/hooks","issue_events_url":"https://api.github.com/repos/openshift/source-to-image/issues/events{/number}","events_url":"https://api.github.com/repos/openshift/source-to-image/events","assignees_url":"https://api.github.com/repos/openshift/source-to-image/assignees{/user}","branches_url":"https://api.github.com/repos/openshift/source-to-image/branches{/branch}","tags_url":"https://api.github.com/repos/openshift/source-to-image/tags","blobs_url":"https://api.github.com/repos/openshift/source-to-image/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openshift/source-to-image/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openshift/source-to-image/git/refs{/sha}","trees_url":"https://api.github.com/repos/openshift/source-to-image/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openshift/source-to-image/statuses/{sha}","languages_url":"https://api.github.com/repos/openshift/source-to-image/languages","stargazers_url":"https://api.github.com/repos/openshift/source-to-image/stargazers","contributors_url":"https://api.github.com/repos/openshift/source-to-image/contributors","subscribers_url":"https://api.github.com/repos/openshift/source-to-image/subscribers","subscription_url":"https://api.github.com/repos/openshift/source-to-image/subscription","commits_url":"https://api.github.com/repos/openshift/source-to-image/commits{/sha}","git_commits_url":"https://api.github.com/repos/openshift/source-to-image/git/commits{/sha}","comments_url":"https://api.github.com/repos/openshift/source-to-image/comments{/number}","issue_comment_url":"https://api.github.com/repos/openshift/source-to-image/issues/comments/{number}","contents_url":"https://api.github.com/repos/openshift/source-to-image/contents/{+path}","compare_url":"https://api.github.com/repos/openshift/source-to-image/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openshift/source-to-image/merges","archive_url":"https://api.github.com/repos/openshift/source-to-image/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openshift/source-to-image/downloads","issues_url":"https://api.github.com/repos/openshift/source-to-image/issues{/number}","pulls_url":"https://api.github.com/repos/openshift/source-to-image/pulls{/number}","milestones_url":"https://api.github.com/repos/openshift/source-to-image/milestones{/number}","notifications_url":"https://api.github.com/repos/openshift/source-to-image/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openshift/source-to-image/labels{/name}","releases_url":"https://api.github.com/repos/openshift/source-to-image/releases{/id}","created_at":"2014-01-28T19:32:40Z","updated_at":"2015-02-18T09:57:29Z","pushed_at":"2015-02-18T09:57:28Z","git_url":"git://github.com/openshift/source-to-image.git","ssh_url":"git@github.com:openshift/source-to-image.git","clone_url":"https://github.com/openshift/source-to-image.git","svn_url":"https://github.com/openshift/source-to-image","homepage":"","size":1695,"stargazers_count":64,"watchers_count":64,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":32,"mirror_url":null,"open_issues_count":11,"forks":32,"open_issues":11,"watchers":64,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/source-to-image/pulls/129"},"html":{"href":"https://github.com/openshift/source-to-image/pull/129"},"issue":{"href":"https://api.github.com/repos/openshift/source-to-image/issues/129"},"comments":{"href":"https://api.github.com/repos/openshift/source-to-image/issues/129/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/source-to-image/pulls/129/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/source-to-image/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/openshift/source-to-image/pulls/129/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/source-to-image/statuses/600dfc85d08f8cd94694fd76a0c82c995cf80206"}}}}