-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
63 lines (49 loc) · 1.29 KB
/
info.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
package helperimage
import (
"fmt"
"gitlab.com/gitlab-org/gitlab-runner/helpers/docker/errors"
)
const (
OSTypeLinux = "linux"
OSTypeWindows = "windows"
name = "gitlab/gitlab-runner-helper"
headRevision = "HEAD"
latestImageRevision = "latest"
)
type Info struct {
Architecture string
Name string
Tag string
IsSupportingLocalImport bool
Cmd []string
}
func (i Info) String() string {
return fmt.Sprintf("%s:%s", i.Name, i.Tag)
}
// Config specifies details about the consumer of this package that need to be
// taken in consideration when building Container.
type Config struct {
OSType string
Architecture string
OperatingSystem string
}
type creator interface {
Create(revision string, cfg Config) (Info, error)
}
var supportedOsTypesFactories = map[string]creator{
OSTypeWindows: new(windowsInfo),
OSTypeLinux: new(linuxInfo),
}
func Get(revision string, cfg Config) (Info, error) {
factory, ok := supportedOsTypesFactories[cfg.OSType]
if !ok {
return Info{}, errors.NewErrOSNotSupported(cfg.OSType)
}
return factory.Create(imageRevision(revision), cfg)
}
func imageRevision(revision string) string {
if revision != headRevision {
return revision
}
return latestImageRevision
}