mirror of https://github.com/perkeep/perkeep.git
internal/images: gate docker pull for thumbnails
Fixes #1091 Change-Id: I31fda636cec4b4ae06c74cc2c04b6986f10222c3
This commit is contained in:
parent
ce955adf48
commit
4050d088dc
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue