MCPcopy
hub / github.com/nektos/act / getImagePullOptions

Function getImagePullOptions

pkg/container/docker_pull.go:78–121  ·  view source on GitHub ↗
(ctx context.Context, input NewDockerPullExecutorInput)

Source from the content-addressed store, hash-verified

76}
77
78func getImagePullOptions(ctx context.Context, input NewDockerPullExecutorInput) (client.ImagePullOptions, error) {
79 imagePullOptions := client.ImagePullOptions{}
80 if input.Platform != "" {
81 parts := strings.SplitN(input.Platform, "/", 2)
82 if len(parts) == 2 {
83 imagePullOptions.Platforms = []specs.Platform{{OS: parts[0], Architecture: parts[1]}}
84 }
85 }
86 logger := common.Logger(ctx)
87
88 if input.Username != "" && input.Password != "" {
89 logger.Debugf("using authentication for docker pull")
90
91 authConfig := registry.AuthConfig{
92 Username: input.Username,
93 Password: input.Password,
94 }
95
96 encodedJSON, err := json.Marshal(authConfig)
97 if err != nil {
98 return imagePullOptions, err
99 }
100
101 imagePullOptions.RegistryAuth = base64.URLEncoding.EncodeToString(encodedJSON)
102 } else {
103 authConfig, err := LoadDockerAuthConfig(ctx, input.Image)
104 if err != nil {
105 return imagePullOptions, err
106 }
107 if authConfig.Username == "" && authConfig.Password == "" {
108 return imagePullOptions, nil
109 }
110 logger.Info("using DockerAuthConfig authentication for docker pull")
111
112 encodedJSON, err := json.Marshal(authConfig)
113 if err != nil {
114 return imagePullOptions, err
115 }
116
117 imagePullOptions.RegistryAuth = base64.URLEncoding.EncodeToString(encodedJSON)
118 }
119
120 return imagePullOptions, nil
121}
122
123func cleanImage(ctx context.Context, image string) string {
124 ref, err := reference.ParseAnyReference(image)

Callers 2

TestGetImagePullOptionsFunction · 0.85
NewDockerPullExecutorFunction · 0.85

Calls 3

LoggerFunction · 0.92
LoadDockerAuthConfigFunction · 0.85
InfoMethod · 0.65

Tested by 1

TestGetImagePullOptionsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…