{"action":"created","comment":{"url":"https://api.github.com/repos/docker/docker/pulls/comments/30159750","id":30159750,"diff_hunk":"@@ -121,24 +124,52 @@ func Build(d *daemon.Daemon, buildConfig *Config) error {\n \t} else if urlutil.IsURL(buildConfig.RemoteURL) {\n \t\tf, err := httputils.Download(buildConfig.RemoteURL)\n \t\tif err != nil {\n-\t\t\treturn err\n+\t\t\treturn fmt.Errorf(\"Error downloading remote context %s: %s\\n\", buildConfig.RemoteURL, err)\n \t\t}\n \t\tdefer f.Body.Close()\n-\t\tdockerFile, err := ioutil.ReadAll(f.Body)\n-\t\tif err != nil {\n-\t\t\treturn err\n+\n+\t\tplen := int(f.ContentLength)\n+\t\tif plen > maxPreambleLength {\n+\t\t\tplen = maxPreambleLength\n+\t\t}\n+\t\t// Some web servers will use application/octet-stream as the default\n+\t\t// content type for files without an extension (e.g. 'Dockerfile')\n+\t\t// so if we receive this value we better check for text content\n+\t\tct := f.Header.Get(\"Content-Type\")\n+\t\tpreambleR := bufio.NewReaderSize(f.Body, plen)\n+\t\tif len(ct) == 0 || ct == httputils.MimeTypes.OctetStream {\n+\t\t\tct, _, err = httputils.DetectContentType(preambleR, plen)\n+\t\t\tif err != nil {\n+\t\t\t\treturn fmt.Errorf(\"Error detecting content type for remote %s: %s\\n\", buildConfig.RemoteURL, err)\n+\t\t\t}\n+\t\t}\n+\t\tcontentType := selectAcceptableMIME(ct)\n+\t\tif len(contentType) == 0 {\n+\t\t\treturn fmt.Errorf(\"builder: Unacceptable content-type %s at remote context %s\", ct, buildConfig.RemoteURL)\n \t\t}\n \n-\t\t// When we're downloading just a Dockerfile put it in\n-\t\t// the default name - don't allow the client to move/specify it\n-\t\tbuildConfig.DockerfileName = api.DefaultDockerfileName\n+\t\tif contentType == httputils.MimeTypes.TextPlain {\n+\t\t\tdockerFile, err := ioutil.ReadAll(f.Body)\n+\t\t\tif err != nil {\n+\t\t\t\treturn err\n+\t\t\t}\n \n-\t\tc, err := archive.Generate(buildConfig.DockerfileName, string(dockerFile))\n-\t\tif err != nil {\n-\t\t\treturn err\n+\t\t\t// When we're downloading just a Dockerfile put it in\n+\t\t\t// the default name - don't allow the client to move/specify it\n+\t\t\tbuildConfig.DockerfileName = api.DefaultDockerfileName\n+\n+\t\t\tc, err := archive.Generate(buildConfig.DockerfileName, string(dockerFile))\n+\t\t\tif err != nil {\n+\t\t\t\treturn err\n+\t\t\t}\n+\t\t\tcontext = c\n+\t\t} else {\n+\t\t\t// Pass through - this is a pre-packaged context, presumably\n+\t\t\t// with a Dockerfile with the right name inside it.\n+\t\t\tcontext = ioutil.NopCloser(io.MultiReader(preambleR, f.Body))","path":"builder/job.go","position":73,"original_position":73,"commit_id":"0ed09b61a3e004e22c79248a4923876c33a0106b","original_commit_id":"0ed09b61a3e004e22c79248a4923876c33a0106b","user":{"login":"duglin","id":1944671,"avatar_url":"https://avatars.githubusercontent.com/u/1944671?v=3","gravatar_id":"","url":"https://api.github.com/users/duglin","html_url":"https://github.com/duglin","followers_url":"https://api.github.com/users/duglin/followers","following_url":"https://api.github.com/users/duglin/following{/other_user}","gists_url":"https://api.github.com/users/duglin/gists{/gist_id}","starred_url":"https://api.github.com/users/duglin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duglin/subscriptions","organizations_url":"https://api.github.com/users/duglin/orgs","repos_url":"https://api.github.com/users/duglin/repos","events_url":"https://api.github.com/users/duglin/events{/privacy}","received_events_url":"https://api.github.com/users/duglin/received_events","type":"User","site_admin":false},"body":"The preambleR variable is only used here, yet in on line 152 we read from `f.Body`. Won't that read be missing the preambleR data if ever invoked?","created_at":"2015-05-12T17:41:50Z","updated_at":"2015-05-12T17:41:50Z","html_url":"https://github.com/docker/docker/pull/12099#discussion_r30159750","pull_request_url":"https://api.github.com/repos/docker/docker/pulls/12099","_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/comments/30159750"},"html":{"href":"https://github.com/docker/docker/pull/12099#discussion_r30159750"},"pull_request":{"href":"https://api.github.com/repos/docker/docker/pulls/12099"}}},"pull_request":{"url":"https://api.github.com/repos/docker/docker/pulls/12099","id":32657868,"html_url":"https://github.com/docker/docker/pull/12099","diff_url":"https://github.com/docker/docker/pull/12099.diff","patch_url":"https://github.com/docker/docker/pull/12099.patch","issue_url":"https://api.github.com/repos/docker/docker/issues/12099","number":12099,"state":"open","locked":false,"title":"Handle binary remote contexts when creating builder jobs.","user":{"login":"moysesb","id":3748237,"avatar_url":"https://avatars.githubusercontent.com/u/3748237?v=3","gravatar_id":"","url":"https://api.github.com/users/moysesb","html_url":"https://github.com/moysesb","followers_url":"https://api.github.com/users/moysesb/followers","following_url":"https://api.github.com/users/moysesb/following{/other_user}","gists_url":"https://api.github.com/users/moysesb/gists{/gist_id}","starred_url":"https://api.github.com/users/moysesb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moysesb/subscriptions","organizations_url":"https://api.github.com/users/moysesb/orgs","repos_url":"https://api.github.com/users/moysesb/repos","events_url":"https://api.github.com/users/moysesb/events{/privacy}","received_events_url":"https://api.github.com/users/moysesb/received_events","type":"User","site_admin":false},"body":"Add support for fetching compressed remote contexts from the `remote` query parameter in `/build`, as described in #12078.\r\n\r\nSigned-off-by: Moysés Borges <moysesb@gmail.com>\r\n\r\ncloses #12078 ","created_at":"2015-04-06T01:27:54Z","updated_at":"2015-05-12T17:41:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"121126746aaf47ba7be5f89832c8d7f3c5be5735","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/docker/docker/pulls/12099/commits","review_comments_url":"https://api.github.com/repos/docker/docker/pulls/12099/comments","review_comment_url":"https://api.github.com/repos/docker/docker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/docker/issues/12099/comments","statuses_url":"https://api.github.com/repos/docker/docker/statuses/0ed09b61a3e004e22c79248a4923876c33a0106b","head":{"label":"moysesb:12078-binary_remote_context","ref":"12078-binary_remote_context","sha":"0ed09b61a3e004e22c79248a4923876c33a0106b","user":{"login":"moysesb","id":3748237,"avatar_url":"https://avatars.githubusercontent.com/u/3748237?v=3","gravatar_id":"","url":"https://api.github.com/users/moysesb","html_url":"https://github.com/moysesb","followers_url":"https://api.github.com/users/moysesb/followers","following_url":"https://api.github.com/users/moysesb/following{/other_user}","gists_url":"https://api.github.com/users/moysesb/gists{/gist_id}","starred_url":"https://api.github.com/users/moysesb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moysesb/subscriptions","organizations_url":"https://api.github.com/users/moysesb/orgs","repos_url":"https://api.github.com/users/moysesb/repos","events_url":"https://api.github.com/users/moysesb/events{/privacy}","received_events_url":"https://api.github.com/users/moysesb/received_events","type":"User","site_admin":false},"repo":{"id":33406425,"name":"docker","full_name":"moysesb/docker","owner":{"login":"moysesb","id":3748237,"avatar_url":"https://avatars.githubusercontent.com/u/3748237?v=3","gravatar_id":"","url":"https://api.github.com/users/moysesb","html_url":"https://github.com/moysesb","followers_url":"https://api.github.com/users/moysesb/followers","following_url":"https://api.github.com/users/moysesb/following{/other_user}","gists_url":"https://api.github.com/users/moysesb/gists{/gist_id}","starred_url":"https://api.github.com/users/moysesb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moysesb/subscriptions","organizations_url":"https://api.github.com/users/moysesb/orgs","repos_url":"https://api.github.com/users/moysesb/repos","events_url":"https://api.github.com/users/moysesb/events{/privacy}","received_events_url":"https://api.github.com/users/moysesb/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/moysesb/docker","description":"Docker - the open-source application container engine","fork":true,"url":"https://api.github.com/repos/moysesb/docker","forks_url":"https://api.github.com/repos/moysesb/docker/forks","keys_url":"https://api.github.com/repos/moysesb/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/moysesb/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/moysesb/docker/teams","hooks_url":"https://api.github.com/repos/moysesb/docker/hooks","issue_events_url":"https://api.github.com/repos/moysesb/docker/issues/events{/number}","events_url":"https://api.github.com/repos/moysesb/docker/events","assignees_url":"https://api.github.com/repos/moysesb/docker/assignees{/user}","branches_url":"https://api.github.com/repos/moysesb/docker/branches{/branch}","tags_url":"https://api.github.com/repos/moysesb/docker/tags","blobs_url":"https://api.github.com/repos/moysesb/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/moysesb/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/moysesb/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/moysesb/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/moysesb/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/moysesb/docker/languages","stargazers_url":"https://api.github.com/repos/moysesb/docker/stargazers","contributors_url":"https://api.github.com/repos/moysesb/docker/contributors","subscribers_url":"https://api.github.com/repos/moysesb/docker/subscribers","subscription_url":"https://api.github.com/repos/moysesb/docker/subscription","commits_url":"https://api.github.com/repos/moysesb/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/moysesb/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/moysesb/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/moysesb/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/moysesb/docker/contents/{+path}","compare_url":"https://api.github.com/repos/moysesb/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/moysesb/docker/merges","archive_url":"https://api.github.com/repos/moysesb/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/moysesb/docker/downloads","issues_url":"https://api.github.com/repos/moysesb/docker/issues{/number}","pulls_url":"https://api.github.com/repos/moysesb/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/moysesb/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/moysesb/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/moysesb/docker/labels{/name}","releases_url":"https://api.github.com/repos/moysesb/docker/releases{/id}","created_at":"2015-04-04T13:30:08Z","updated_at":"2015-04-24T11:16:29Z","pushed_at":"2015-05-08T23:56:24Z","git_url":"git://github.com/moysesb/docker.git","ssh_url":"git@github.com:moysesb/docker.git","clone_url":"https://github.com/moysesb/docker.git","svn_url":"https://github.com/moysesb/docker","homepage":"http://www.docker.com","size":53942,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"12078-binary_remote_context"}},"base":{"label":"docker:master","ref":"master","sha":"3697dddc0d913d0d4468a1570408390a336d8b7b","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":7691631,"name":"docker","full_name":"docker/docker","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/docker","description":"Docker - the open-source application container engine","fork":false,"url":"https://api.github.com/repos/docker/docker","forks_url":"https://api.github.com/repos/docker/docker/forks","keys_url":"https://api.github.com/repos/docker/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/docker/teams","hooks_url":"https://api.github.com/repos/docker/docker/hooks","issue_events_url":"https://api.github.com/repos/docker/docker/issues/events{/number}","events_url":"https://api.github.com/repos/docker/docker/events","assignees_url":"https://api.github.com/repos/docker/docker/assignees{/user}","branches_url":"https://api.github.com/repos/docker/docker/branches{/branch}","tags_url":"https://api.github.com/repos/docker/docker/tags","blobs_url":"https://api.github.com/repos/docker/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/docker/languages","stargazers_url":"https://api.github.com/repos/docker/docker/stargazers","contributors_url":"https://api.github.com/repos/docker/docker/contributors","subscribers_url":"https://api.github.com/repos/docker/docker/subscribers","subscription_url":"https://api.github.com/repos/docker/docker/subscription","commits_url":"https://api.github.com/repos/docker/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/docker/contents/{+path}","compare_url":"https://api.github.com/repos/docker/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/docker/merges","archive_url":"https://api.github.com/repos/docker/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/docker/downloads","issues_url":"https://api.github.com/repos/docker/docker/issues{/number}","pulls_url":"https://api.github.com/repos/docker/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/docker/labels{/name}","releases_url":"https://api.github.com/repos/docker/docker/releases{/id}","created_at":"2013-01-18T18:10:57Z","updated_at":"2015-05-12T17:29:09Z","pushed_at":"2015-05-12T17:32:01Z","git_url":"git://github.com/docker/docker.git","ssh_url":"git@github.com:docker/docker.git","clone_url":"https://github.com/docker/docker.git","svn_url":"https://github.com/docker/docker","homepage":"http://www.docker.com","size":205336,"stargazers_count":21570,"watchers_count":21570,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5057,"mirror_url":null,"open_issues_count":975,"forks":5057,"open_issues":975,"watchers":21570,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/12099"},"html":{"href":"https://github.com/docker/docker/pull/12099"},"issue":{"href":"https://api.github.com/repos/docker/docker/issues/12099"},"comments":{"href":"https://api.github.com/repos/docker/docker/issues/12099/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/docker/pulls/12099/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/docker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/docker/pulls/12099/commits"},"statuses":{"href":"https://api.github.com/repos/docker/docker/statuses/0ed09b61a3e004e22c79248a4923876c33a0106b"}}}}