Просмотр исходного кода

Merge pull request #3298 from creack/add_arch_user_agent

Add arch/os info to user agent (Registry)
Victor Vieux 11 лет назад
Родитель
Сommit
3fe4d5477a
5 измененных файлов с 17 добавлено и 10 удалено
  1. 3 1
      graph.go
  2. 1 0
      image.go
  3. 2 0
      server.go
  4. 9 9
      utils/http.go
  5. 2 0
      version.go

+ 3 - 1
graph.go

@@ -10,6 +10,7 @@ import (
 	"os"
 	"path"
 	"path/filepath"
+	"runtime"
 	"strings"
 	"syscall"
 	"time"
@@ -131,7 +132,8 @@ func (graph *Graph) Create(layerData archive.Archive, container *Container, comm
 		DockerVersion: VERSION,
 		Author:        author,
 		Config:        config,
-		Architecture:  "x86_64",
+		Architecture:  runtime.GOARCH,
+		OS:            runtime.GOOS,
 	}
 	if container != nil {
 		img.Parent = container.Image

+ 1 - 0
image.go

@@ -28,6 +28,7 @@ type Image struct {
 	Author          string    `json:"author,omitempty"`
 	Config          *Config   `json:"config,omitempty"`
 	Architecture    string    `json:"architecture,omitempty"`
+	OS              string    `json:"os,omitempty"`
 	graph           *Graph
 	Size            int64
 }

+ 2 - 0
server.go

@@ -2018,6 +2018,8 @@ func (srv *Server) HTTPRequestFactory(metaHeaders map[string][]string) *utils.HT
 	httpVersion = append(httpVersion, &simpleVersionInfo{"go", v.Get("GoVersion")})
 	httpVersion = append(httpVersion, &simpleVersionInfo{"git-commit", v.Get("GitCommit")})
 	httpVersion = append(httpVersion, &simpleVersionInfo{"kernel", v.Get("KernelVersion")})
+	httpVersion = append(httpVersion, &simpleVersionInfo{"os", v.Get("Os")})
+	httpVersion = append(httpVersion, &simpleVersionInfo{"arch", v.Get("Arch")})
 	ud := utils.NewHTTPUserAgentDecorator(httpVersion...)
 	md := &utils.HTTPMetaHeadersDecorator{
 		Headers: metaHeaders,

+ 9 - 9
utils/http.go

@@ -76,9 +76,9 @@ type HTTPUserAgentDecorator struct {
 }
 
 func NewHTTPUserAgentDecorator(versions ...VersionInfo) HTTPRequestDecorator {
-	ret := new(HTTPUserAgentDecorator)
-	ret.versions = versions
-	return ret
+	return &HTTPUserAgentDecorator{
+		versions: versions,
+	}
 }
 
 func (h *HTTPUserAgentDecorator) ChangeRequest(req *http.Request) (newReq *http.Request, err error) {
@@ -108,15 +108,15 @@ func (h *HTTPMetaHeadersDecorator) ChangeRequest(req *http.Request) (newReq *htt
 }
 
 type HTTPAuthDecorator struct {
-	login string
+	login    string
 	password string
 }
 
 func NewHTTPAuthDecorator(login, password string) HTTPRequestDecorator {
-	ret := new(HTTPAuthDecorator)
-	ret.login = login
-	ret.password = password
-	return ret
+	return &HTTPAuthDecorator{
+		login:    login,
+		password: password,
+	}
 }
 
 func (self *HTTPAuthDecorator) ChangeRequest(req *http.Request) (*http.Request, error) {
@@ -136,7 +136,7 @@ func NewHTTPRequestFactory(d ...HTTPRequestDecorator) *HTTPRequestFactory {
 	}
 }
 
-func (self *HTTPRequestFactory) AddDecorator(d... HTTPRequestDecorator) {
+func (self *HTTPRequestFactory) AddDecorator(d ...HTTPRequestDecorator) {
 	self.decorators = append(self.decorators, d...)
 }
 

+ 2 - 0
version.go

@@ -25,6 +25,8 @@ func dockerVersion() *engine.Env {
 	v.Set("Version", VERSION)
 	v.Set("GitCommit", GITCOMMIT)
 	v.Set("GoVersion", runtime.Version())
+	v.Set("Os", runtime.GOOS)
+	v.Set("Arch", runtime.GOARCH)
 	// FIXME:utils.GetKernelVersion should only be needed here
 	if kernelVersion, err := utils.GetKernelVersion(); err == nil {
 		v.Set("KernelVersion", kernelVersion.String())