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
|
package helperimage
import (
"fmt"
"gitlab.com/gitlab-org/gitlab-runner/helpers/docker/errors"
"gitlab.com/gitlab-org/gitlab-runner/shells"
)
const (
OSTypeLinux = "linux"
OSTypeWindows = "windows"
//nolint:lll
// DockerHubWarningMessage is the message that is printed to the user when
// it's using the helper image hosted in Docker Hub. It is up to the caller
// to print this message.
DockerHubWarningMessage = "Pulling GitLab Runner helper image from Docker Hub. " +
"Helper image is migrating to registry.gitlab.com, " +
"for more information see " +
"https://docs.gitlab.com/runner/configuration/advanced-configuration.html#migrate-helper-image-to-registrygitlabcom"
// DockerHubName is the name of the helper image hosted in Docker Hub.
DockerHubName = "gitlab/gitlab-runner-helper"
// GitLabRegistryName is the name of the helper image hosted in registry.gitlab.com.
GitLabRegistryName = "registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper"
// DefaultFlavor is the default flavor of image we use for the helper.
DefaultFlavor = "alpine"
headRevision = "HEAD"
latestImageRevision = "latest"
)
type Info struct {
OSType string
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
Shell string
GitLabRegistry bool
Flavor 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)
}
info, err := factory.Create(imageRevision(revision), cfg)
info.OSType = cfg.OSType
return info, err
}
func imageRevision(revision string) string {
if revision != headRevision {
return revision
}
return latestImageRevision
}
func imageName(gitlabRegistry bool) string {
if gitlabRegistry {
return GitLabRegistryName
}
return DockerHubName
}
func getPowerShellCmd(shell string) []string {
if shell == "" {
shell = shells.SNPowershell
}
return shells.PowershellDockerCmd(shell)
}
|