github.com/secure-build/gitlab-runner@v12.5.0+incompatible/helpers/docker/helperimage/info.go (about) 1 package helperimage 2 3 import ( 4 "fmt" 5 6 "gitlab.com/gitlab-org/gitlab-runner/helpers/docker/errors" 7 ) 8 9 const ( 10 OSTypeLinux = "linux" 11 OSTypeWindows = "windows" 12 13 name = "gitlab/gitlab-runner-helper" 14 15 headRevision = "HEAD" 16 latestImageRevision = "latest" 17 ) 18 19 type Info struct { 20 Architecture string 21 Name string 22 Tag string 23 IsSupportingLocalImport bool 24 Cmd []string 25 } 26 27 func (i Info) String() string { 28 return fmt.Sprintf("%s:%s", i.Name, i.Tag) 29 } 30 31 // Config specifies details about the consumer of this package that need to be 32 // taken in consideration when building Container. 33 type Config struct { 34 OSType string 35 Architecture string 36 OperatingSystem string 37 } 38 39 type creator interface { 40 Create(revision string, cfg Config) (Info, error) 41 } 42 43 var supportedOsTypesFactories = map[string]creator{ 44 OSTypeWindows: new(windowsInfo), 45 OSTypeLinux: new(linuxInfo), 46 } 47 48 func Get(revision string, cfg Config) (Info, error) { 49 factory, ok := supportedOsTypesFactories[cfg.OSType] 50 if !ok { 51 return Info{}, errors.NewErrOSNotSupported(cfg.OSType) 52 } 53 54 return factory.Create(imageRevision(revision), cfg) 55 } 56 57 func imageRevision(revision string) string { 58 if revision != headRevision { 59 return revision 60 } 61 62 return latestImageRevision 63 }