repoName = "" tag = "latest" insecureRegistries = []string{} authConfig = ®istry.AuthConfig{} }) Context("with an invalid host", func() { BeforeEach(func() { setupPingableRegistry() repoName = "qwer:5123/some_user/some_repo" }) It("should error", func() { _, err := helpers.FetchMetadata(repoName, tag, insecureRegistries, authConfig) Expect(err).To(HaveOccurred()) }) }) Context("with an unknown repository", func() { BeforeEach(func() { setupPingableRegistry() repoName = registryHost + "/some_user/not_some_repo" }) It("should error", func() { _, err := helpers.FetchMetadata(repoName, tag, insecureRegistries, authConfig) Expect(err).To(HaveOccurred()) }) })
func (builder *Builder) build() <-chan error { errorChan := make(chan error, 1) go func() { defer close(errorChan) authConfig := ®istry.AuthConfig{ Username: builder.DockerUser, Password: builder.DockerPassword, Email: builder.DockerEmail, ServerAddress: builder.DockerLoginServer, } img, err := helpers.FetchMetadata(builder.RepoName, builder.Tag, builder.InsecureDockerRegistries, authConfig) if err != nil { errorChan <- fmt.Errorf( "failed to fetch metadata from [%s] with tag [%s] and insecure registries %s due to %s", builder.RepoName, builder.Tag, builder.InsecureDockerRegistries, err.Error(), ) return } info := protocol.DockerImageMetadata{} if img.Config != nil { info.ExecutionMetadata.Cmd = img.Config.Cmd info.ExecutionMetadata.Entrypoint = img.Config.Entrypoint info.ExecutionMetadata.Workdir = img.Config.WorkingDir info.ExecutionMetadata.User = img.Config.User info.ExecutionMetadata.ExposedPorts, err = extractPorts(img.Config.ExposedPorts) if err != nil { portDetails := fmt.Sprintf("%v", img.Config.ExposedPorts) println("failed to parse image ports", portDetails, err.Error()) errorChan <- err return } } dockerImageURL := builder.RepoName if len(builder.Tag) > 0 { dockerImageURL = dockerImageURL + ":" + builder.Tag } info.DockerImage = dockerImageURL if builder.CacheDockerImage { info.DockerImage, err = builder.cacheDockerImage(dockerImageURL) if err != nil { println("failed to cache image", dockerImageURL, err.Error()) errorChan <- err return } } if err := helpers.SaveMetadata(builder.OutputFilename, &info); err != nil { errorChan <- fmt.Errorf( "failed to save metadata to [%s] due to %s", builder.OutputFilename, err.Error(), ) return } errorChan <- nil }() return errorChan }