-
-
Notifications
You must be signed in to change notification settings - Fork 615
/
version.go
190 lines (149 loc) · 6.24 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package version
import (
"fmt"
"github.com/drud/ddev/pkg/nodeps"
"github.com/fsouza/go-dockerclient"
"os/exec"
"runtime"
"strings"
)
// MariaDBDefaultVersion is the default version we use in the db container
const MariaDBDefaultVersion = "10.2"
// VERSION is supplied with the git committish this is built from
var VERSION = ""
// IMPORTANT: These versions are overridden by version ldflags specifications VERSION_VARIABLES in the Makefile
// DdevVersion is the current version of ddev, by default the git committish (should be current git tag)
var DdevVersion = "v0.0.0-overridden-by-make" // Note that this is overridden by make
// SegmentKey is the ddev-specific key for Segment service
// Compiled with link-time variables
var SegmentKey = "CawBO33fRNynkaZsfgjY8sTxDT3yrH9c"
// DockerVersionConstraint is the current minimum version of docker required for ddev.
// See https://godoc.org/github.com/Masterminds/semver#hdr-Checking_Version_Constraints
// for examples defining version constraints.
// REMEMBER TO CHANGE docs/index.md if you touch this!
// The constraint MUST HAVE a -pre of some kind on it for successful comparison.
// See https://github.com/drud/ddev/pull/738.. and regression https://github.com/drud/ddev/issues/1431
var DockerVersionConstraint = ">= 18.06.1-alpha1"
// DockerComposeVersionConstraint is the current minimum version of docker-compose required for ddev.
// REMEMBER TO CHANGE docs/index.md if you touch this!
// The constraint MUST HAVE a -pre of some kind on it for successful comparison.
// See https://github.com/drud/ddev/pull/738.. and regression https://github.com/drud/ddev/issues/1431
var DockerComposeVersionConstraint = ">= 1.21.0-alpha1"
// DockerComposeFileFormatVersion is the compose version to be used
var DockerComposeFileFormatVersion = "3.6"
// WebImg defines the default web image used for applications.
var WebImg = "drud/ddev-webserver"
// WebTag defines the default web image tag for drud dev
var WebTag = "20200818_remove_apache_cgi" // Note that this can be overridden by make
// DBImg defines the default db image used for applications.
var DBImg = "drud/ddev-dbserver"
// BaseDBTag is the main tag, DBTag is constructed from it
var BaseDBTag = "20200821_remove_docker_toolbox"
// DBAImg defines the default phpmyadmin image tag used for applications.
var DBAImg = "phpmyadmin/phpmyadmin"
// DBATag defines the default phpmyadmin image tag used for applications.
var DBATag = "5" // Note that this can be overridden by make
// RouterImage defines the image used for the router.
var RouterImage = "drud/ddev-router"
// RouterTag defines the tag used for the router.
var RouterTag = "20200817_custom_certs" // Note that this can be overridden by make
var SSHAuthImage = "drud/ddev-ssh-agent"
var SSHAuthTag = "v1.15.1"
// COMMIT is the actual committish, supplied by make
var COMMIT = "COMMIT should be overridden"
// BUILDINFO is information with date and context, supplied by make
var BUILDINFO = "BUILDINFO should have new info"
// DockerVersion is cached version of docker
var DockerVersion = ""
// DockerComposeVersion is filled with the version we find for docker-compose
var DockerComposeVersion = ""
// GetVersionInfo returns a map containing the version info defined above.
func GetVersionInfo() map[string]string {
var err error
versionInfo := make(map[string]string)
versionInfo["DDEV-Local version"] = DdevVersion
versionInfo["web"] = GetWebImage()
versionInfo["db"] = GetDBImage(nodeps.MariaDB)
versionInfo["dba"] = GetDBAImage()
versionInfo["router"] = RouterImage + ":" + RouterTag
versionInfo["ddev-ssh-agent"] = SSHAuthImage + ":" + SSHAuthTag
versionInfo["commit"] = COMMIT
versionInfo["build info"] = BUILDINFO
versionInfo["os"] = runtime.GOOS
if versionInfo["docker"], err = GetDockerVersion(); err != nil {
versionInfo["docker"] = fmt.Sprintf("failed to GetDockerVersion(): %v", err)
}
if versionInfo["docker-compose"], err = GetDockerComposeVersion(); err != nil {
versionInfo["docker-compose"] = fmt.Sprintf("failed to GetDockerComposeVersion(): %v", err)
}
if runtime.GOOS == "windows" {
versionInfo["docker type"] = "Docker Desktop For Windows"
}
return versionInfo
}
// GetWebImage returns the correctly formatted web image:tag reference
func GetWebImage() string {
return fmt.Sprintf("%s:%s", WebImg, WebTag)
}
// GetDBImage returns the correctly formatted db image:tag reference
func GetDBImage(dbType string, dbVersion ...string) string {
v := MariaDBDefaultVersion
if len(dbVersion) > 0 {
v = dbVersion[0]
}
return fmt.Sprintf("%s-%s-%s:%s", DBImg, dbType, v, BaseDBTag)
}
// GetDBAImage returns the correctly formatted dba image:tag reference
func GetDBAImage() string {
return fmt.Sprintf("%s:%s", DBAImg, DBATag)
}
// GetSSHAuthImage returns the correctly formatted sshauth image:tag reference
func GetSSHAuthImage() string {
return fmt.Sprintf("%s:%s", SSHAuthImage, SSHAuthTag)
}
// GetRouterImage returns the correctly formatted router image:tag reference
func GetRouterImage() string {
return fmt.Sprintf("%s:%s", RouterImage, RouterTag)
}
// GetDockerComposeVersion runs docker-compose -v to get the current version
func GetDockerComposeVersion() (string, error) {
if DockerComposeVersion != "" {
return DockerComposeVersion, nil
}
executableName := "docker-compose"
path, err := exec.LookPath(executableName)
if err != nil {
return "", fmt.Errorf("no docker-compose")
}
// Temporarily fake the docker-compose check on macOS because of
// the slow docker-compose problem in https://github.com/docker/compose/issues/6956
// This can be removed when that's resolved.
if runtime.GOOS != "darwin" {
DockerComposeVersion = "1.25.0-rc4"
return DockerComposeVersion, nil
}
out, err := exec.Command(path, "version", "--short").Output()
if err != nil {
return "", err
}
v := string(out)
DockerComposeVersion = strings.TrimSpace(v)
return DockerComposeVersion, nil
}
// GetDockerVersion gets the cached or api-sourced version of docker engine
func GetDockerVersion() (string, error) {
if DockerVersion != "" {
return DockerVersion, nil
}
var client *docker.Client
var err error
if client, err = docker.NewClientFromEnv(); err != nil {
return "", err
}
v, err := client.Version()
if err != nil {
return "", err
}
DockerVersion = v.Get("Version")
return DockerVersion, nil
}