pull.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. package graph
  2. import (
  3. "fmt"
  4. "io"
  5. "io/ioutil"
  6. "net"
  7. "net/url"
  8. "os"
  9. "strings"
  10. "time"
  11. log "github.com/Sirupsen/logrus"
  12. "github.com/docker/docker/engine"
  13. "github.com/docker/docker/image"
  14. "github.com/docker/docker/pkg/common"
  15. "github.com/docker/docker/pkg/progressreader"
  16. "github.com/docker/docker/pkg/tarsum"
  17. "github.com/docker/docker/registry"
  18. "github.com/docker/docker/utils"
  19. )
  20. func (s *TagStore) CmdPull(job *engine.Job) engine.Status {
  21. if n := len(job.Args); n != 1 && n != 2 {
  22. return job.Errorf("Usage: %s IMAGE [TAG]", job.Name)
  23. }
  24. var (
  25. localName = job.Args[0]
  26. tag string
  27. sf = utils.NewStreamFormatter(job.GetenvBool("json"))
  28. authConfig = &registry.AuthConfig{}
  29. metaHeaders map[string][]string
  30. )
  31. // Resolve the Repository name from fqn to RepositoryInfo
  32. repoInfo, err := registry.ResolveRepositoryInfo(job, localName)
  33. if err != nil {
  34. return job.Error(err)
  35. }
  36. if len(job.Args) > 1 {
  37. tag = job.Args[1]
  38. }
  39. job.GetenvJson("authConfig", authConfig)
  40. job.GetenvJson("metaHeaders", &metaHeaders)
  41. c, err := s.poolAdd("pull", repoInfo.LocalName+":"+tag)
  42. if err != nil {
  43. if c != nil {
  44. // Another pull of the same repository is already taking place; just wait for it to finish
  45. job.Stdout.Write(sf.FormatStatus("", "Repository %s already being pulled by another client. Waiting.", repoInfo.LocalName))
  46. <-c
  47. return engine.StatusOK
  48. }
  49. return job.Error(err)
  50. }
  51. defer s.poolRemove("pull", repoInfo.LocalName+":"+tag)
  52. log.Debugf("pulling image from host %q with remote name %q", repoInfo.Index.Name, repoInfo.RemoteName)
  53. endpoint, err := repoInfo.GetEndpoint()
  54. if err != nil {
  55. return job.Error(err)
  56. }
  57. r, err := registry.NewSession(authConfig, registry.HTTPRequestFactory(metaHeaders), endpoint, true)
  58. if err != nil {
  59. return job.Error(err)
  60. }
  61. logName := repoInfo.LocalName
  62. if tag != "" {
  63. logName += ":" + tag
  64. }
  65. if len(repoInfo.Index.Mirrors) == 0 && ((repoInfo.Official && repoInfo.Index.Official) || endpoint.Version == registry.APIVersion2) {
  66. if repoInfo.Official {
  67. j := job.Eng.Job("trust_update_base")
  68. if err = j.Run(); err != nil {
  69. log.Errorf("error updating trust base graph: %s", err)
  70. }
  71. }
  72. log.Debugf("pulling v2 repository with local name %q", repoInfo.LocalName)
  73. if err := s.pullV2Repository(job.Eng, r, job.Stdout, repoInfo, tag, sf, job.GetenvBool("parallel")); err == nil {
  74. if err = job.Eng.Job("log", "pull", logName, "").Run(); err != nil {
  75. log.Errorf("Error logging event 'pull' for %s: %s", logName, err)
  76. }
  77. return engine.StatusOK
  78. } else if err != registry.ErrDoesNotExist && err != ErrV2RegistryUnavailable {
  79. log.Errorf("Error from V2 registry: %s", err)
  80. }
  81. log.Debug("image does not exist on v2 registry, falling back to v1")
  82. }
  83. log.Debugf("pulling v1 repository with local name %q", repoInfo.LocalName)
  84. if err = s.pullRepository(r, job.Stdout, repoInfo, tag, sf, job.GetenvBool("parallel")); err != nil {
  85. return job.Error(err)
  86. }
  87. if err = job.Eng.Job("log", "pull", logName, "").Run(); err != nil {
  88. log.Errorf("Error logging event 'pull' for %s: %s", logName, err)
  89. }
  90. return engine.StatusOK
  91. }
  92. func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo *registry.RepositoryInfo, askedTag string, sf *utils.StreamFormatter, parallel bool) error {
  93. out.Write(sf.FormatStatus("", "Pulling repository %s", repoInfo.CanonicalName))
  94. repoData, err := r.GetRepositoryData(repoInfo.RemoteName)
  95. if err != nil {
  96. if strings.Contains(err.Error(), "HTTP code: 404") {
  97. return fmt.Errorf("Error: image %s:%s not found", repoInfo.RemoteName, askedTag)
  98. }
  99. // Unexpected HTTP error
  100. return err
  101. }
  102. log.Debugf("Retrieving the tag list")
  103. tagsList, err := r.GetRemoteTags(repoData.Endpoints, repoInfo.RemoteName, repoData.Tokens)
  104. if err != nil {
  105. log.Errorf("unable to get remote tags: %s", err)
  106. return err
  107. }
  108. for tag, id := range tagsList {
  109. repoData.ImgList[id] = &registry.ImgData{
  110. ID: id,
  111. Tag: tag,
  112. Checksum: "",
  113. }
  114. }
  115. log.Debugf("Registering tags")
  116. // If no tag has been specified, pull them all
  117. if askedTag == "" {
  118. for tag, id := range tagsList {
  119. repoData.ImgList[id].Tag = tag
  120. }
  121. } else {
  122. // Otherwise, check that the tag exists and use only that one
  123. id, exists := tagsList[askedTag]
  124. if !exists {
  125. return fmt.Errorf("Tag %s not found in repository %s", askedTag, repoInfo.CanonicalName)
  126. }
  127. repoData.ImgList[id].Tag = askedTag
  128. }
  129. errors := make(chan error)
  130. layers_downloaded := false
  131. for _, image := range repoData.ImgList {
  132. downloadImage := func(img *registry.ImgData) {
  133. if askedTag != "" && img.Tag != askedTag {
  134. if parallel {
  135. errors <- nil
  136. }
  137. return
  138. }
  139. if img.Tag == "" {
  140. log.Debugf("Image (id: %s) present in this repository but untagged, skipping", img.ID)
  141. if parallel {
  142. errors <- nil
  143. }
  144. return
  145. }
  146. // ensure no two downloads of the same image happen at the same time
  147. if c, err := s.poolAdd("pull", "img:"+img.ID); err != nil {
  148. if c != nil {
  149. out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Layer already being pulled by another client. Waiting.", nil))
  150. <-c
  151. out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Download complete", nil))
  152. } else {
  153. log.Debugf("Image (id: %s) pull is already running, skipping: %v", img.ID, err)
  154. }
  155. if parallel {
  156. errors <- nil
  157. }
  158. return
  159. }
  160. defer s.poolRemove("pull", "img:"+img.ID)
  161. out.Write(sf.FormatProgress(common.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s", img.Tag, repoInfo.CanonicalName), nil))
  162. success := false
  163. var lastErr, err error
  164. var is_downloaded bool
  165. for _, ep := range repoInfo.Index.Mirrors {
  166. out.Write(sf.FormatProgress(common.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s, mirror: %s", img.Tag, repoInfo.CanonicalName, ep), nil))
  167. if is_downloaded, err = s.pullImage(r, out, img.ID, ep, repoData.Tokens, sf); err != nil {
  168. // Don't report errors when pulling from mirrors.
  169. log.Debugf("Error pulling image (%s) from %s, mirror: %s, %s", img.Tag, repoInfo.CanonicalName, ep, err)
  170. continue
  171. }
  172. layers_downloaded = layers_downloaded || is_downloaded
  173. success = true
  174. break
  175. }
  176. if !success {
  177. for _, ep := range repoData.Endpoints {
  178. out.Write(sf.FormatProgress(common.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s, endpoint: %s", img.Tag, repoInfo.CanonicalName, ep), nil))
  179. if is_downloaded, err = s.pullImage(r, out, img.ID, ep, repoData.Tokens, sf); err != nil {
  180. // It's not ideal that only the last error is returned, it would be better to concatenate the errors.
  181. // As the error is also given to the output stream the user will see the error.
  182. lastErr = err
  183. out.Write(sf.FormatProgress(common.TruncateID(img.ID), fmt.Sprintf("Error pulling image (%s) from %s, endpoint: %s, %s", img.Tag, repoInfo.CanonicalName, ep, err), nil))
  184. continue
  185. }
  186. layers_downloaded = layers_downloaded || is_downloaded
  187. success = true
  188. break
  189. }
  190. }
  191. if !success {
  192. err := fmt.Errorf("Error pulling image (%s) from %s, %v", img.Tag, repoInfo.CanonicalName, lastErr)
  193. out.Write(sf.FormatProgress(common.TruncateID(img.ID), err.Error(), nil))
  194. if parallel {
  195. errors <- err
  196. return
  197. }
  198. }
  199. out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Download complete", nil))
  200. if parallel {
  201. errors <- nil
  202. }
  203. }
  204. if parallel {
  205. go downloadImage(image)
  206. } else {
  207. downloadImage(image)
  208. }
  209. }
  210. if parallel {
  211. var lastError error
  212. for i := 0; i < len(repoData.ImgList); i++ {
  213. if err := <-errors; err != nil {
  214. lastError = err
  215. }
  216. }
  217. if lastError != nil {
  218. return lastError
  219. }
  220. }
  221. for tag, id := range tagsList {
  222. if askedTag != "" && tag != askedTag {
  223. continue
  224. }
  225. if err := s.Set(repoInfo.LocalName, tag, id, true); err != nil {
  226. return err
  227. }
  228. }
  229. requestedTag := repoInfo.CanonicalName
  230. if len(askedTag) > 0 {
  231. requestedTag = repoInfo.CanonicalName + ":" + askedTag
  232. }
  233. WriteStatus(requestedTag, out, sf, layers_downloaded)
  234. return nil
  235. }
  236. func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint string, token []string, sf *utils.StreamFormatter) (bool, error) {
  237. history, err := r.GetRemoteHistory(imgID, endpoint, token)
  238. if err != nil {
  239. return false, err
  240. }
  241. out.Write(sf.FormatProgress(common.TruncateID(imgID), "Pulling dependent layers", nil))
  242. // FIXME: Try to stream the images?
  243. // FIXME: Launch the getRemoteImage() in goroutines
  244. layers_downloaded := false
  245. for i := len(history) - 1; i >= 0; i-- {
  246. id := history[i]
  247. // ensure no two downloads of the same layer happen at the same time
  248. if c, err := s.poolAdd("pull", "layer:"+id); err != nil {
  249. log.Debugf("Image (id: %s) pull is already running, skipping: %v", id, err)
  250. <-c
  251. }
  252. defer s.poolRemove("pull", "layer:"+id)
  253. if !s.graph.Exists(id) {
  254. out.Write(sf.FormatProgress(common.TruncateID(id), "Pulling metadata", nil))
  255. var (
  256. imgJSON []byte
  257. imgSize int
  258. err error
  259. img *image.Image
  260. )
  261. retries := 5
  262. for j := 1; j <= retries; j++ {
  263. imgJSON, imgSize, err = r.GetRemoteImageJSON(id, endpoint, token)
  264. if err != nil && j == retries {
  265. out.Write(sf.FormatProgress(common.TruncateID(id), "Error pulling dependent layers", nil))
  266. return layers_downloaded, err
  267. } else if err != nil {
  268. time.Sleep(time.Duration(j) * 500 * time.Millisecond)
  269. continue
  270. }
  271. img, err = image.NewImgJSON(imgJSON)
  272. layers_downloaded = true
  273. if err != nil && j == retries {
  274. out.Write(sf.FormatProgress(common.TruncateID(id), "Error pulling dependent layers", nil))
  275. return layers_downloaded, fmt.Errorf("Failed to parse json: %s", err)
  276. } else if err != nil {
  277. time.Sleep(time.Duration(j) * 500 * time.Millisecond)
  278. continue
  279. } else {
  280. break
  281. }
  282. }
  283. for j := 1; j <= retries; j++ {
  284. // Get the layer
  285. status := "Pulling fs layer"
  286. if j > 1 {
  287. status = fmt.Sprintf("Pulling fs layer [retries: %d]", j)
  288. }
  289. out.Write(sf.FormatProgress(common.TruncateID(id), status, nil))
  290. layer, err := r.GetRemoteImageLayer(img.ID, endpoint, token, int64(imgSize))
  291. if uerr, ok := err.(*url.Error); ok {
  292. err = uerr.Err
  293. }
  294. if terr, ok := err.(net.Error); ok && terr.Timeout() && j < retries {
  295. time.Sleep(time.Duration(j) * 500 * time.Millisecond)
  296. continue
  297. } else if err != nil {
  298. out.Write(sf.FormatProgress(common.TruncateID(id), "Error pulling dependent layers", nil))
  299. return layers_downloaded, err
  300. }
  301. layers_downloaded = true
  302. defer layer.Close()
  303. err = s.graph.Register(img,
  304. progressreader.New(progressreader.Config{
  305. In: layer,
  306. Out: out,
  307. Formatter: sf,
  308. Size: imgSize,
  309. NewLines: false,
  310. ID: common.TruncateID(id),
  311. Action: "Downloading",
  312. }))
  313. if terr, ok := err.(net.Error); ok && terr.Timeout() && j < retries {
  314. time.Sleep(time.Duration(j) * 500 * time.Millisecond)
  315. continue
  316. } else if err != nil {
  317. out.Write(sf.FormatProgress(common.TruncateID(id), "Error downloading dependent layers", nil))
  318. return layers_downloaded, err
  319. } else {
  320. break
  321. }
  322. }
  323. }
  324. out.Write(sf.FormatProgress(common.TruncateID(id), "Download complete", nil))
  325. }
  326. return layers_downloaded, nil
  327. }
  328. func WriteStatus(requestedTag string, out io.Writer, sf *utils.StreamFormatter, layers_downloaded bool) {
  329. if layers_downloaded {
  330. out.Write(sf.FormatStatus("", "Status: Downloaded newer image for %s", requestedTag))
  331. } else {
  332. out.Write(sf.FormatStatus("", "Status: Image is up to date for %s", requestedTag))
  333. }
  334. }
  335. // downloadInfo is used to pass information from download to extractor
  336. type downloadInfo struct {
  337. imgJSON []byte
  338. img *image.Image
  339. tmpFile *os.File
  340. length int64
  341. downloaded bool
  342. err chan error
  343. }
  344. func (s *TagStore) pullV2Repository(eng *engine.Engine, r *registry.Session, out io.Writer, repoInfo *registry.RepositoryInfo, tag string, sf *utils.StreamFormatter, parallel bool) error {
  345. endpoint, err := r.V2RegistryEndpoint(repoInfo.Index)
  346. if err != nil {
  347. if repoInfo.Index.Official {
  348. log.Debugf("Unable to pull from V2 registry, falling back to v1: %s", err)
  349. return ErrV2RegistryUnavailable
  350. }
  351. return fmt.Errorf("error getting registry endpoint: %s", err)
  352. }
  353. auth, err := r.GetV2Authorization(endpoint, repoInfo.RemoteName, true)
  354. if err != nil {
  355. return fmt.Errorf("error getting authorization: %s", err)
  356. }
  357. var layersDownloaded bool
  358. if tag == "" {
  359. log.Debugf("Pulling tag list from V2 registry for %s", repoInfo.CanonicalName)
  360. tags, err := r.GetV2RemoteTags(endpoint, repoInfo.RemoteName, auth)
  361. if err != nil {
  362. return err
  363. }
  364. if len(tags) == 0 {
  365. return registry.ErrDoesNotExist
  366. }
  367. for _, t := range tags {
  368. if downloaded, err := s.pullV2Tag(eng, r, out, endpoint, repoInfo, t, sf, parallel, auth); err != nil {
  369. return err
  370. } else if downloaded {
  371. layersDownloaded = true
  372. }
  373. }
  374. } else {
  375. if downloaded, err := s.pullV2Tag(eng, r, out, endpoint, repoInfo, tag, sf, parallel, auth); err != nil {
  376. return err
  377. } else if downloaded {
  378. layersDownloaded = true
  379. }
  380. }
  381. requestedTag := repoInfo.CanonicalName
  382. if len(tag) > 0 {
  383. requestedTag = repoInfo.CanonicalName + ":" + tag
  384. }
  385. WriteStatus(requestedTag, out, sf, layersDownloaded)
  386. return nil
  387. }
  388. func (s *TagStore) pullV2Tag(eng *engine.Engine, r *registry.Session, out io.Writer, endpoint *registry.Endpoint, repoInfo *registry.RepositoryInfo, tag string, sf *utils.StreamFormatter, parallel bool, auth *registry.RequestAuthorization) (bool, error) {
  389. log.Debugf("Pulling tag from V2 registry: %q", tag)
  390. manifestBytes, err := r.GetV2ImageManifest(endpoint, repoInfo.RemoteName, tag, auth)
  391. if err != nil {
  392. return false, err
  393. }
  394. manifest, verified, err := s.loadManifest(eng, manifestBytes)
  395. if err != nil {
  396. return false, fmt.Errorf("error verifying manifest: %s", err)
  397. }
  398. if err := checkValidManifest(manifest); err != nil {
  399. return false, err
  400. }
  401. if verified {
  402. log.Printf("Image manifest for %s:%s has been verified", repoInfo.CanonicalName, tag)
  403. }
  404. out.Write(sf.FormatStatus(tag, "Pulling from %s", repoInfo.CanonicalName))
  405. downloads := make([]downloadInfo, len(manifest.FSLayers))
  406. for i := len(manifest.FSLayers) - 1; i >= 0; i-- {
  407. var (
  408. sumStr = manifest.FSLayers[i].BlobSum
  409. imgJSON = []byte(manifest.History[i].V1Compatibility)
  410. )
  411. img, err := image.NewImgJSON(imgJSON)
  412. if err != nil {
  413. return false, fmt.Errorf("failed to parse json: %s", err)
  414. }
  415. downloads[i].img = img
  416. // Check if exists
  417. if s.graph.Exists(img.ID) {
  418. log.Debugf("Image already exists: %s", img.ID)
  419. continue
  420. }
  421. chunks := strings.SplitN(sumStr, ":", 2)
  422. if len(chunks) < 2 {
  423. return false, fmt.Errorf("expected 2 parts in the sumStr, got %#v", chunks)
  424. }
  425. sumType, checksum := chunks[0], chunks[1]
  426. out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Pulling fs layer", nil))
  427. downloadFunc := func(di *downloadInfo) error {
  428. log.Debugf("pulling blob %q to V1 img %s", sumStr, img.ID)
  429. if c, err := s.poolAdd("pull", "img:"+img.ID); err != nil {
  430. if c != nil {
  431. out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Layer already being pulled by another client. Waiting.", nil))
  432. <-c
  433. out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Download complete", nil))
  434. } else {
  435. log.Debugf("Image (id: %s) pull is already running, skipping: %v", img.ID, err)
  436. }
  437. } else {
  438. defer s.poolRemove("pull", "img:"+img.ID)
  439. tmpFile, err := ioutil.TempFile("", "GetV2ImageBlob")
  440. if err != nil {
  441. return err
  442. }
  443. r, l, err := r.GetV2ImageBlobReader(endpoint, repoInfo.RemoteName, sumType, checksum, auth)
  444. if err != nil {
  445. return err
  446. }
  447. defer r.Close()
  448. // Wrap the reader with the appropriate TarSum reader.
  449. tarSumReader, err := tarsum.NewTarSumForLabel(r, true, sumType)
  450. if err != nil {
  451. return fmt.Errorf("unable to wrap image blob reader with TarSum: %s", err)
  452. }
  453. if _, err := io.Copy(tmpFile, progressreader.New(progressreader.Config{
  454. In: ioutil.NopCloser(tarSumReader),
  455. Out: out,
  456. Formatter: sf,
  457. Size: int(l),
  458. NewLines: false,
  459. ID: common.TruncateID(img.ID),
  460. Action: "Downloading",
  461. })); err != nil {
  462. return fmt.Errorf("unable to copy v2 image blob data: %s", err)
  463. }
  464. out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Verifying Checksum", nil))
  465. if finalChecksum := tarSumReader.Sum(nil); !strings.EqualFold(finalChecksum, sumStr) {
  466. log.Infof("Image verification failed: checksum mismatch - expected %q but got %q", sumStr, finalChecksum)
  467. verified = false
  468. }
  469. out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Download complete", nil))
  470. log.Debugf("Downloaded %s to tempfile %s", img.ID, tmpFile.Name())
  471. di.tmpFile = tmpFile
  472. di.length = l
  473. di.downloaded = true
  474. }
  475. di.imgJSON = imgJSON
  476. return nil
  477. }
  478. if parallel {
  479. downloads[i].err = make(chan error)
  480. go func(di *downloadInfo) {
  481. di.err <- downloadFunc(di)
  482. }(&downloads[i])
  483. } else {
  484. err := downloadFunc(&downloads[i])
  485. if err != nil {
  486. return false, err
  487. }
  488. }
  489. }
  490. var tagUpdated bool
  491. for i := len(downloads) - 1; i >= 0; i-- {
  492. d := &downloads[i]
  493. if d.err != nil {
  494. err := <-d.err
  495. if err != nil {
  496. return false, err
  497. }
  498. }
  499. if d.downloaded {
  500. // if tmpFile is empty assume download and extracted elsewhere
  501. defer os.Remove(d.tmpFile.Name())
  502. defer d.tmpFile.Close()
  503. d.tmpFile.Seek(0, 0)
  504. if d.tmpFile != nil {
  505. err = s.graph.Register(d.img,
  506. progressreader.New(progressreader.Config{
  507. In: d.tmpFile,
  508. Out: out,
  509. Formatter: sf,
  510. Size: int(d.length),
  511. ID: common.TruncateID(d.img.ID),
  512. Action: "Extracting",
  513. }))
  514. if err != nil {
  515. return false, err
  516. }
  517. // FIXME: Pool release here for parallel tag pull (ensures any downloads block until fully extracted)
  518. }
  519. out.Write(sf.FormatProgress(common.TruncateID(d.img.ID), "Pull complete", nil))
  520. tagUpdated = true
  521. } else {
  522. out.Write(sf.FormatProgress(common.TruncateID(d.img.ID), "Already exists", nil))
  523. }
  524. }
  525. // Check for new tag if no layers downloaded
  526. if !tagUpdated {
  527. repo, err := s.Get(repoInfo.LocalName)
  528. if err != nil {
  529. return false, err
  530. }
  531. if repo != nil {
  532. if _, exists := repo[tag]; !exists {
  533. tagUpdated = true
  534. }
  535. }
  536. }
  537. if verified && tagUpdated {
  538. out.Write(sf.FormatStatus(repoInfo.CanonicalName+":"+tag, "The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security."))
  539. }
  540. if err = s.Set(repoInfo.LocalName, tag, downloads[0].img.ID, true); err != nil {
  541. return false, err
  542. }
  543. return tagUpdated, nil
  544. }