forked from dagger/dagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.go
73 lines (61 loc) · 1.7 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
package engine
import (
"fmt"
"os"
"runtime/debug"
"golang.org/x/mod/semver"
)
const (
EngineImageRepo = "registry.dagger.io/engine"
)
var DevelopmentVersion = fmt.Sprintf("devel (%s)", vcsRevision())
// Version holds the complete version number. Filled in at linking time.
var Version string
func init() {
if Version == "" {
Version = DevelopmentVersion
}
// normalize Version to semver
if semver.IsValid("v" + Version) {
Version = "v" + Version
}
}
func ImageRef() string {
// If "devel" is set, then this is a local build. Normally _EXPERIMENTAL_DAGGER_RUNNER_HOST
// should be set to point to a runner built from local code, but we default to using "main"
// in case it's not.
if Version == DevelopmentVersion {
return fmt.Sprintf("%s:main", EngineImageRepo)
}
// If Version is set to something besides a semver tag, then it's a build off our main branch.
// For now, this also defaults to using the "main" tag, but in the future if we tag engine
// images with git sha then we could use that instead
if !semver.IsValid(Version) {
return fmt.Sprintf("%s:main", EngineImageRepo)
}
// Version is a semver tag, so use the engine image at that tag
return fmt.Sprintf("%s:%s", EngineImageRepo, Version)
}
func RunnerHost() string {
var runnerHost string
if v, ok := os.LookupEnv("_EXPERIMENTAL_DAGGER_RUNNER_HOST"); ok {
runnerHost = v
} else {
runnerHost = "docker-image://" + ImageRef()
}
return runnerHost
}
// revision returns the VCS revision being used to build or empty string
// if none.
func vcsRevision() string {
bi, ok := debug.ReadBuildInfo()
if !ok {
return ""
}
for _, s := range bi.Settings {
if s.Key == "vcs.revision" {
return s.Value[:9]
}
}
return ""
}