No ResourceType/Mime for Images on an alpine/Hugo extended

Hello.

My hugo was working fine on localhost + gitlab pages using the monachus/hugo image.

I added SCSS and I had to use the extended version. Docker files that can reproduce the issue:

base image

FROM frolvlad/alpine-glibc:glibc-2.28
MAINTAINER adrian@coder.today

RUN apk add --update git asciidoctor libstdc++ \
    && apk upgrade \
    && apk add --no-cache ca-certificates

# Install HUGO
ENV HUGO_VERSION 0.53
ENV HUGO_BINARY hugo_${HUGO_VERSION}_Linux-64bit.tar.gz
RUN wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/${HUGO_BINARY} && \
  tar xzf ${HUGO_BINARY} && \
  rm -r ${HUGO_BINARY} && \
  mv hugo /usr/bin

and my image:

FROM bgadrian/hugo-extended AS builder
MAINTAINER adrian@coder.today

WORKDIR /src
COPY . .

ENV PORT=1313
EXPOSE 1313

#listening on all interfaces 0.0.0.0 is important!
ENTRYPOINT ["hugo", "serve", "--watch=false", "--bind=0.0.0.0"]

Now I cannot build it anymore because of the following issue: All the images from the project are not detected as images. Basically I have this:

{{ $first := .Resources.GetMatch "images/*" }}
{{ with $first }}
    {{ if eq $first.ResourceType "image" }}
        {{ $thumb := $first.Fill "300x300 center" }}
       .....
     {{ else }}
         {{ errorf "file '%s' is not ResourceImage type (masonry) ResourceType:'%s' MediaType.SubType:'%s'" $first.RelPermalink $first.ResourceType $first.MediaType.SubType    }}
     {{ end }}
{{ end }}

And I get errors for all the images:

ERROR 2018/12/28 13:07:44 file '/tech/2014-08-28_unity-click-and-touch-script/images/1.jpeg' is not ResourceImage type (masonry) ResourceType:'' MediaType.SubType:''

My guess is that Hugo uses an external library to detect types and I’m missing it? I searched for a clue in the docs, source code and other dockerfiles but I’m stuck.

  • on localhost Ubuntu 18 is working
  • before adding the extended + alpine was working
  • the $file.Content is there and is binary, so the file is found

Any clue? Thanks!

We have a fall back to Go’s mimetype “guessing”, but the main logic is “custom Hugo”. You can define your own media types if you have some special names for your images. It should be documented.

I have found the problem, all my images that are .jpeg fail, here is one: 1

If I change their extension to .jpg it is working.

I tried with klakegg/hugo: docker images, they all fail (extended and normal, ubuntu and alpine).
Maybe when I saved them something happened, but the strange thing is that on my localhost they are working fine (and before start using the extended version with pipelines).

I renamed all my jpeg to jpg files, I will try to reproduce it and if I find something I will report it to github/gohugo

As I said, you can define your own JPEG mediatype with the extensions you want. See the docs.

I’m having this same issue, even after adding:

[mediaTypes]
  [mediaTypes."image/jpg"]
    suffixes = ["jpg", "jpeg"]

Any image I have as .jpeg isn’t recognized until it’s changed to .jpg.

I too am using Hugo 0.54.0 on Alpine Linux in Docker, whether or not that is a cause I’m not sure.

{{ $img := (($.Site.GetPage "section" "uploads").Resources.ByType "image").GetMatch (strings.TrimPrefix "/uploads/" . ) }}
  {{ with $img }}
  ...

nothing in the with block matches with .jpeg files.

I also see that
image/jpeg
is the actual mime type for .jpg image, not
image/jpg
according to this discussion

I tried making a mediaType for image/jpeg with the .jpeg extension, and still no luck.