Browse code

Remove extra binaries commit variables from windows build

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>

Kenfe-Mickael Laventure authored on 2016/11/12 01:02:23
Showing 4 changed files
... ...
@@ -1,11 +1,8 @@
1 1
 package daemon
2 2
 
3 3
 import (
4
-	"context"
5 4
 	"os"
6
-	"os/exec"
7 5
 	"runtime"
8
-	"strings"
9 6
 	"sync/atomic"
10 7
 	"time"
11 8
 
... ...
@@ -135,76 +132,8 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
135 135
 		Isolation:          daemon.defaultIsolation,
136 136
 	}
137 137
 
138
-	// TODO Windows. Refactor this more once sysinfo is refactored into
139
-	// platform specific code. On Windows, sysinfo.cgroupMemInfo and
140
-	// sysinfo.cgroupCpuInfo will be nil otherwise and cause a SIGSEGV if
141
-	// an attempt is made to access through them.
142
-	if runtime.GOOS != "windows" {
143
-		v.MemoryLimit = sysInfo.MemoryLimit
144
-		v.SwapLimit = sysInfo.SwapLimit
145
-		v.KernelMemory = sysInfo.KernelMemory
146
-		v.OomKillDisable = sysInfo.OomKillDisable
147
-		v.CPUCfsPeriod = sysInfo.CPUCfsPeriod
148
-		v.CPUCfsQuota = sysInfo.CPUCfsQuota
149
-		v.CPUShares = sysInfo.CPUShares
150
-		v.CPUSet = sysInfo.Cpuset
151
-		v.Runtimes = daemon.configStore.GetAllRuntimes()
152
-		v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName()
153
-		v.InitBinary = daemon.configStore.GetInitPath()
154
-
155
-		v.ContainerdCommit.Expected = dockerversion.ContainerdCommitID
156
-		if sv, err := daemon.containerd.GetServerVersion(context.Background()); err == nil {
157
-			v.ContainerdCommit.ID = sv.Revision
158
-		} else {
159
-			logrus.Warnf("failed to retrieve containerd version: %v", err)
160
-			v.ContainerdCommit.ID = "N/A"
161
-		}
162
-
163
-		v.RuncCommit.Expected = dockerversion.RuncCommitID
164
-		if rv, err := exec.Command(DefaultRuntimeBinary, "--version").Output(); err == nil {
165
-			parts := strings.Split(strings.TrimSpace(string(rv)), "\n")
166
-			if len(parts) == 3 {
167
-				parts = strings.Split(parts[1], ": ")
168
-				if len(parts) == 2 {
169
-					v.RuncCommit.ID = strings.TrimSpace(parts[1])
170
-				}
171
-			}
172
-
173
-			if v.RuncCommit.ID == "" {
174
-				logrus.Warnf("failed to retrieve %s version: unknown output format: %s", DefaultRuntimeBinary, string(rv))
175
-				v.RuncCommit.ID = "N/A"
176
-			}
177
-		} else {
178
-			logrus.Warnf("failed to retrieve %s version: %v", DefaultRuntimeBinary, err)
179
-			v.RuncCommit.ID = "N/A"
180
-		}
181
-
182
-		v.InitCommit.Expected = dockerversion.InitCommitID
183
-		if rv, err := exec.Command(DefaultInitBinary, "--version").Output(); err == nil {
184
-			parts := strings.Split(strings.TrimSpace(string(rv)), " - ")
185
-			if len(parts) == 2 {
186
-				if dockerversion.InitCommitID[0] == 'v' {
187
-					vs := strings.TrimPrefix(parts[0], "tini version ")
188
-					v.InitCommit.ID = "v" + vs
189
-				} else {
190
-					// Get the sha1
191
-					gitParts := strings.Split(parts[1], ".")
192
-					if len(gitParts) == 2 && gitParts[0] == "git" {
193
-						v.InitCommit.ID = gitParts[1]
194
-						v.InitCommit.Expected = dockerversion.InitCommitID[0:len(gitParts[1])]
195
-					}
196
-				}
197
-			}
198
-
199
-			if v.InitCommit.ID == "" {
200
-				logrus.Warnf("failed to retrieve %s version: unknown output format: %s", DefaultInitBinary, string(rv))
201
-				v.InitCommit.ID = "N/A"
202
-			}
203
-		} else {
204
-			logrus.Warnf("failed to retrieve %s version", DefaultInitBinary)
205
-			v.InitCommit.ID = "N/A"
206
-		}
207
-	}
138
+	// Retrieve platform specific info
139
+	daemon.FillPlatformInfo(v, sysInfo)
208 140
 
209 141
 	hostname := ""
