From 4050d088dc4a5347beba67a815466e0ce88148d6 Mon Sep 17 00:00:00 2001 From: mpl Date: Tue, 17 Apr 2018 17:13:30 +0200 Subject: [PATCH] internal/images: gate docker pull for thumbnails Fixes #1091 Change-Id: I31fda636cec4b4ae06c74cc2c04b6986f10222c3 --- internal/images/docker.go | 13 +++++++++++++ internal/images/images.go | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/images/docker.go b/internal/images/docker.go index 42720e6f5..e37769932 100644 --- a/internal/images/docker.go +++ b/internal/images/docker.go @@ -23,16 +23,28 @@ import ( "log" "os/exec" "strings" + + "go4.org/syncutil" ) // TODO(mpl): refactor somewhere with pkg/test/dockertest const thumbnailImage = "gcr.io/perkeep-containers/thumbnail" +var ( + thumbnailPullGate = syncutil.NewGate(1) + haveThumbnailImage bool +) + func setUpThumbnailContainer() error { if !haveDocker() { return errors.New("'docker' command not found") } + thumbnailPullGate.Start() + defer thumbnailPullGate.Done() + if haveThumbnailImage { + return nil + } if ok, err := haveImage(thumbnailImage); !ok || err != nil { if err != nil { return fmt.Errorf("error running docker to check for %s: %v", thumbnailImage, err) @@ -42,6 +54,7 @@ func setUpThumbnailContainer() error { return fmt.Errorf("error pulling %s: %v", thumbnailImage, err) } } + haveThumbnailImage = true return nil } diff --git a/internal/images/images.go b/internal/images/images.go index 7e6b50ced..ad02f030b 100644 --- a/internal/images/images.go +++ b/internal/images/images.go @@ -640,7 +640,6 @@ func HEIFToJPEG(fr io.Reader, size *Dimensions) ([]byte, error) { bin, err := exec.LookPath("heiftojpeg") if err != nil { pathErr := err - // TODO(mpl): "pre-pull" the image on Perkeep startup or something like that? if err := setUpThumbnailContainer(); err != nil { return nil, fmt.Errorf("heiftojpeg not found in PATH (%v), and could not fallback on docker image because %v. You need to install github.com/pushd/heif, or set up docker.", pathErr, err) }