info.go 1.29 KB
Newer Older
1
2
3
package helperimage

import (
4
	"fmt"
5
6

	"gitlab.com/gitlab-org/gitlab-runner/helpers/docker/errors"
7
8
9
10
11
)

const (
	OSTypeLinux   = "linux"
	OSTypeWindows = "windows"
12
13

	name = "gitlab/gitlab-runner-helper"
14
15
16

	headRevision        = "HEAD"
	latestImageRevision = "latest"
17
18
)

19
20
21
22
23
type Info struct {
	Architecture            string
	Name                    string
	Tag                     string
	IsSupportingLocalImport bool
24
	Cmd                     []string
25
26
27
28
}

func (i Info) String() string {
	return fmt.Sprintf("%s:%s", i.Name, i.Tag)
29
30
}

31
32
33
34
35
36
37
38
39
40
41
// 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)
}
42

43
44
45
var supportedOsTypesFactories = map[string]creator{
	OSTypeWindows: new(windowsInfo),
	OSTypeLinux:   new(linuxInfo),
46
47
}

48
49
func Get(revision string, cfg Config) (Info, error) {
	factory, ok := supportedOsTypesFactories[cfg.OSType]
50
	if !ok {
51
		return Info{}, errors.NewErrOSNotSupported(cfg.OSType)
52
53
	}

54
55
56
57
58
59
60
61
62
	return factory.Create(imageRevision(revision), cfg)
}

func imageRevision(revision string) string {
	if revision != headRevision {
		return revision
	}

	return latestImageRevision
63
}