(ctx context.Context, service types.ServiceConfig, quietPull bool, defaultPlatform string)
| 174 | } |
| 175 | |
| 176 | func (s *composeService) pullServiceImage(ctx context.Context, service types.ServiceConfig, quietPull bool, defaultPlatform string) (string, error) { |
| 177 | resource := "Image " + service.Image |
| 178 | s.events.On(newEvent(resource, api.Working, api.StatusPulling)) |
| 179 | ref, err := reference.ParseNormalizedNamed(service.Image) |
| 180 | if err != nil { |
| 181 | return "", err |
| 182 | } |
| 183 | |
| 184 | encodedAuth, err := encodedAuth(ref, s.configFile()) |
| 185 | if err != nil { |
| 186 | return "", err |
| 187 | } |
| 188 | |
| 189 | platform := service.Platform |
| 190 | if platform == "" { |
| 191 | platform = defaultPlatform |
| 192 | } |
| 193 | |
| 194 | var ociPlatforms []ocispec.Platform |
| 195 | if platform != "" { |
| 196 | p, err := platforms.Parse(platform) |
| 197 | if err != nil { |
| 198 | return "", err |
| 199 | } |
| 200 | ociPlatforms = append(ociPlatforms, p) |
| 201 | } |
| 202 | |
| 203 | stream, err := s.apiClient().ImagePull(ctx, service.Image, client.ImagePullOptions{ |
| 204 | RegistryAuth: encodedAuth, |
| 205 | Platforms: ociPlatforms, |
| 206 | }) |
| 207 | |
| 208 | if ctx.Err() != nil { |
| 209 | s.events.On(api.Resource{ |
| 210 | ID: resource, |
| 211 | Status: api.Warning, |
| 212 | Text: "Interrupted", |
| 213 | }) |
| 214 | return "", nil |
| 215 | } |
| 216 | |
| 217 | // check if it has an error and the service has a build section |
| 218 | // then the status should be warning instead of error |
| 219 | if err != nil && service.Build != nil { |
| 220 | s.events.On(api.Resource{ |
| 221 | ID: resource, |
| 222 | Status: api.Warning, |
| 223 | Text: getUnwrappedErrorMessage(err), |
| 224 | }) |
| 225 | return "", err |
| 226 | } |
| 227 | |
| 228 | if err != nil { |
| 229 | s.events.On(errorEvent(resource, getUnwrappedErrorMessage(err))) |
| 230 | return "", err |
| 231 | } |
| 232 | |
| 233 | dec := json.NewDecoder(stream) |
no test coverage detected