210 142
 	if hn, err := os.Hostname(); err != nil {
211 143
new file mode 100644
... ...
@@ -0,0 +1,81 @@
0
+// +build !windows
1
+
2
+package daemon
3
+
4
+import (
5
+	"context"
6
+	"os/exec"
7
+	"strings"
8
+
9
+	"github.com/Sirupsen/logrus"
10
+	"github.com/docker/docker/api/types"
11
+	"github.com/docker/docker/dockerversion"
12
+	"github.com/docker/docker/pkg/sysinfo"
13
+)
14
+
15
+func (daemon *Daemon) FillPlatformInfo(v *types.InfoBase, sysInfo *sysinfo.SysInfo) {
16
+	v.MemoryLimit = sysInfo.MemoryLimit
17
+	v.SwapLimit = sysInfo.SwapLimit
18
+	v.KernelMemory = sysInfo.KernelMemory
19
+	v.OomKillDisable = sysInfo.OomKillDisable
20
+	v.CPUCfsPeriod = sysInfo.CPUCfsPeriod
21
+	v.CPUCfsQuota = sysInfo.CPUCfsQuota
22
+	v.CPUShares = sysInfo.CPUShares
23
+	v.CPUSet = sysInfo.Cpuset
24
+	v.Runtimes = daemon.configStore.GetAllRuntimes()
25
+	v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName()
26
+	v.InitBinary = daemon.configStore.GetInitPath()
27
+
28
+	v.ContainerdCommit.Expected = dockerversion.ContainerdCommitID
29
+	if sv, err := daemon.containerd.GetServerVersion(context.Background()); err == nil {
30
+		v.ContainerdCommit.ID = sv.Revision
31
+	} else {
32
+		logrus.Warnf("failed to retrieve containerd version: %v", err)
33
+		v.ContainerdCommit.ID = "N/A"
34
+	}
35
+
36
+	v.RuncCommit.Expected = dockerversion.RuncCommitID
37
+	if rv, err := exec.Command(DefaultRuntimeBinary, "--version").Output(); err == nil {
38
+		parts := strings.Split(strings.TrimSpace(string(rv)), "\n")
39
+		if len(parts) == 3 {
40
+			parts = strings.Split(parts[1], ": ")
41
+			if len(parts) == 2 {
42
+				v.RuncCommit.ID = strings.TrimSpace(parts[1])
43
+			}
44
+		}
45
+
46
+		if v.RuncCommit.ID == "" {
47
+			logrus.Warnf("failed to retrieve %s version: unknown output format: %s", DefaultRuntimeBinary, string(rv))
48
+			v.RuncCommit.ID = "N/A"
49
+		}
50
+	} else {
51
+		logrus.Warnf("failed to retrieve %s version: %v", DefaultRuntimeBinary, err)
52
+		v.RuncCommit.ID = "N/A"
53
+	}
54
+
55
+	v.InitCommit.Expected = dockerversion.InitCommitID
56
+	if rv, err := exec.Command(DefaultInitBinary, "--version").Output(); err == nil {
57
+		parts := strings.Split(strings.TrimSpace(string(rv)), " - ")
58
+		if len(parts) == 2 {
59
+			if dockerversion.InitCommitID[0] == 'v' {
60
+				vs := strings.TrimPrefix(parts[0], "tini version ")
61
+				v.InitCommit.ID = "v" + vs
62
+			} else {
63
+				// Get the sha1
64
+				gitParts := strings.Split(parts[1], ".")
65
+				if len(gitParts) == 2 && gitParts[0] == "git" {
66
+					v.InitCommit.ID = gitParts[1]
67
+					v.InitCommit.Expected = dockerversion.InitCommitID[0:len(gitParts[1])]
68
+				}
69
+			}
70
+		}
71
+
72
+		if v.InitCommit.ID == "" {
73
+			logrus.Warnf("failed to retrieve %s version: unknown output format: %s", DefaultInitBinary, string(rv))
74
+			v.InitCommit.ID = "N/A"
75
+		}
76
+	} else {
77
+		logrus.Warnf("failed to retrieve %s version", DefaultInitBinary)
78
+		v.InitCommit.ID = "N/A"
79
+	}
80
+}
0 81
new file mode 100644
... ...
@@ -0,0 +1,9 @@
0
+package daemon
1
+
2
+import (
3
+	"github.com/docker/docker/api/types"
4
+	"github.com/docker/docker/pkg/sysinfo"
5
+)
6
+
7
+func (daemon *Daemon) FillPlatformInfo(v *types.InfoBase, sysInfo *sysinfo.SysInfo) {
8
+}
... ...
@@ -17,6 +17,20 @@ const (
17 17
 	Version            string = "$VERSION"
18 18
 	BuildTime          string = "$BUILDTIME"
19 19
 	IAmStatic          string = "${IAMSTATIC:-true}"
20
+)
21
+
22
+// AUTOGENERATED FILE; see /go/src/github.com/docker/docker/hack/make/.go-autogen
23
+DVEOF
24
+
25
+cat > dockerversion/version_autogen_unix.go <<DVEOF
26
+// +build autogen,!windows
27
+
28
+// Package dockerversion is auto-generated at build-time
29
+package dockerversion
30
+
31
+// Default build-time variable for library-import.
32
+// This file is overridden on build with build-time informations.
33
+const (
20 34
 	ContainerdCommitID string = "${CONTAINERD_COMMIT}"
21 35
 	RuncCommitID       string = "${RUNC_COMMIT}"
22 36
 	InitCommitID       string = "${TINI_COMMIT}"